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>;
@@ -546,6 +546,7 @@ class Node {
546
546
  await player.queue.setPrevious(trimmed);
547
547
  }
548
548
  }
549
+ player.set("skipFlag", false);
549
550
  const oldPlayer = player;
550
551
  // Handle track end events
551
552
  switch (reason) {
@@ -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
- // Check if there are previous tracks in the queue.
667
- if (!(await this.queue.getPrevious()).length) {
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
- // Store the current track before changing it.
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
- // Add the current track back to the end of the previous queue
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
  /**
@@ -46,6 +46,9 @@ class Queue extends Array {
46
46
  async setPrevious(tracks) {
47
47
  this.previous = [...tracks];
48
48
  }
49
+ async popPrevious() {
50
+ return this.previous.shift() || null; // get newest track
51
+ }
49
52
  async clearPrevious() {
50
53
  this.previous = [];
51
54
  }
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.9.0-dev.20",
3
+ "version": "2.9.0-dev.22",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",