(
message: Message,
tx: Sender<Result<MessageReply>>,
spirc: &mut Spirc,
session: &mut Session,
)
| 212 | |
| 213 | #[tracing::instrument(level = "debug", skip(message, tx, spirc, session))] |
| 214 | fn handle_command( |
| 215 | message: Message, |
| 216 | tx: Sender<Result<MessageReply>>, |
| 217 | spirc: &mut Spirc, |
| 218 | session: &mut Session, |
| 219 | ) { |
| 220 | match message { |
| 221 | Message::Play => { |
| 222 | let res = (spirc) |
| 223 | .play() |
| 224 | .map(|_| MessageReply::None) |
| 225 | .map_err(MoosyncError::Librespot); |
| 226 | |
| 227 | tx.send(res).unwrap(); |
| 228 | } |
| 229 | |
| 230 | Message::Pause => { |
| 231 | let res = (spirc) |
| 232 | .pause() |
| 233 | .map(|_| MessageReply::None) |
| 234 | .map_err(MoosyncError::Librespot); |
| 235 | |
| 236 | tx.send(res).unwrap(); |
| 237 | } |
| 238 | |
| 239 | Message::GetToken(scopes) => { |
| 240 | let rt = Builder::new_current_thread().build().unwrap(); |
| 241 | let data = rt.block_on(async move { |
| 242 | session |
| 243 | .token_provider() |
| 244 | .get_token(scopes.as_str()) |
| 245 | .await |
| 246 | .map(MessageReply::GetToken) |
| 247 | .map_err(MoosyncError::Librespot) |
| 248 | }); |
| 249 | |
| 250 | tx.send(data).unwrap(); |
| 251 | } |
| 252 | Message::Seek(pos) => { |
| 253 | let res = spirc |
| 254 | .set_position_ms(pos) |
| 255 | .map(|_| MessageReply::None) |
| 256 | .map_err(MoosyncError::Librespot); |
| 257 | tx.send(res).unwrap(); |
| 258 | } |
| 259 | Message::Load(uri, autoplay) => { |
| 260 | let track_id = SpotifyId::from_uri(uri.as_str()).map_err(MoosyncError::Librespot); |
| 261 | match track_id { |
| 262 | Err(e) => { |
| 263 | tx.send(Err(e)).unwrap(); |
| 264 | } |
| 265 | Ok(_track_id) => { |
| 266 | // track_ref.set_gid(Vec::from(track_id.to_raw())); |
| 267 | let command = LoadRequest::from_context_uri( |
| 268 | uri, |
| 269 | LoadRequestOptions { |
| 270 | start_playing: autoplay, |
| 271 | seek_to: 0, |
nothing calls this directly
no test coverage detected