Skip to content

Commit

Permalink
Merge pull request #186 from camphor-/fix-is-playing-crrect-track
Browse files Browse the repository at this point in the history
同期チェックでPlayingが正しいかもかもチェックする
  • Loading branch information
p1ass authored Aug 6, 2020
2 parents 1758f33 + 3685a39 commit 61feab1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions domain/entity/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ func (s *Session) IsPlayingCorrectTrack(playingInfo *CurrentPlayingInfo) error {
})
return fmt.Errorf("session playing different track: queue track %s, but playing track %v: %w", s.QueueTracks[s.QueueHead].URI, playingInfo.Track, ErrSessionPlayingDifferentTrack)
}

if playingInfo.Playing != s.IsPlaying() {
logger.Infoj(map[string]interface{}{
"message": "session playing, but spotify is not playing",
"queueTrack": s.QueueTracks[s.QueueHead].URI,
"playingTrack": playingInfo.Track,
})
return fmt.Errorf("session playing, but spotify is not playing: %w", ErrSessionPlayingDifferentTrack)

}

return nil
}

Expand Down
17 changes: 17 additions & 0 deletions domain/entity/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,23 @@ func TestSession_IsPlayingCorrectTrack(t *testing.T) {
playingInfo: nil,
wantErr: true,
},
{
name: "再生されているはずなのにSpotify側が一時停止していたらエラー",
session: &Session{
StateType: Play,
QueueHead: 0,
QueueTracks: []*QueueTrack{
{URI: "spotify:track:5uQ0vKy2973Y9IUCd1wMEF"},
},
},
playingInfo: &CurrentPlayingInfo{
Playing: false,
Progress: 0,
Track: &Track{},
Device: &Device{},
},
wantErr: true,
},
{
name: "再生が終了してStopになっていたらエラーにならない",
session: &Session{
Expand Down
3 changes: 3 additions & 0 deletions usecase/session_timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ func (s *SessionTimerUseCase) handleTrackEndTx(sessionID string) func(ctx contex

track := sess.TrackURIShouldBeAddedWhenHandleTrackEnd()
if track != "" {
// TODO: Spotifyアプリを閉じた後、ずっとRelaymを開かないとINTERRUPTにならずにここまでたどり着いて
// active device not foundになってしまう
// そのときstateはPLAYのままなので表示がバグる
if err := s.playerCli.Enqueue(ctx, track, sess.DeviceID); err != nil {
return &handleTrackEndResponse{
nextTrack: false,
Expand Down

0 comments on commit 61feab1

Please sign in to comment.