magmastream 2.9.0-dev.20 → 2.9.0-dev.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -594,6 +594,7 @@ declare class Queue extends Array<Track> implements IQueue {
|
|
|
594
594
|
getPrevious(): Promise<Track[]>;
|
|
595
595
|
addPrevious(track: Track | Track[]): Promise<void>;
|
|
596
596
|
setPrevious(tracks: Track[]): Promise<void>;
|
|
597
|
+
popPrevious(): Promise<Track | null>;
|
|
597
598
|
clearPrevious(): Promise<void>;
|
|
598
599
|
/**
|
|
599
600
|
* The total duration of the queue in milliseconds.
|
|
@@ -921,6 +922,8 @@ interface IQueue {
|
|
|
921
922
|
getPrevious(): Promise<Track[]>;
|
|
922
923
|
addPrevious(track: Track | Track[]): Promise<void>;
|
|
923
924
|
setPrevious(track: Track | Track[]): Promise<void>;
|
|
925
|
+
/** Get newest track (index 0) */
|
|
926
|
+
popPrevious(): Promise<Track | null>;
|
|
924
927
|
clearPrevious(): Promise<void>;
|
|
925
928
|
size(): Promise<number>;
|
|
926
929
|
totalSize(): Promise<number>;
|
package/dist/structures/Node.js
CHANGED
|
@@ -663,25 +663,17 @@ class Player {
|
|
|
663
663
|
* @emits {PlayerStateUpdate} - With {@link PlayerStateEventTypes.TrackChange} as the change type.
|
|
664
664
|
*/
|
|
665
665
|
async previous() {
|
|
666
|
-
//
|
|
667
|
-
|
|
666
|
+
// Get and remove the most recent previous track
|
|
667
|
+
const lastTrack = await this.queue.popPrevious();
|
|
668
|
+
if (!lastTrack) {
|
|
668
669
|
throw new Error("No previous track available.");
|
|
669
670
|
}
|
|
670
671
|
// Capture the current state of the player before making changes.
|
|
671
672
|
const oldPlayer = { ...this };
|
|
672
|
-
//
|
|
673
|
-
// let currentTrackBeforeChange: Track | null = this.queue.current ? (this.queue.current as Track) : null;
|
|
674
|
-
// Get the last played track and remove it from the history
|
|
675
|
-
const previousTracks = await this.queue.getPrevious();
|
|
676
|
-
const lastTrack = previousTracks.pop();
|
|
677
|
-
await this.queue.clearPrevious();
|
|
678
|
-
await this.queue.addPrevious(previousTracks);
|
|
679
|
-
// Set the skip flag to true to prevent the onTrackEnd event from playing the next track.
|
|
673
|
+
// Set skip flag so trackEnd doesn't add current to previous
|
|
680
674
|
this.set("skipFlag", true);
|
|
681
675
|
await this.play(lastTrack);
|
|
682
|
-
//
|
|
683
|
-
// if (currentTrackBeforeChange) this.queue.push(currentTrackBeforeChange);
|
|
684
|
-
// Emit a player state update event indicating the track change to previous.
|
|
676
|
+
// Emit state update
|
|
685
677
|
this.manager.emit(Manager_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this, {
|
|
686
678
|
changeType: Manager_1.PlayerStateEventTypes.TrackChange,
|
|
687
679
|
details: {
|
|
@@ -689,8 +681,6 @@ class Player {
|
|
|
689
681
|
track: lastTrack,
|
|
690
682
|
},
|
|
691
683
|
});
|
|
692
|
-
// Reset the skip flag.
|
|
693
|
-
this.set("skipFlag", false);
|
|
694
684
|
return this;
|
|
695
685
|
}
|
|
696
686
|
/**
|
package/dist/structures/Queue.js
CHANGED
|
@@ -63,6 +63,10 @@ class RedisQueue {
|
|
|
63
63
|
await this.redis.del(this.previousKey);
|
|
64
64
|
await this.redis.rpush(this.previousKey, ...tracks.map(this.serialize));
|
|
65
65
|
}
|
|
66
|
+
async popPrevious() {
|
|
67
|
+
const raw = await this.redis.lpop(this.previousKey); // get newest track (index 0)
|
|
68
|
+
return raw ? this.deserialize(raw) : null;
|
|
69
|
+
}
|
|
66
70
|
async clearPrevious() {
|
|
67
71
|
await this.redis.del(this.previousKey);
|
|
68
72
|
}
|