1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00

rs-terminal: decode PlaybackUpdate for current version

This commit is contained in:
Marcus Hanestad 2025-06-04 13:15:39 +02:00
parent 91a2bbee13
commit 1eca7df85d
3 changed files with 24 additions and 10 deletions

View file

@ -8,7 +8,7 @@ use std::{
use crate::{
models::{
v2::{self, PlaybackUpdateMessage},
v2,
v3, PlaybackErrorMessage, VersionMessage, VolumeUpdateMessage,
},
transport::Transport,
@ -303,12 +303,26 @@ impl<'a> FCastSession<'a> {
match opcode {
Opcode::PlaybackUpdate => {
if let Some(body_str) = body {
if let Ok(playback_update_msg) =
serde_json::from_str::<PlaybackUpdateMessage>(body_str.as_str())
{
println!("Received playback update {:?}", playback_update_msg);
} else {
println!("Received playback update with malformed body.");
match self.state {
SessionState::Connected(ProtoVersion::V2) => {
if let Ok(playback_update_msg) =
serde_json::from_str::<v2::PlaybackUpdateMessage>(body_str.as_str())
{
println!("Received playback update {:?}", playback_update_msg);
} else {
println!("Received playback update with malformed body.");
}
}
SessionState::Connected(ProtoVersion::V3) => {
if let Ok(playback_update_msg) =
serde_json::from_str::<v3::PlaybackUpdateMessage>(body_str.as_str())
{
println!("Received playback update {:?}", playback_update_msg);
} else {
println!("Received playback update with malformed body.");
}
}
_ => unreachable!(),
}
} else {
println!("Received playback update with no body.");

View file

@ -63,7 +63,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
Arg::with_name("subscribe")
.short('s')
.long("subscribe")
.value_name("SUBSCRIPTIONS")
.value_name("EVENTS")
.help("A comma separated list of events to subscribe to (e.g. MediaItemStart,KeyDown). \
Available events: [MediaItemStart, MediaItemEnd, MediaItemChange, KeyDown, KeyUp]")
.required(false)

View file

@ -149,7 +149,7 @@ pub struct PlaylistContent {
pub metadata: Option<MetadataObject>,
}
#[derive(Serialize_repr, Debug)]
#[derive(Serialize_repr, Deserialize_repr, Debug)]
#[repr(u8)]
pub enum PlaybackState {
Idle = 0,
@ -157,7 +157,7 @@ pub enum PlaybackState {
Paused = 2,
}
#[derive(Serialize, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct PlaybackUpdateMessage {
// The time the packet was generated (unix time milliseconds)
pub generationTime: u64,