UNPKG

damonjs

Version:

A modified Shoukaku wrapper with enhanced queue support.

813 lines (812 loc) 35 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DamonJsPlayer = void 0; const DamonJsQueue_1 = require("./Supports/DamonJsQueue"); const Interfaces_1 = require("../Modules/Interfaces"); const events_1 = __importDefault(require("events")); class DamonJsPlayer { constructor(damonjs, shoukaku, player, connection, options) { this.lockMap = new Map(); this.state = Interfaces_1.PlayerState.CONNECTING; this.loop = Interfaces_1.LoopState.None; this.playbackQueue = { operations: [], isProcessing: false, }; this.options = options; this.damonjs = damonjs; this.player = player; this.events = new events_1.default(); this.connection = connection; this.shoukaku = shoukaku; this.queue = new DamonJsQueue_1.DamonJsQueue(this); this.data = new Map(options.data); this.textId = this.options.textId; this.stats = { skipAttemptData: { skipAttempts: [], destroyTriggers: [], lastSkipTime: 0 }, }; this.search = (query, searchOptions) => this.damonjs.search(query, searchOptions, this); } executePlaybackOperation(name, operation, priority = 1) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { this.playbackQueue.operations.push({ priority, name, operation, resolve, reject, }); this.playbackQueue.operations.sort((a, b) => b.priority - a.priority); if (!this.playbackQueue.isProcessing) { this.processPlaybackQueue(); } }); }); } processPlaybackQueue() { return __awaiter(this, void 0, void 0, function* () { if (this.playbackQueue.isProcessing || this.playbackQueue.operations.length === 0) return; this.playbackQueue.isProcessing = true; while (this.playbackQueue.operations.length > 0) { const current = this.playbackQueue.operations.shift(); if (!current) continue; try { const result = yield current.operation(); this.emit(Interfaces_1.Events.Debug, this, `Executed ${current.name} operation successfully`); current.resolve(result); } catch (error) { this.emit(Interfaces_1.Events.Debug, this, `Failed to execute ${current.name} operation: ${error instanceof Error ? error.message : String(error)}`); current.reject(error instanceof Error ? error : new Error(String(error))); } } this.playbackQueue.isProcessing = false; if (this.playbackQueue.operations.length > 0) { this.processPlaybackQueue(); } }); } init() { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.CONNECTED) throw new Interfaces_1.DamonJsError(1, 'Player is already initialized or initializing'); yield this.setGlobalVolume(this.options.volume); this.initEventListeners(); this.state = Interfaces_1.PlayerState.CONNECTED; }); } initEventListeners() { const eventHandlers = { start: () => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackStart(); }), end: (data) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackEnd(data); }), closed: (data) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackClosed(data); }), exception: (data) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackException(data); }), update: (data) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackUpdate(data); }), stuck: (data) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackStuck(data); }), resumed: () => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackResumed(); }), empty: () => __awaiter(this, void 0, void 0, function* () { yield this.handlePlayerEmpty(); }), resolveError: (resolveResult) => __awaiter(this, void 0, void 0, function* () { yield this.handleResolveError(resolveResult); }), trackPlay: (tracks, options) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackPlay(tracks, options); }), trackSkip: (trackId) => __awaiter(this, void 0, void 0, function* () { yield this.handleTrackSkip(trackId); }), playerDestroy: () => __awaiter(this, void 0, void 0, function* () { yield this.handlePlayerDestroy(); }), }; const shoukakuEvents = ['start', 'end', 'closed', 'exception', 'update', 'stuck', 'resumed']; shoukakuEvents.forEach((event) => { this.player.on(event, (data) => this.events.emit(event, data)); }); const damonjsEvents = [ 'start', 'end', 'closed', 'exception', 'update', 'stuck', 'resumed', 'empty', 'resolveError', 'trackPlay', 'trackSkip', 'playerDestroy', ]; damonjsEvents.forEach((event) => { this.events.on(event, (data) => eventHandlers[event](data)); }); } // playback functions (HAPPENS SEQUANTIALLY) handleTrackEnd(data) { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('trackEnd', () => __awaiter(this, void 0, void 0, function* () { const currentTrack = this.queue.current; if (currentTrack) { this.queue.current = undefined; this.emit(Interfaces_1.Events.PlayerEnd, this, currentTrack, data); } if (this.damonjs.trackEnd.skip) { const trackId = this.queue.currentId + 1; this.events.emit('trackSkip', trackId); } }), 2); }); } handleTrackException(data) { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('trackStart', () => __awaiter(this, void 0, void 0, function* () { const currentTrack = this.queue.current; if (currentTrack) { this.queue.current = undefined; this.emit(Interfaces_1.Events.PlayerException, this, currentTrack, data); } if (this.damonjs.trackException.skip) { const trackId = this.queue.currentId + 1; this.events.emit('trackSkip', trackId); } }), 2); }); } handleTrackStuck(data) { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('trackStuck', () => __awaiter(this, void 0, void 0, function* () { const currentTrack = this.queue.current; if (currentTrack) { this.queue.current = undefined; this.emit(Interfaces_1.Events.PlayerStuck, this, currentTrack, data); } if (this.damonjs.trackStuck.skip) { const trackId = this.queue.currentId + 1; this.events.emit('trackSkip', trackId); } }), 2); }); } handleResolveError(resolveResult) { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('resolveError', () => __awaiter(this, void 0, void 0, function* () { const currentTrack = this.queue.current; if (currentTrack) { this.queue.current = undefined; this.emit(Interfaces_1.Events.PlayerResolveError, this, currentTrack, resolveResult.message); } if (this.damonjs.trackResolveError.skip) { const trackId = this.queue.currentId + 1; this.events.emit('trackSkip', trackId); } }), 2); }); } handleTrackStart() { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('trackStart', () => __awaiter(this, void 0, void 0, function* () { const currentTrack = this.queue.current; if (!currentTrack) { return this.emit(Interfaces_1.Events.Debug, this, `No track to start ${this.guildId}`); } this.player.paused = false; this.emit(Interfaces_1.Events.PlayerStart, this, currentTrack); }), 2); }); } handlePlayerEmpty() { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('playerEmpty', () => __awaiter(this, void 0, void 0, function* () { this.emit(Interfaces_1.Events.PlayerEmpty, this, this.queue.lastTrack); return this; }), 1); }); } handleTrackSkip(trackId) { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('trackSkip', () => __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) { throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); } const now = Date.now(); const playAttempts = this.stats.skipAttemptData.skipAttempts.filter((time) => now - time < this.damonjs.skipSpam.rule.timeFrame); const destroyTriggers = this.stats.skipAttemptData.destroyTriggers.filter((time) => now - time < this.damonjs.skipSpam.destroy.timeFrame); playAttempts.push(now); this.stats.skipAttemptData.skipAttempts = playAttempts; this.stats.skipAttemptData.lastSkipTime = now; if (playAttempts.length >= this.damonjs.skipSpam.rule.maxhits) { destroyTriggers.push(now); this.stats.skipAttemptData.destroyTriggers = destroyTriggers; if (destroyTriggers.length >= this.damonjs.skipSpam.destroy.maxhits) { this.emit(Interfaces_1.Events.Debug, this, `Player ${this.guildId} skipped too many times, destroying`); this.events.emit('playerDestroy'); return this; } this.emit(Interfaces_1.Events.Debug, this, `Player ${this.guildId} skipped too many times, in cooldown for ${this.damonjs.skipSpam.rule.cooldown}ms`); yield new Promise((resolve) => setTimeout(resolve, this.damonjs.skipSpam.rule.cooldown)); } if (this.loop === Interfaces_1.LoopState.Track) { this.queue.currentId = this.queue.currentId; } else if (this.loop === Interfaces_1.LoopState.Queue && this.queue.isEnd) { this.queue.currentId = 0; } else if (this.queue[trackId]) { this.queue.currentId = trackId; } else if (this.queue.length <= trackId) { this.queue.currentId = this.queue.length; } else { this.queue.currentId = this.queue.length - 1; } this.events.emit('trackPlay'); return this; }), 2); }); } handleTrackPlay(tracks, options) { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('play', () => __awaiter(this, void 0, void 0, function* () { var _a; if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); if (!tracks && !this.queue.totalSize) throw new Interfaces_1.DamonJsError(1, 'No track is available to play'); if (tracks) { if ((options === null || options === void 0 ? void 0 : options.replaceCurrent) && this.queue.current) { // Remove current track and add new tracks at current position this.queue.splice(this.queue.currentId, 1, ...tracks); } else { // Add after current track this.queue.splice(this.queue.currentId, 0, ...tracks); } } if (this.queue.current) { this.queue.currentId--; yield this.stopTrack(); return this; } const currentTrack = this.queue.at(this.queue.currentId); if (!currentTrack) { this.events.emit('empty'); throw new Interfaces_1.DamonJsError(1, 'No track is available to play'); } this.queue.current = currentTrack; currentTrack.setDamonJs(this.damonjs); const resolveResult = yield currentTrack.resolve({ player: this }).catch((e) => e); if (resolveResult instanceof Error) { this.events.emit('resolveError', resolveResult); throw new Interfaces_1.DamonJsError(1, `Player ${this.guildId} resolve error: ${resolveResult.message}-${currentTrack.identifier}`); } let playOptions = { track: { encoded: currentTrack.encoded, userData: (_a = currentTrack.requester) !== null && _a !== void 0 ? _a : {} } }; if (options) playOptions = Object.assign(Object.assign({}, playOptions), options); const playerResult = yield this.player.playTrack(playOptions).catch((e) => e); if (playerResult instanceof Error) { this.events.emit('resolveError', playerResult); throw new Interfaces_1.DamonJsError(1, `Player ${this.guildId} resolve error: ${playerResult.message}-${currentTrack.identifier}`); } return this; }), 2); }); } handlePlayerDestroy() { return __awaiter(this, void 0, void 0, function* () { return this.executePlaybackOperation('destroy', () => __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYING || this.state === Interfaces_1.PlayerState.DESTROYED) { throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); } this.state = Interfaces_1.PlayerState.DESTROYING; this.events.removeAllListeners(); this.lockMap.clear(); this.queue.clear(); this.data.clear(); yield this.shoukaku.leaveVoiceChannel(this.guildId); this.damonjs.players.delete(this.guildId); this.state = Interfaces_1.PlayerState.DESTROYED; this.emit(Interfaces_1.Events.PlayerDestroy, this, this.queue.current); this.emit(Interfaces_1.Events.Debug, this, `Player destroyed; Guild id: ${this.guildId}`); return this; }), 2); }); } // NON playback operations (does not go sequentially) handleTrackResumed() { return __awaiter(this, void 0, void 0, function* () { this.emit(Interfaces_1.Events.PlayerResumed, this); }); } handleTrackClosed(data) { return __awaiter(this, void 0, void 0, function* () { this.emit(Interfaces_1.Events.PlayerClosed, this, data); }); } handleTrackUpdate(data) { return __awaiter(this, void 0, void 0, function* () { if (!this.queue.current) { return this.emit(Interfaces_1.Events.Debug, this, `No Track to Update ${this.guildId}`); } this.queue.current.position = data.state.position || 0; this.emit(Interfaces_1.Events.PlayerUpdate, this, this.queue.current, data); }); } /** * Get GuildId */ get guildId() { return this.connection.guildId; } /** * Get VoiceId */ get voiceId() { return this.connection.channelId; } /** * Get Deaf Status */ get deaf() { return this.connection.deafened; } /** * Get Playing Status */ get playing() { return this.queue.current && !this.player.paused ? true : false; } /** * Get Paused Status */ get paused() { return this.player.paused; } /** * Get Mute Status */ get mute() { return this.connection.muted; } /** * Get volume */ get volume() { return this.player.volume; } /** * Get Filter volume */ get filterVolume() { return this.player.filters.volume; } /** * Get player position */ get position() { return this.player.position; } /** * Get filters */ get filters() { return this.player.filters; } get node() { return this.player.node; } /** * Pause the player * @param pause Whether to pause or not * @returns Promise<DamonJsPlayer> */ pause(pause) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); if (this.paused === pause || !this.queue.totalSize) return this; yield this.player.setPaused(pause); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Set loop mode * @param [loop] Loop mode * @returns DamonJsPlayer */ setLoop(loop) { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); if (loop === undefined) { if (this.loop === Interfaces_1.LoopState.None) this.loop = Interfaces_1.LoopState.Queue; else if (this.loop === Interfaces_1.LoopState.Queue) this.loop = Interfaces_1.LoopState.Track; else if (this.loop === Interfaces_1.LoopState.Track) this.loop = Interfaces_1.LoopState.None; } else this.loop = loop; this.emit(Interfaces_1.Events.InitQueue, this); return this; } /** * Play a track * @param {DamonJsTrack} tracks Track to play * @param {PlayOptions} options Play options * @returns {Promise<DamonJsPlayer>} */ play(tracks, options) { return __awaiter(this, void 0, void 0, function* () { return this.handleTrackPlay(tracks, options); }); } /** * Skips to the next track in the queue. * @returns {Promise<DamonJsPlayer>} */ skip() { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) { throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); } const trackId = this.queue.currentId + 1; yield this.skipto(trackId); return this; }); } /** * Stops the currently playing track. * @returns {Promise<DamonJsPlayer>} */ stopTrack() { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) { throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); } yield this.player.stopTrack(); return this; }); } /** * Skips to the previous track in the queue. * @returns {Promise<DamonJsPlayer>} */ previous() { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) { throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); } const trackId = this.queue.currentId - 1; yield this.skipto(trackId); return this; }); } /** * Skips to the specified track in the queue. * If the player is in a destroyed state, it will throw an error. * If the player is currently looping the track or queue, it will continue to do so. * If the provided track ID exists in the queue, it will skip to that track. * If the provided track ID is greater than the queue length, it will skip to the last track. * If the provided track ID is out of bounds, it will skip to the previous track. * * @param trackId - The ID of the track to skip to. * @returns A Promise that resolves to the DamonJsPlayer instance. * @throws {DamonJsError} If the player is already destroyed. */ skipto(trackId) { return __awaiter(this, void 0, void 0, function* () { return this.handleTrackSkip(trackId); }); } /** * seek to a specifc position * @param position Position * @returns Promise<DamonJsPlayer> */ seek(position) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); if (!this.queue.current) throw new Interfaces_1.DamonJsError(1, "Player has no current track in it's queue"); if (!this.queue.current.isSeekable) throw new Interfaces_1.DamonJsError(1, "The current track isn't seekable"); position = Number(position); if (isNaN(position)) throw new Interfaces_1.DamonJsError(1, 'position must be a number'); if (position < 0 || position > ((_a = this.queue.current.length) !== null && _a !== void 0 ? _a : 0)) position = Math.max(Math.min(position, (_b = this.queue.current.length) !== null && _b !== void 0 ? _b : 0), 0); yield this.player.seekTo(position); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Set the Global volume * @param volume Volume * @returns Promise<DamonJsPlayer> */ setGlobalVolume(volume) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); if (isNaN(volume)) throw new Interfaces_1.DamonJsError(1, 'volume must be a number'); yield this.player.setGlobalVolume(volume); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Set the Filter volume * @param volume Volume * @returns Promise<DamonJsPlayer> */ setFilterVolume(volume) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); if (isNaN(volume)) throw new Interfaces_1.DamonJsError(1, 'volume must be a number'); yield this.player.setFilterVolume(volume / 100); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Set voice channel and move the player to the voice channel * @param voiceId Voice channel ID * @returns DamonJsPlayer */ setVoiceChannel(voiceId) { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); this.state = Interfaces_1.PlayerState.CONNECTING; this.connection.channelId = voiceId; this.connection.manager.connector.sendPacket(this.connection.shardId, { op: 4, d: { guild_id: this.guildId, channel_id: this.voiceId, self_deaf: this.deaf, self_mute: this.mute }, }, false); this.state = Interfaces_1.PlayerState.CONNECTED; this.emit(Interfaces_1.Events.Debug, this, `Player ${this.guildId} moved to voice channel ${voiceId}`); this.emit(Interfaces_1.Events.InitQueue, this); return this; } /** * Set text channel * @param textId Text channel ID * @returns DamonJsPlayer */ setTextChannel(textId) { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); this.textId = textId; this.emit(Interfaces_1.Events.InitQueue, this); return this; } /** * Set the Mute State * @param mute Mute State * @returns DamonJsPlayer */ setMute(mute) { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); this.connection.setMute(mute); this.emit(Interfaces_1.Events.InitQueue, this); return this; } /** * Set the Deaf State * @param deaf Deaf State * @returns DamonJsPlayer */ setDeaf(deaf) { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); this.connection.setDeaf(deaf); this.emit(Interfaces_1.Events.InitQueue, this); return this; } /** * Change the equalizer settings applied to the currently playing track * @param equalizer An array of objects that conforms to the Bands type that define volumes at different frequencies * @returns Promise<DamonJsPlayer> */ setEqualizer(equalizer) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setEqualizer(equalizer); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the karaoke settings applied to the currently playing track * @param karaoke An object that conforms to the KaraokeSettings type that defines a range of frequencies to mute * @returns Promise<DamonJsPlayer> */ setKaraoke(karaoke) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setKaraoke(karaoke); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the timescale settings applied to the currently playing track * @param timescale An object that conforms to the TimescaleSettings type that defines the time signature to play the audio at * @returns Promise<DamonJsPlayer> */ setTimescale(timescale) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setTimescale(timescale); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the tremolo settings applied to the currently playing track * @param tremolo An object that conforms to the FreqSettings type that defines an oscillation in volume * @returns Promise<DamonJsPlayer> */ setTremolo(tremolo) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setTremolo(tremolo); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the vibrato settings applied to the currently playing track * @param vibrato An object that conforms to the FreqSettings type that defines an oscillation in pitch * @returns Promise<DamonJsPlayer> */ setVibrato(vibrato) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setVibrato(vibrato); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the rotation settings applied to the currently playing track * @param rotation An object that conforms to the RotationSettings type that defines the frequency of audio rotating round the listener * @returns Promise<DamonJsPlayer> */ setRotation(rotation) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setRotation(rotation); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the distortion settings applied to the currently playing track * @param distortion An object that conforms to DistortionSettings that defines distortions in the audio * @returns Promise<DamonJsPlayer> */ setDistortion(distortion) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setDistortion(distortion); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the channel mix settings applied to the currently playing track * @param channelMix An object that conforms to ChannelMixSettings that defines how much the left and right channels affect each other (setting all factors to 0.5 causes both channels to get the same audio) * @returns Promise<DamonJsPlayer> */ setChannelMix(channelMix) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setChannelMix(channelMix); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the low pass settings applied to the currently playing track * @param lowPass An object that conforms to LowPassSettings that defines the amount of suppression on higher frequencies * @returns Promise<DamonJsPlayer> */ setLowPass(lowPass) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.setLowPass(lowPass); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Change the all filter settings applied to the currently playing track * @param filters An object that conforms to FilterOptions that defines all filters to apply/modify * @returns Promise<DamonJsPlayer> */ setFilters(filters) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.setFilters(filters); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Move player to another node * @param name? Name of node to move to, or the default ideal node * @returns true if the player was moved, false if not */ move(name) { return __awaiter(this, void 0, void 0, function* () { if (this.state === Interfaces_1.PlayerState.DESTROYED) throw new Interfaces_1.DamonJsError(1, 'Player is already destroyed'); yield this.player.move(name); this.emit(Interfaces_1.Events.InitQueue, this); return this; }); } /** * Destroy the player * @returns Promise<DamonJsPlayer> */ destroy() { return __awaiter(this, void 0, void 0, function* () { return this.handlePlayerDestroy(); }); } emit(event, ...args) { this.damonjs.emit(event, ...args); } } exports.DamonJsPlayer = DamonJsPlayer;