diff --git a/package.json b/package.json index a9d78a8..9058b22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "damonjs", - "version": "1.5.0", + "version": "1.5.1", "preview": false, "description": "A modified Shoukaku wrapper with enhanced queue support.", "main": "dist/Index.js", diff --git a/src/Index.ts b/src/Index.ts index 5d77312..5016b6f 100644 --- a/src/Index.ts +++ b/src/Index.ts @@ -8,4 +8,4 @@ export * from './DamonJs'; export { DamonJsTrack, DamonJsQueue, DamonJsPlayer, Plugins }; export * from './Modules/Interfaces'; -export const version = '1.5.0'; +export const version = '1.5.1'; diff --git a/src/Managers/DamonJsPlayer.ts b/src/Managers/DamonJsPlayer.ts index 2cda8ee..4d5ef39 100644 --- a/src/Managers/DamonJsPlayer.ts +++ b/src/Managers/DamonJsPlayer.ts @@ -281,15 +281,15 @@ export class DamonJsPlayer { * @param {PlayOptions} options Play options * @returns {Promise} */ - public async play(track?: DamonJsTrack, options?: PlayOptions): Promise { + public async play(tracks?: DamonJsTrack[], options?: PlayOptions): Promise { if (this.state === PlayerState.DESTROYED) throw new DamonJsError(1, 'Player is already destroyed'); - if (!track && !this.queue.totalSize) throw new DamonJsError(1, 'No track is available to play'); + if (!tracks && !this.queue.totalSize) throw new DamonJsError(1, 'No track is available to play'); if (!options) options = { replaceCurrent: false }; - if (track) { - this.queue.splice(this.queue.currentId, options.replaceCurrent && this.queue.current ? 1 : 0, track); + if (tracks) { + this.queue.splice(this.queue.currentId, options.replaceCurrent && this.queue.current ? 1 : 0, ...tracks); } if (this.playable) { diff --git a/src/Managers/Supports/DamonJsQueue.ts b/src/Managers/Supports/DamonJsQueue.ts index dafb67b..a0b06da 100644 --- a/src/Managers/Supports/DamonJsQueue.ts +++ b/src/Managers/Supports/DamonJsQueue.ts @@ -94,8 +94,26 @@ export class DamonJsQueue extends Array { return this; } public removeDupes(): DamonJsQueue { - const newQueue = [...new Set(this)]; - this.splice(0, this.length, ...newQueue); + const trackUris = new Set(); + const playedTracks = this.slice(0, this.currentId); + const unplayedTracks = this.slice(this.currentId + 1); + const currentTrack = this[this.currentId]; + trackUris.add(currentTrack.uri); + + const newPlayedTracks = playedTracks.filter((track) => { + if (trackUris.has(track.uri)) return false; + trackUris.add(track.uri); + return true; + }); + + const newUnplayedTracks = unplayedTracks.filter((track) => { + if (trackUris.has(track.uri)) return false; + trackUris.add(track.uri); + return true; + }); + + this.currentId = newPlayedTracks.length; + this.splice(0, this.length, ...newPlayedTracks, currentTrack, ...newUnplayedTracks); this.player.emit(Events.InitQueue, this.player); return this; }