Skip to content

Commit

Permalink
fix(backend): added 1s delay before fetching and sending updated play…
Browse files Browse the repository at this point in the history
…back state after a skip/previous action to ensure the track was successfully skipped
  • Loading branch information
MAXOUXAX committed Apr 20, 2024
1 parent 846d68a commit 030d71e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions backend/src/socketio/RoomIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,14 @@ export default function onRoomWSConnection(socket: TypedSocket) {
}

socket.emit("player:skip", response);
if (!response.error) await room.updatePlaybackState();

// If the skip action was successful, we update the playback state
// This is done after a timeout to ensure that the track has been skipped on the remote
if (!response.error) {
setTimeout(() => {
room.updatePlaybackState();
}, 1000);
}
});

socket.on("player:previous", async () => {
Expand All @@ -165,7 +172,13 @@ export default function onRoomWSConnection(socket: TypedSocket) {
const response = await remote.previous();
socket.emit("player:previous", response);

if (!response.error) await room.updatePlaybackState();
// If the previous action was successful, we update the playback state
// This is done after a timeout to ensure that the track has been skipped on the remote
if (!response.error) {
setTimeout(() => {
room.updatePlaybackState();
}, 1000);
}
});

socket.on("player:setVolume", async (volume) => {
Expand Down

0 comments on commit 030d71e

Please sign in to comment.