From 3329b7708b757f3e9c32a40445ee3394343604aa Mon Sep 17 00:00:00 2001 From: MAXOUXAX <24844231+MAXOUXAX@users.noreply.github.com> Date: Sat, 20 Apr 2024 15:28:25 +0200 Subject: [PATCH] fix(backend): only add the very next track to the streaming service queue --- backend/src/RoomStorage.ts | 4 ++++ backend/src/socketio/Room.ts | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/RoomStorage.ts b/backend/src/RoomStorage.ts index bb9e09b3..956acdb8 100644 --- a/backend/src/RoomStorage.ts +++ b/backend/src/RoomStorage.ts @@ -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); diff --git a/backend/src/socketio/Room.ts b/backend/src/socketio/Room.ts index 1d16b21c..3827c193 100644 --- a/backend/src/socketio/Room.ts +++ b/backend/src/socketio/Room.ts @@ -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) {