mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
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:
parent
597974f7d8
commit
755aa2e5a0
2 changed files with 18 additions and 14 deletions
|
@ -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 `seek_to` field to `SpircLoadCommand` (breaking)
|
||||||
- [connect] Add `repeat_track` 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)
|
- [playback] Add `track` field to `PlayerEvent::RepeatChanged` (breaking)
|
||||||
- [core] Add `request_with_options` and `request_with_protobuf_and_options` to `SpClient`
|
- [core] Add `request_with_options` and `request_with_protobuf_and_options` to `SpClient`
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ enum SpircCommand {
|
||||||
Shuffle(bool),
|
Shuffle(bool),
|
||||||
Repeat(bool),
|
Repeat(bool),
|
||||||
RepeatTrack(bool),
|
RepeatTrack(bool),
|
||||||
Disconnect,
|
Disconnect { pause: bool },
|
||||||
SetPosition(u32),
|
SetPosition(u32),
|
||||||
SetVolume(u16),
|
SetVolume(u16),
|
||||||
Activate,
|
Activate,
|
||||||
|
@ -311,8 +311,8 @@ impl Spirc {
|
||||||
pub fn set_position_ms(&self, position_ms: u32) -> Result<(), Error> {
|
pub fn set_position_ms(&self, position_ms: u32) -> Result<(), Error> {
|
||||||
Ok(self.commands.send(SpircCommand::SetPosition(position_ms))?)
|
Ok(self.commands.send(SpircCommand::SetPosition(position_ms))?)
|
||||||
}
|
}
|
||||||
pub fn disconnect(&self) -> Result<(), Error> {
|
pub fn disconnect(&self, pause: bool) -> Result<(), Error> {
|
||||||
Ok(self.commands.send(SpircCommand::Disconnect)?)
|
Ok(self.commands.send(SpircCommand::Disconnect { pause })?)
|
||||||
}
|
}
|
||||||
pub fn activate(&self) -> Result<(), Error> {
|
pub fn activate(&self) -> Result<(), Error> {
|
||||||
Ok(self.commands.send(SpircCommand::Activate)?)
|
Ok(self.commands.send(SpircCommand::Activate)?)
|
||||||
|
@ -438,20 +438,17 @@ impl SpircTask {
|
||||||
error!("error updating connect state for volume update: {why}")
|
error!("error updating connect state for volume update: {why}")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => break
|
else => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.shutdown && self.connect_state.is_active() {
|
if !self.shutdown && self.connect_state.is_active() {
|
||||||
if let Err(why) = self.notify().await {
|
warn!("unexpected shutdown");
|
||||||
warn!("notify before unexpected shutdown couldn't be send: {why}")
|
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;
|
self.session.dealer().close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +648,10 @@ impl SpircTask {
|
||||||
self.handle_volume_down();
|
self.handle_volume_down();
|
||||||
self.notify().await
|
self.notify().await
|
||||||
}
|
}
|
||||||
SpircCommand::Disconnect => {
|
SpircCommand::Disconnect { pause } => {
|
||||||
|
if pause {
|
||||||
|
self.handle_pause()
|
||||||
|
}
|
||||||
self.handle_disconnect().await?;
|
self.handle_disconnect().await?;
|
||||||
self.notify().await
|
self.notify().await
|
||||||
}
|
}
|
||||||
|
@ -1142,15 +1142,18 @@ impl SpircTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_disconnect(&mut self) -> Result<(), Error> {
|
async fn handle_disconnect(&mut self) -> Result<(), Error> {
|
||||||
self.handle_stop();
|
|
||||||
|
|
||||||
self.play_status = SpircPlayStatus::Stopped {};
|
|
||||||
self.connect_state
|
self.connect_state
|
||||||
.update_position_in_relation(self.now_ms());
|
.update_position_in_relation(self.now_ms());
|
||||||
self.notify().await?;
|
self.notify().await?;
|
||||||
|
|
||||||
self.connect_state.became_inactive(&self.session).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
|
self.player
|
||||||
.emit_session_disconnected_event(self.session.connection_id(), self.session.username());
|
.emit_session_disconnected_event(self.session.connection_id(), self.session.username());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue