Skip to content

Commit

Permalink
connect: remove logout support
Browse files Browse the repository at this point in the history
- handle logout command
- disable support for logout
- add todos for logout
  • Loading branch information
photovoltex committed Nov 27, 2024
1 parent 7ebacc7 commit 749622a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
24 changes: 23 additions & 1 deletion connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
},
protocol::{
autoplay_context_request::AutoplayContextRequest,
connect::{Cluster, ClusterUpdate, PutStateReason, SetVolumeCommand},
connect::{Cluster, ClusterUpdate, LogoutCommand, PutStateReason, SetVolumeCommand},
explicit_content_pubsub::UserAttributesUpdate,
player::{Context, TransferState},
playlist4_external::PlaylistModificationInfo,
Expand Down Expand Up @@ -84,6 +84,7 @@ struct SpircTask {
connection_id_update: BoxedStreamResult<String>,
connect_state_update: BoxedStreamResult<ClusterUpdate>,
connect_state_volume_update: BoxedStreamResult<SetVolumeCommand>,
connect_state_logout_request: BoxedStreamResult<LogoutCommand>,
playlist_update: BoxedStreamResult<PlaylistModificationInfo>,
session_update: BoxedStreamResult<SessionUpdate>,
connect_state_command: BoxedStream<RequestReply>,
Expand Down Expand Up @@ -179,6 +180,13 @@ impl Spirc {
.map(Message::from_raw),
);

let connect_state_logout_request = Box::pin(
session
.dealer()
.listen_for("hm://connect-state/v1/connect/logout")?
.map(Message::from_raw),
);

let playlist_update = Box::pin(
session
.dealer()
Expand Down Expand Up @@ -240,6 +248,7 @@ impl Spirc {
connection_id_update,
connect_state_update,
connect_state_volume_update,
connect_state_logout_request,
playlist_update,
session_update,
connect_state_command,
Expand Down Expand Up @@ -376,6 +385,19 @@ impl SpircTask {
break;
}
},
logout_request = self.connect_state_logout_request.next() => match logout_request {
Some(result) => match result {
Ok(logout_request) => {
error!("received logout request, currently not supported: {logout_request:#?}");
// todo: call logout handling
},
Err(e) => error!("could not parse logout request: {}", e),
}
None => {
error!("logout request selected, but none received");
break;
}
},
playlist_update = self.playlist_update.next() => match playlist_update {
Some(result) => match result {
Ok(update) => if let Err(why) = self.handle_playlist_modification(update) {
Expand Down
5 changes: 2 additions & 3 deletions connect/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub struct ConnectStateConfig {
pub initial_volume: u32,
pub name: String,
pub device_type: DeviceType,
pub zeroconf_enabled: bool,
pub volume_steps: i32,
pub is_group: bool,
}
Expand All @@ -87,7 +86,6 @@ impl Default for ConnectStateConfig {
initial_volume: u32::from(u16::MAX) / 2,
name: "librespot".to_string(),
device_type: DeviceType::Speaker,
zeroconf_enabled: false,
volume_steps: 64,
is_group: false,
}
Expand Down Expand Up @@ -158,7 +156,8 @@ impl ConnectState {
is_controllable: true,

supports_gzip_pushes: true,
supports_logout: cfg.zeroconf_enabled,
// todo: enable after logout handling is implemented, see spirc logout_request
supports_logout: false,
supported_types: vec!["audio/episode".into(), "audio/track".into()],
supports_playlist_v2: true,
supports_transfer_command: true,
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,15 +1487,13 @@ fn get_setup() -> Setup {
device_type,
is_group,
initial_volume: initial_volume.into(),
zeroconf_enabled: zeroconf_backend.is_some(),
..Default::default()
}
} else {
ConnectStateConfig {
name,
device_type,
is_group,
zeroconf_enabled: zeroconf_backend.is_some(),
..Default::default()
}
}
Expand Down

0 comments on commit 749622a

Please sign in to comment.