use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize)]
pub(crate) struct WsOutgoing {
pub method: &'static str,
pub params: WsOutgoingParams,
}
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum WsOutgoingParams {
RemoteControl {
#[serde(rename = "Cmd")]
cmd: String,
#[serde(rename = "DataOfCmd")]
data_of_cmd: String,
#[serde(rename = "Option")]
option: String,
#[serde(rename = "TypeOfRemote")]
type_of_remote: String,
},
ChannelEmit {
event: String,
to: String,
data: String,
},
}
#[derive(Debug, Deserialize)]
pub(crate) struct WsIncoming {
pub event: Option<String>,
pub data: Option<serde_json::Value>,
}
impl WsOutgoing {
pub fn remote_key_click(key_code: &str) -> Self {
Self {
method: "ms.remote.control",
params: WsOutgoingParams::RemoteControl {
cmd: "Click".to_string(),
data_of_cmd: key_code.to_string(),
option: "false".to_string(),
type_of_remote: "SendRemoteKey".to_string(),
},
}
}
pub fn art_request(data_json: &str) -> Self {
Self {
method: "ms.channel.emit",
params: WsOutgoingParams::ChannelEmit {
event: super::event::ART_APP_REQUEST.to_string(),
to: "host".to_string(),
data: data_json.to_string(),
},
}
}
}