Skip to content

Commit

Permalink
Sync the state of the remote player (related to #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Apr 2, 2019
1 parent 2d8da2a commit 0a81fab
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 299 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Web-based overlay with current song ([#22]).
- Player will no longer pause the current song (if it's playing) and will instead synchronize the state of the player with Spotify ([#18]).
- Implement `!commands rename <from> <to>`
- Ability to sync remote state of player with `[player] sync_player_interval = "10s"` ([#18]).

### Changed
- Cleaned up old cruft in the codebase (`gfx` module).
Expand Down
16 changes: 11 additions & 5 deletions bot/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ pub enum Message {
SongCurrent {
track: Option<spotify::FullTrack>,
user: Option<String>,
paused: bool,
is_playing: bool,
elapsed: u64,
duration: u64,
},
}

Expand All @@ -182,23 +184,27 @@ impl Message {
}
}

/// Message indicating that no song is playing.
pub fn from_song(song: Option<&player::Song>, paused: bool) -> Self {
/// Construct a message that the given song is running.
pub fn song(song: Option<&player::Song>) -> Self {
let song = match song {
Some(song) => song,
None => {
return Message::SongCurrent {
track: None,
user: None,
paused,
is_playing: false,
elapsed: 0,
duration: 0,
}
}
};

Message::SongCurrent {
track: Some(song.item.track.clone()),
user: song.item.user.clone(),
paused,
is_playing: song.is_playing(),
elapsed: song.elapsed().as_secs(),
duration: song.duration().as_secs(),
}
}

Expand Down
Loading

0 comments on commit 0a81fab

Please sign in to comment.