Skip to content

Commit

Permalink
fix(backend): only add the very next track to the streaming service q…
Browse files Browse the repository at this point in the history
…ueue
  • Loading branch information
MAXOUXAX committed Apr 20, 2024
1 parent 3808ae4 commit 3329b77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/src/RoomStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export default class RoomStorage {
if (remote instanceof QueueableRemote) {
let nextTrack = room.getQueue().at(0);

/* If the track that just started playing is the next track in the queue,
* that means the streaming service has started playing it, most likely because
* the previous track ended so we can remove it from the queue
*/
if (nextTrack?.url === newPlaybackState.url) {
room.shiftQueue();
nextTrack = room.getQueue().at(0);
Expand Down
8 changes: 7 additions & 1 deletion backend/src/socketio/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ export default class Room {

// For remote streaming services, we should add the track to the queue of the player
if (!(this.remote instanceof QueueableRemote)) return;
(this.remote as QueueableRemote).addToQueue(track.url);

// Only add the track to the queue if it's the first track added to the queue
// On QueuableRemotes, we only want the very next track to be in the queue, so that other tracks in the queue can be downvoted, without needing to remove the downvoted tracks from the QueuableRemote queue
if (this.queue.length > 1) return;

const queuableRemote = this.remote as QueueableRemote;
queuableRemote.addToQueue(track.url);
}

async removeWithLink(rawUrl: string) {
Expand Down

0 comments on commit 3329b77

Please sign in to comment.