diff --git a/src/main.rs b/src/main.rs index 263b75f..99027ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,9 +49,9 @@ async fn main() -> Result<(), Box> { sleep(Duration::from_secs(1)).await; let mut mpvctl = MpvCtl::connect("/tmp/recordwatchsocket").await?; - mpvctl.get_client_name().await?; + let client_name = mpvctl.get_client_name().await?; - println!("done"); + println!("done {}", client_name); Ok(()) } diff --git a/src/mpvctl/mpvctl.rs b/src/mpvctl/mpvctl.rs index cdd165e..64d16fc 100644 --- a/src/mpvctl/mpvctl.rs +++ b/src/mpvctl/mpvctl.rs @@ -35,6 +35,7 @@ impl MpvCtl { loop { match framed_read.read_frame().await { Ok(Some(frame)) => { + println!("Read {}", frame); // get the request id and push the result into the channel let reqid = { let obj = match &frame { @@ -94,7 +95,7 @@ impl MpvCtl { cmd: Command, ) -> Result, Box> { let serialized = serde_json::to_string(&cmd)? + "\n"; - println!("Sending {}", serialized); + print!("Sending {}", serialized); let (response_tx, response_rx) = oneshot::channel::(); match cmd.get_request_id() { Some(reqid) => { @@ -111,12 +112,21 @@ impl MpvCtl { Ok(response_rx) } - pub async fn get_client_name(&mut self) -> Result<(), Box> { + pub async fn get_client_name(&mut self) -> Result> { let request_id = self.grab_request_id(); let cmd = Command::new(vec!["client_name".to_string()], Some(request_id)); let cmd_result = self.send_command(cmd).await?; let result = cmd_result.await?; - println!("Read the following result: {}", result); - Ok(()) + if let serde_json::Value::Object(obj) = result { + let client_name = match obj.get("data") { + Some(serde_json::Value::String(client_name)) => client_name, + _ => { + return Err("Failed to get client name".into()); + } + }; + return Ok(client_name.to_owned()); + } else { + return Err("Did not get back an object".into()); + } } }