Add function for sending load comand.

This commit is contained in:
Simon Persson 2016-02-17 20:35:31 +01:00
parent 5e3404137f
commit 8e0325c297

View file

@ -146,18 +146,10 @@ impl SpircManager {
.send(); .send();
} }
pub fn send_replace_tracks<S: AsRef<str>, I: Iterator<Item = S>>(&mut self, pub fn send_replace_tracks<I: Iterator<Item = SpotifyId>>(&mut self,
recipient: &str, recipient: &str,
track_ids: I) { track_ids: I) {
let tracks: Vec<protocol::spirc::TrackRef> = track_ids.map(|i| { let state = track_ids_to_state(track_ids);
protobuf_init!(protocol::spirc::TrackRef::new(), { gid: SpotifyId::from_base62(i.as_ref()).to_raw().to_vec()})
})
.collect();
let state = protobuf_init!(protocol::spirc::State::new(), {
track: RepeatedField::from_vec(tracks)
});
let mut internal = self.0.lock().unwrap(); let mut internal = self.0.lock().unwrap();
CommandSender::new(&mut *internal, CommandSender::new(&mut *internal,
protocol::spirc::MessageType::kMessageTypeReplace) protocol::spirc::MessageType::kMessageTypeReplace)
@ -165,6 +157,18 @@ impl SpircManager {
.state(state) .state(state)
.send(); .send();
} }
pub fn send_load_tracks<I: Iterator<Item = SpotifyId>>(&mut self,
recipient: &str,
track_ids: I) {
let state = track_ids_to_state(track_ids);
let mut internal = self.0.lock().unwrap();
CommandSender::new(&mut *internal,
protocol::spirc::MessageType::kMessageTypeLoad)
.recipient(recipient)
.state(state)
.send();
}
} }
impl SpircInternal { impl SpircInternal {
@ -462,3 +466,14 @@ impl<'a> CommandSender<'a> {
.fire(); .fire();
} }
} }
fn track_ids_to_state<I: Iterator<Item = SpotifyId>>(track_ids: I) -> protocol::spirc::State {
let tracks: Vec<protocol::spirc::TrackRef> =
track_ids.map(|i| {
protobuf_init!(protocol::spirc::TrackRef::new(), { gid: i.to_raw().to_vec()})
})
.collect();
protobuf_init!(protocol::spirc::State::new(), {
track: RepeatedField::from_vec(tracks)
})
}