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
This commit is contained in:
naglis 2023-07-30 23:14:20 +03:00
parent c5550739f4
commit 83abe0bf62
2 changed files with 14 additions and 0 deletions

View File

@ -414,6 +414,19 @@ pub fn listen(instance: &mut Mpv) -> Result<Event, Error> {
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::<Result<Vec<_>, _>>(),
_ => return Err(Error(ErrorCode::JsonContainsUnexptectedType)),
}?;
Event::ClientMessage { args }
}
_ => Event::Unimplemented,
};
Ok(event)

View File

@ -25,6 +25,7 @@ pub enum Event {
PlaybackRestart,
PropertyChange { id: usize, property: Property },
ChapterChange,
ClientMessage { args: Vec<String> },
Unimplemented,
}