Spotify now starts playing the latest song if the queue was empty before and then a song was added
This commit is contained in:
parent
e9fdc05c2d
commit
63dec0ede2
2 changed files with 13 additions and 4 deletions
|
|
@ -231,9 +231,9 @@ class SpotiQueue {
|
|||
this.socket && this.socket.readyState === WebSocket.OPEN &&
|
||||
!this.startedPlaying
|
||||
) {
|
||||
Spicetify.Player.pause();
|
||||
console.log("[SpotiQueue] Requesting new song...");
|
||||
this.send({ c: "next_song" });
|
||||
Spicetify.Player.pause();
|
||||
}
|
||||
this.startedPlaying = false;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@ export type MergedQueue = { user: string; song: Song }[];
|
|||
export class PlayerManager {
|
||||
private userQueue: { [x: string]: UserQueue } = {};
|
||||
private nextUserIndex = 0;
|
||||
private queueStopped = false;
|
||||
public mergedQueue: MergedQueue = [];
|
||||
|
||||
|
||||
public login(name: string, userWS: UserWS): UserQueue {
|
||||
if (name in this.userQueue) {
|
||||
const user = this.userQueue[name];
|
||||
|
|
@ -23,8 +25,7 @@ export class PlayerManager {
|
|||
}
|
||||
|
||||
this.userQueue[name] = {
|
||||
queue: [],
|
||||
userWS,
|
||||
queue: [], userWS,
|
||||
};
|
||||
|
||||
return this.userQueue[name];
|
||||
|
|
@ -39,7 +40,10 @@ export class PlayerManager {
|
|||
}
|
||||
public getNext(): Song | null {
|
||||
const song = this.mergedQueue.shift();
|
||||
if (song === undefined) return null;
|
||||
if (song === undefined) {
|
||||
this.queueStopped = true;
|
||||
return null
|
||||
};
|
||||
|
||||
if (song.user in this.userQueue) {
|
||||
const user = this.userQueue[song.user];
|
||||
|
|
@ -57,6 +61,11 @@ export class PlayerManager {
|
|||
public updateMergedQueue() {
|
||||
this.generateMergedQueue();
|
||||
this.broadcastMergedQueue();
|
||||
|
||||
if (this.queueStopped && this.mergedQueue.length > 0) {
|
||||
this.queueStopped = false;
|
||||
spotify?.sendSong();
|
||||
}
|
||||
}
|
||||
private broadcastMergedQueue() {
|
||||
for (const user of Object.values(this.userQueue)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue