mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #23 from JayRod12/master
Use canonical username when subscribing to spirc.
This commit is contained in:
commit
877f4f7b93
3 changed files with 17 additions and 7 deletions
|
@ -63,6 +63,7 @@ fn main() {
|
|||
device_id: name.clone(),
|
||||
cache_location: PathBuf::from(cache_location)
|
||||
};
|
||||
|
||||
let session = Session::new(config);
|
||||
session.login(username.clone(), password);
|
||||
session.poll();
|
||||
|
@ -76,7 +77,7 @@ fn main() {
|
|||
|
||||
let player = Player::new(&session);
|
||||
|
||||
let mut spirc_manager = SpircManager::new(&session, player, username, name);
|
||||
let mut spirc_manager = SpircManager::new(&session, player, name);
|
||||
spirc_manager.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ pub struct Config {
|
|||
|
||||
pub struct SessionData {
|
||||
pub country: String,
|
||||
pub canonical_username: String,
|
||||
}
|
||||
|
||||
pub struct SessionInternal {
|
||||
|
@ -125,6 +126,7 @@ impl Session {
|
|||
config: config,
|
||||
data: RwLock::new(SessionData {
|
||||
country: String::new(),
|
||||
canonical_username: String::new(),
|
||||
}),
|
||||
|
||||
rx_connection: Mutex::new(cipher_connection.clone()),
|
||||
|
@ -179,7 +181,14 @@ impl Session {
|
|||
},
|
||||
|
||||
0xb2...0xb6 => self.0.mercury.lock().unwrap().handle(cmd, data),
|
||||
0xac => eprintln!("Authentication succeedded"),
|
||||
0xac => {
|
||||
let welcome_data : protocol::authentication::APWelcome =
|
||||
protobuf::parse_from_bytes(&data).unwrap();
|
||||
self.0.data.write().unwrap().canonical_username =
|
||||
welcome_data.get_canonical_username().to_string();
|
||||
eprintln!("Authentication succeeded")
|
||||
},
|
||||
|
||||
0xad => eprintln!("Authentication failed"),
|
||||
_ => ()
|
||||
}
|
||||
|
|
10
src/spirc.rs
10
src/spirc.rs
|
@ -15,7 +15,6 @@ pub struct SpircManager<'s, D: SpircDelegate> {
|
|||
delegate: D,
|
||||
session: &'s Session,
|
||||
|
||||
username: String,
|
||||
state_update_id: i64,
|
||||
seq_nr: u32,
|
||||
|
||||
|
@ -61,12 +60,11 @@ pub trait SpircState {
|
|||
|
||||
impl <'s, D: SpircDelegate> SpircManager<'s, D> {
|
||||
pub fn new(session: &'s Session, delegate: D,
|
||||
username: String, name: String) -> SpircManager<'s, D> {
|
||||
name: String) -> SpircManager<'s, D> {
|
||||
SpircManager {
|
||||
delegate: delegate,
|
||||
session: &session,
|
||||
|
||||
username: username.clone(),
|
||||
state_update_id: 0,
|
||||
seq_nr: 0,
|
||||
|
||||
|
@ -91,7 +89,8 @@ impl <'s, D: SpircDelegate> SpircManager<'s, D> {
|
|||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
let rx = self.session.mercury_sub(format!("hm://remote/3/user/{}/", self.username));
|
||||
let rx = self.session.mercury_sub(format!("hm://remote/3/user/{}/",
|
||||
self.session.0.data.read().unwrap().canonical_username.clone()));
|
||||
let updates = self.delegate.updates();
|
||||
|
||||
loop {
|
||||
|
@ -192,7 +191,8 @@ impl <'s, D: SpircDelegate> SpircManager<'s, D> {
|
|||
|
||||
self.session.mercury(MercuryRequest{
|
||||
method: MercuryMethod::SEND,
|
||||
uri: format!("hm://remote/user/{}", self.username),
|
||||
uri: format!("hm://remote/user/{}",
|
||||
self.session.0.data.read().unwrap().canonical_username.clone()),
|
||||
content_type: None,
|
||||
payload: vec![ pkt.write_to_bytes().unwrap() ]
|
||||
}).await().unwrap();
|
||||
|
|
Loading…
Reference in a new issue