Dealer: Improve disconnect (#1420)

* connect: adjust disconnect behavior

* update CHANGELOG.md

* core: adjust param of `set_session_id`

* connect: move unexpected disconnect outside the loop again
This commit is contained in:
Felix Prillwitz 2024-12-17 18:57:02 +01:00 committed by GitHub
parent 597974f7d8
commit 755aa2e5a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 14 deletions

View file

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [connect] Add `seek_to` field to `SpircLoadCommand` (breaking)
- [connect] Add `repeat_track` field to `SpircLoadCommand` (breaking)
- [connect] Add `pause` parameter to `Spirc::disconnect` method (breaking)
- [playback] Add `track` field to `PlayerEvent::RepeatChanged` (breaking)
- [core] Add `request_with_options` and `request_with_protobuf_and_options` to `SpClient`

View file

@ -129,7 +129,7 @@ enum SpircCommand {
Shuffle(bool),
Repeat(bool),
RepeatTrack(bool),
Disconnect,
Disconnect { pause: bool },
SetPosition(u32),
SetVolume(u16),
Activate,
@ -311,8 +311,8 @@ impl Spirc {
pub fn set_position_ms(&self, position_ms: u32) -> Result<(), Error> {
Ok(self.commands.send(SpircCommand::SetPosition(position_ms))?)
}
pub fn disconnect(&self) -> Result<(), Error> {
Ok(self.commands.send(SpircCommand::Disconnect)?)
pub fn disconnect(&self, pause: bool) -> Result<(), Error> {
Ok(self.commands.send(SpircCommand::Disconnect { pause })?)
}
pub fn activate(&self) -> Result<(), Error> {
Ok(self.commands.send(SpircCommand::Activate)?)
@ -438,20 +438,17 @@ impl SpircTask {
error!("error updating connect state for volume update: {why}")
}
},
else => break
else => break,
}
}
if !self.shutdown && self.connect_state.is_active() {
if let Err(why) = self.notify().await {
warn!("notify before unexpected shutdown couldn't be send: {why}")
warn!("unexpected shutdown");
if let Err(why) = self.handle_disconnect().await {
error!("error during disconnecting: {why}")
}
}
// clears the session id, leaving an empty state
if let Err(why) = self.session.spclient().delete_connect_state_request().await {
warn!("deleting connect_state failed before unexpected shutdown: {why}")
}
self.session.dealer().close().await;
}
@ -651,7 +648,10 @@ impl SpircTask {
self.handle_volume_down();
self.notify().await
}
SpircCommand::Disconnect => {
SpircCommand::Disconnect { pause } => {
if pause {
self.handle_pause()
}
self.handle_disconnect().await?;
self.notify().await
}
@ -1142,15 +1142,18 @@ impl SpircTask {
}
async fn handle_disconnect(&mut self) -> Result<(), Error> {
self.handle_stop();
self.play_status = SpircPlayStatus::Stopped {};
self.connect_state
.update_position_in_relation(self.now_ms());
self.notify().await?;
self.connect_state.became_inactive(&self.session).await?;
// this should clear the active session id, leaving an empty state
self.session
.spclient()
.delete_connect_state_request()
.await?;
self.player
.emit_session_disconnected_event(self.session.connection_id(), self.session.username());