Skip to content

Commit

Permalink
refactor: move queue operations to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Feb 9, 2024
1 parent be3f8c7 commit 9feee26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 14 additions & 0 deletions cmd/daemon/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ func (p *AppPlayer) setShufflingContext(val bool) {
})
}

func (p *AppPlayer) addToQueue(track *connectpb.ContextTrack) {
p.state.tracks.AddToQueue(track)
p.state.player.PrevTracks = p.state.tracks.PrevTracks()
p.state.player.NextTracks = p.state.tracks.NextTracks()
p.updateState()
}

func (p *AppPlayer) setQueue(prev []*connectpb.ContextTrack, next []*connectpb.ContextTrack) {
p.state.tracks.SetQueue(prev, next)
p.state.player.PrevTracks = p.state.tracks.PrevTracks()
p.state.player.NextTracks = p.state.tracks.NextTracks()
p.updateState()
}

func (p *AppPlayer) play() error {
if p.stream == nil {
return fmt.Errorf("no stream")
Expand Down
10 changes: 2 additions & 8 deletions cmd/daemon/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,10 @@ func (p *AppPlayer) handlePlayerCommand(req dealer.RequestPayload) error {
p.setShufflingContext(req.Command.Value.(bool))
return nil
case "set_queue":
p.state.tracks.SetQueue(req.Command.PrevTracks, req.Command.NextTracks)
p.state.player.PrevTracks = p.state.tracks.PrevTracks()
p.state.player.NextTracks = p.state.tracks.NextTracks()
p.updateState()
p.setQueue(req.Command.PrevTracks, req.Command.NextTracks)
return nil
case "add_to_queue":
p.state.tracks.AddToQueue(req.Command.Track)
p.state.player.PrevTracks = p.state.tracks.PrevTracks()
p.state.player.NextTracks = p.state.tracks.NextTracks()
p.updateState()
p.addToQueue(req.Command.Track)
return nil
default:
return fmt.Errorf("unsupported player command: %s", req.Command.Endpoint)
Expand Down

0 comments on commit 9feee26

Please sign in to comment.