add doc strings
This commit is contained in:
parent
c02241ffe8
commit
25e2ed7390
@ -173,6 +173,7 @@ struct ResponseData {
|
|||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read the request body and convert it to a string
|
||||||
fn read_request_body(request: &mut Request) -> Result<String, IoError> {
|
fn read_request_body(request: &mut Request) -> Result<String, IoError> {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let body = request.as_reader();
|
let body = request.as_reader();
|
||||||
@ -183,6 +184,7 @@ fn read_request_body(request: &mut Request) -> Result<String, IoError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// create client response in JSON format
|
||||||
fn json_response(data: serde_json::Map<String, serde_json::Value>) -> Response<Cursor<Vec<u8>>> {
|
fn json_response(data: serde_json::Map<String, serde_json::Value>) -> Response<Cursor<Vec<u8>>> {
|
||||||
let response_body = serde_json::to_string(&data).unwrap();
|
let response_body = serde_json::to_string(&data).unwrap();
|
||||||
|
|
||||||
@ -192,6 +194,7 @@ fn json_response(data: serde_json::Map<String, serde_json::Value>) -> Response<C
|
|||||||
.with_header(Header::from_bytes(&b"Content-Type"[..], &b"application/json"[..]).unwrap())
|
.with_header(Header::from_bytes(&b"Content-Type"[..], &b"application/json"[..]).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// create client error message
|
||||||
fn error_response(answer: &str, code: i32) -> Response<Cursor<Vec<u8>>> {
|
fn error_response(answer: &str, code: i32) -> Response<Cursor<Vec<u8>>> {
|
||||||
error!("RPC: {answer}");
|
error!("RPC: {answer}");
|
||||||
|
|
||||||
@ -200,6 +203,7 @@ fn error_response(answer: &str, code: i32) -> Response<Cursor<Vec<u8>>> {
|
|||||||
.with_header(Header::from_bytes(&b"Content-Type"[..], &b"text/plain"[..]).unwrap())
|
.with_header(Header::from_bytes(&b"Content-Type"[..], &b"text/plain"[..]).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// control playout: jump to last clip
|
||||||
fn control_back(
|
fn control_back(
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
play_control: &PlayerControl,
|
play_control: &PlayerControl,
|
||||||
@ -245,6 +249,7 @@ fn control_back(
|
|||||||
error_response("Clip index out of range!", 400)
|
error_response("Clip index out of range!", 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// control playout: jump to next clip
|
||||||
fn control_next(
|
fn control_next(
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
play_control: &PlayerControl,
|
play_control: &PlayerControl,
|
||||||
@ -291,6 +296,7 @@ fn control_next(
|
|||||||
error_response("Last clip can not be skipped!", 400)
|
error_response("Last clip can not be skipped!", 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// control playout: reset playlist state
|
||||||
fn control_reset(
|
fn control_reset(
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
playout_stat: &PlayoutStatus,
|
playout_stat: &PlayoutStatus,
|
||||||
@ -325,16 +331,17 @@ fn control_reset(
|
|||||||
error_response("Reset playout state failed!", 400)
|
error_response("Reset playout state failed!", 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// control playout: stop playlout
|
||||||
fn control_stop(proc: &ProcessControl) -> Response<Cursor<Vec<u8>>> {
|
fn control_stop(proc: &ProcessControl) -> Response<Cursor<Vec<u8>>> {
|
||||||
proc.stop_all();
|
proc.stop_all();
|
||||||
|
|
||||||
let mut data_map = Map::new();
|
let mut data_map = Map::new();
|
||||||
data_map.insert("message".to_string(), json!("Stop playout!"));
|
data_map.insert("message".to_string(), json!("Stop playout!"));
|
||||||
|
|
||||||
// Ok(Value::String("Stop playout!".to_string()));
|
|
||||||
json_response(data_map)
|
json_response(data_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// control playout: create text filter for ffmpeg
|
||||||
fn control_text(
|
fn control_text(
|
||||||
data: HashMap<String, serde_json::Value>,
|
data: HashMap<String, serde_json::Value>,
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
@ -384,6 +391,7 @@ fn control_text(
|
|||||||
error_response("text message missing!", 400)
|
error_response("text message missing!", 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// media info: get infos about current clip
|
||||||
fn media_current(
|
fn media_current(
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
play_control: &PlayerControl,
|
play_control: &PlayerControl,
|
||||||
@ -398,6 +406,7 @@ fn media_current(
|
|||||||
error_response("No current clip...", 204)
|
error_response("No current clip...", 204)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// media info: get infos about next clip
|
||||||
fn media_next(config: &PlayoutConfig, play_control: &PlayerControl) -> Response<Cursor<Vec<u8>>> {
|
fn media_next(config: &PlayoutConfig, play_control: &PlayerControl) -> Response<Cursor<Vec<u8>>> {
|
||||||
let index = play_control.index.load(Ordering::SeqCst);
|
let index = play_control.index.load(Ordering::SeqCst);
|
||||||
let current_list = play_control.current_list.lock().unwrap();
|
let current_list = play_control.current_list.lock().unwrap();
|
||||||
@ -413,6 +422,7 @@ fn media_next(config: &PlayoutConfig, play_control: &PlayerControl) -> Response<
|
|||||||
error_response("There is no next clip", 500)
|
error_response("There is no next clip", 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// media info: get infos about last clip
|
||||||
fn media_last(config: &PlayoutConfig, play_control: &PlayerControl) -> Response<Cursor<Vec<u8>>> {
|
fn media_last(config: &PlayoutConfig, play_control: &PlayerControl) -> Response<Cursor<Vec<u8>>> {
|
||||||
let index = play_control.index.load(Ordering::SeqCst);
|
let index = play_control.index.load(Ordering::SeqCst);
|
||||||
let current_list = play_control.current_list.lock().unwrap();
|
let current_list = play_control.current_list.lock().unwrap();
|
||||||
@ -428,6 +438,8 @@ fn media_last(config: &PlayoutConfig, play_control: &PlayerControl) -> Response<
|
|||||||
error_response("There is no last clip", 500)
|
error_response("There is no last clip", 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// response builder
|
||||||
|
/// convert request body to struct and create response according to the request values
|
||||||
fn build_response(
|
fn build_response(
|
||||||
mut request: Request,
|
mut request: Request,
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
@ -493,6 +505,8 @@ fn build_response(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// request handler
|
||||||
|
/// check if authorization header with correct value exists and forward traffic to build_response()
|
||||||
fn handle_request(
|
fn handle_request(
|
||||||
request: Request,
|
request: Request,
|
||||||
config: &PlayoutConfig,
|
config: &PlayoutConfig,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user