mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Get connection ID
This commit is contained in:
parent
9a31aa0362
commit
9a93cca562
3 changed files with 39 additions and 0 deletions
|
@ -61,6 +61,7 @@ struct SpircTask {
|
|||
play_status: SpircPlayStatus,
|
||||
|
||||
subscription: BoxedStream<Frame>,
|
||||
connection_id_update: BoxedStream<String>,
|
||||
user_attributes_update: BoxedStream<UserAttributesUpdate>,
|
||||
user_attributes_mutation: BoxedStream<UserAttributesMutation>,
|
||||
sender: MercurySender,
|
||||
|
@ -254,6 +255,21 @@ impl Spirc {
|
|||
}),
|
||||
);
|
||||
|
||||
let connection_id_update = Box::pin(
|
||||
session
|
||||
.mercury()
|
||||
.listen_for("hm://pusher/v1/connections/")
|
||||
.map(UnboundedReceiverStream::new)
|
||||
.flatten_stream()
|
||||
.map(|response| -> String {
|
||||
response
|
||||
.uri
|
||||
.strip_prefix("hm://pusher/v1/connections/")
|
||||
.unwrap_or("")
|
||||
.to_owned()
|
||||
}),
|
||||
);
|
||||
|
||||
let user_attributes_update = Box::pin(
|
||||
session
|
||||
.mercury()
|
||||
|
@ -306,6 +322,7 @@ impl Spirc {
|
|||
play_status: SpircPlayStatus::Stopped,
|
||||
|
||||
subscription,
|
||||
connection_id_update,
|
||||
user_attributes_update,
|
||||
user_attributes_mutation,
|
||||
sender,
|
||||
|
@ -390,6 +407,13 @@ impl SpircTask {
|
|||
break;
|
||||
}
|
||||
},
|
||||
connection_id_update = self.connection_id_update.next() => match connection_id_update {
|
||||
Some(connection_id) => self.handle_connection_id_update(connection_id),
|
||||
None => {
|
||||
error!("connection ID update selected, but none received");
|
||||
break;
|
||||
}
|
||||
},
|
||||
cmd = async { commands.unwrap().recv().await }, if commands.is_some() => if let Some(cmd) = cmd {
|
||||
self.handle_command(cmd);
|
||||
},
|
||||
|
@ -619,6 +643,11 @@ impl SpircTask {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_connection_id_update(&mut self, connection_id: String) {
|
||||
trace!("Received connection ID update: {:?}", connection_id);
|
||||
self.session.set_connection_id(connection_id);
|
||||
}
|
||||
|
||||
fn handle_user_attributes_update(&mut self, update: UserAttributesUpdate) {
|
||||
trace!("Received attributes update: {:#?}", update);
|
||||
let attributes: UserAttributes = update
|
||||
|
|
|
@ -264,6 +264,7 @@ impl MercuryManager {
|
|||
|
||||
if !found {
|
||||
debug!("unknown subscription uri={}", response.uri);
|
||||
trace!("response pushed over Mercury: {:?}", response);
|
||||
}
|
||||
})
|
||||
} else if let Some(cb) = pending.callback {
|
||||
|
|
|
@ -52,6 +52,7 @@ pub struct UserData {
|
|||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct SessionData {
|
||||
connection_id: String,
|
||||
time_delta: i64,
|
||||
invalid: bool,
|
||||
user_data: UserData,
|
||||
|
@ -319,6 +320,14 @@ impl Session {
|
|||
&self.config().device_id
|
||||
}
|
||||
|
||||
pub fn connection_id(&self) -> String {
|
||||
self.0.data.read().unwrap().connection_id.clone()
|
||||
}
|
||||
|
||||
pub fn set_connection_id(&self, connection_id: String) {
|
||||
self.0.data.write().unwrap().connection_id = connection_id;
|
||||
}
|
||||
|
||||
pub fn username(&self) -> String {
|
||||
self.0
|
||||
.data
|
||||
|
|
Loading…
Reference in a new issue