From 83abe0bf62a61234c855068a817acd3ca6a356e4 Mon Sep 17 00:00:00 2001 From: naglis <55976-naglis@users.noreply.gitlab.com> Date: Sun, 30 Jul 2023 23:14:20 +0300 Subject: [PATCH] Add support for `client-message` events These events are issued [1] when clients communicate to each other using `script-message` [2] and `script-message-to` [3] commands. [1]: https://mpv.io/manual/stable/#command-interface-client-message [2]: https://mpv.io/manual/stable/#command-interface-script-message [3]: https://mpv.io/manual/stable/#command-interface-script-message-to --- src/ipc.rs | 13 +++++++++++++ src/lib.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/src/ipc.rs b/src/ipc.rs index 670dc53..91297bd 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -414,6 +414,19 @@ pub fn listen(instance: &mut Mpv) -> Result { try_convert_property(name.as_ref(), id, data) } + "client-message" => { + let args = match e["args"] { + Value::Array(ref a) => json_array_to_vec(a) + .iter() + .map(|arg| match arg { + MpvDataType::String(s) => Ok(s.to_owned()), + _ => Err(Error(ErrorCode::JsonContainsUnexptectedType)), + }) + .collect::, _>>(), + _ => return Err(Error(ErrorCode::JsonContainsUnexptectedType)), + }?; + Event::ClientMessage { args } + } _ => Event::Unimplemented, }; Ok(event) diff --git a/src/lib.rs b/src/lib.rs index 31e5017..a2ded09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ pub enum Event { PlaybackRestart, PropertyChange { id: usize, property: Property }, ChapterChange, + ClientMessage { args: Vec }, Unimplemented, }