From 4dc352714c3462c5a230ec314fb995ec57a613b1 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 20 Feb 2022 22:16:51 -0500 Subject: [PATCH] Detect events. --- src/mpvctl/mpvctl.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mpvctl/mpvctl.rs b/src/mpvctl/mpvctl.rs index 8ecbbd4..a048228 100644 --- a/src/mpvctl/mpvctl.rs +++ b/src/mpvctl/mpvctl.rs @@ -56,6 +56,15 @@ impl MpvCtl { match framed_read.read_frame().await { Ok(Some(frame)) => { println!("Read {}", frame); + // check if its an event + let is_event = match &frame { + serde_json::Value::Object(obj) => obj.contains_key("event"), + _ => false, + }; + if is_event { + // TODO: Currently we are not doing anything with events. Perhaps they should be dumped onto a stream? Perhaps many streams each representing a listener to an event? + return Ok(()); + } // get the request id and push the result into the channel let reqid = { let obj = match &frame { @@ -64,6 +73,10 @@ impl MpvCtl { return Err("Got back a json value that wasn't an object.".into()); } }; + match obj.get("event") { + Some(event) => {} + _ => (), + }; match obj.get("request_id") { Some(serde_json::Value::Number(reqid)) if reqid.is_u64() => { reqid.as_u64().unwrap()