diff --git a/src/Player.ts b/src/Player.ts index 9cbd4fd..ed9eaf3 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -561,11 +561,11 @@ class Player extends EventEmitter { return `${depsReport}\n${line}\nLoaded Extractors:\n${extractorReport || "None"}`; } - emit(eventName: U, ...args: Parameters): boolean { + emit(eventName: U, ...args: Parameters): boolean { if (this.requiredEvents.includes(eventName) && !super.eventNames().includes(eventName)) { // eslint-disable-next-line no-console console.error(...args); - process.emitWarning(`[DiscordPlayerWarning] Unhandled "${eventName}" event! Events ${this.requiredEvents.map(m => `"${m}"`).join(", ")} must have event listeners!`); + process.emitWarning(`[DiscordPlayerWarning] Unhandled "${eventName}" event! Events ${this.requiredEvents.map((m) => `"${m}"`).join(", ")} must have event listeners!`); return false; } else { return super.emit(eventName, ...args); diff --git a/src/Structures/Queue.ts b/src/Structures/Queue.ts index 8255546..4b91839 100644 --- a/src/Structures/Queue.ts +++ b/src/Structures/Queue.ts @@ -106,7 +106,8 @@ class Queue { }, initialVolume: 100, bufferingTimeout: 3000, - spotifyBridge: true + spotifyBridge: true, + disableVolume: false } as PlayerOptions, options ); @@ -695,7 +696,8 @@ class Queue { const resource: AudioResource = this.connection.createStream(stream, { type: StreamType.Raw, - data: track + data: track, + disableVolume: Boolean(this.options.disableVolume) }); if (options.seek) this._streamTime = options.seek; diff --git a/src/VoiceInterface/StreamDispatcher.ts b/src/VoiceInterface/StreamDispatcher.ts index 0624b53..96ce549 100644 --- a/src/VoiceInterface/StreamDispatcher.ts +++ b/src/VoiceInterface/StreamDispatcher.ts @@ -133,11 +133,12 @@ class StreamDispatcher extends EventEmitter { * @returns {AudioResource} */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - createStream(src: Readable | Duplex | string, ops?: { type?: StreamType; data?: any }) { + createStream(src: Readable | Duplex | string, ops?: { type?: StreamType; data?: any; disableVolume?: boolean }) { this.audioResource = createAudioResource(src, { inputType: ops?.type ?? StreamType.Arbitrary, metadata: ops?.data, - inlineVolume: true // we definitely need volume controls, right? + // eslint-disable-next-line no-extra-boolean-cast + inlineVolume: !Boolean(ops?.disableVolume) }); return this.audioResource; @@ -223,9 +224,8 @@ class StreamDispatcher extends EventEmitter { * @returns {boolean} */ setVolume(value: number) { - if (!this.audioResource || isNaN(value) || value < 0 || value > Infinity) return false; + if (!this.audioResource?.volume || isNaN(value) || value < 0 || value > Infinity) return false; - // ye boi logarithmic ✌ this.audioResource.volume.setVolumeLogarithmic(value / 100); return true; } @@ -235,7 +235,7 @@ class StreamDispatcher extends EventEmitter { * @type {number} */ get volume() { - if (!this.audioResource || !this.audioResource.volume) return 100; + if (!this.audioResource?.volume) return 100; const currentVol = this.audioResource.volume.volume; return Math.round(Math.pow(currentVol, 1 / 1.660964) * 100); } diff --git a/src/types/types.ts b/src/types/types.ts index 24ded07..3334768 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -134,6 +134,7 @@ export interface PlayerProgressbarOptions { * @property {number} [initialVolume=100] The initial player volume * @property {number} [bufferingTimeout=3000] Buffering timeout for the stream * @property {boolean} [spotifyBridge=true] If player should bridge spotify source to youtube + * @property {boolean} [disableVolume=false] If player should disable inline volume * @property {Function} [onBeforeCreateStream] Runs before creating stream */ export interface PlayerOptions { @@ -146,6 +147,7 @@ export interface PlayerOptions { initialVolume?: number; bufferingTimeout?: number; spotifyBridge?: boolean; + disableVolume?: boolean; onBeforeCreateStream?: (track: Track, source: TrackSource, queue: Queue) => Promise; }