diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 3d1efb311..2cac273c6 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -530,10 +530,7 @@ impl SpircTask { match self.session.spclient().get_context(context_uri).await { Err(why) => error!("failed to resolve context '{context_uri}': {why}"), Ok(ctx) if update => { - if let Err(why) = self.connect_state.update_context(ctx, UpdateContext::Default) { - error!("failed loading context: {why}"); - self.handle_stop() - } + self.connect_state.update_context(ctx, UpdateContext::Default)? } Ok(mut ctx) if matches!(ctx.pages.first(), Some(p) if !p.tracks.is_empty()) => { debug!("update context from single page, context {} had {} pages", ctx.uri, ctx.pages.len()); @@ -921,12 +918,8 @@ impl SpircTask { self.connect_state.active && cluster.active_device_id != self.session.device_id(); if became_inactive { info!("device became inactive"); + self.connect_state.became_inactive(&self.session).await?; self.handle_stop(); - self.connect_state.reset(); - let _ = self - .connect_state - .update_state(&self.session, PutStateReason::BECAME_INACTIVE) - .await?; } else if self.connect_state.active { // fixme: workaround fix, because of missing information why it behaves like it does // background: when another device sends a connect-state update, some player's position de-syncs @@ -1125,9 +1118,7 @@ impl SpircTask { .update_position_in_relation(self.now_ms()); self.notify().await?; - self.connect_state - .update_state(&self.session, PutStateReason::BECAME_INACTIVE) - .await?; + self.connect_state.became_inactive(&self.session).await?; self.player .emit_session_disconnected_event(self.session.connection_id(), self.session.username()); @@ -1538,6 +1529,7 @@ impl SpircTask { fn load_track(&mut self, start_playing: bool, position_ms: u32) -> Result<(), Error> { if self.connect_state.current_track(MessageField::is_none) { + debug!("current track is none, stopping playback"); self.handle_stop(); return Ok(()); } diff --git a/connect/src/state.rs b/connect/src/state.rs index 2e113eaa4..94095cc5a 100644 --- a/connect/src/state.rs +++ b/connect/src/state.rs @@ -397,12 +397,19 @@ impl ConnectState { self.player.timestamp = timestamp; } + pub async fn became_inactive(&mut self, session: &Session) -> SpClientResult { + self.reset(); + self.reset_context(None); + + session.spclient().put_connect_state_inactive(false).await + } + /// Updates the connect state for the connect session /// /// Prepares a [PutStateRequest] from the current connect state pub async fn update_state(&self, session: &Session, reason: PutStateReason) -> SpClientResult { if matches!(reason, PutStateReason::BECAME_INACTIVE) { - return session.spclient().put_connect_state_inactive(false).await; + warn!("should use instead") } let now = SystemTime::now(); diff --git a/connect/src/state/context.rs b/connect/src/state/context.rs index 77e02593d..825dca157 100644 --- a/connect/src/state/context.rs +++ b/connect/src/state/context.rs @@ -67,7 +67,9 @@ impl ConnectState { self.autoplay_context = None; self.shuffle_context = None; - if matches!(new_context, Some(ctx) if self.player.context_uri != ctx) { + let reset_default_context = new_context.is_none() + || matches!(new_context, Some(ctx) if self.player.context_uri != ctx); + if reset_default_context { self.context = None; self.next_contexts.clear(); } else if let Some(ctx) = self.context.as_mut() { diff --git a/core/src/dealer/protocol.rs b/core/src/dealer/protocol.rs index 858a10e7c..e6b7f2dc3 100644 --- a/core/src/dealer/protocol.rs +++ b/core/src/dealer/protocol.rs @@ -155,7 +155,11 @@ impl WebsocketRequest { let payload = String::from_utf8(payload)?; if log::max_level() >= LevelFilter::Trace { - trace!("{:#?}", serde_json::from_str::(&payload)); + if let Ok(json) = serde_json::from_str::(&payload) { + trace!("websocket request: {json:#?}"); + } else { + trace!("websocket request: {payload}"); + } } serde_json::from_str(&payload)