feat(Queue): add option to disable inline volume
This commit is contained in:
parent
3185557833
commit
87d49c688d
4 changed files with 13 additions and 9 deletions
|
@ -565,7 +565,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
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);
|
||||
|
|
|
@ -106,7 +106,8 @@ class Queue<T = unknown> {
|
|||
},
|
||||
initialVolume: 100,
|
||||
bufferingTimeout: 3000,
|
||||
spotifyBridge: true
|
||||
spotifyBridge: true,
|
||||
disableVolume: false
|
||||
} as PlayerOptions,
|
||||
options
|
||||
);
|
||||
|
@ -695,7 +696,8 @@ class Queue<T = unknown> {
|
|||
|
||||
const resource: AudioResource<Track> = this.connection.createStream(stream, {
|
||||
type: StreamType.Raw,
|
||||
data: track
|
||||
data: track,
|
||||
disableVolume: Boolean(this.options.disableVolume)
|
||||
});
|
||||
|
||||
if (options.seek) this._streamTime = options.seek;
|
||||
|
|
|
@ -133,11 +133,12 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
|||
* @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<VoiceEvents> {
|
|||
* @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<VoiceEvents> {
|
|||
* @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);
|
||||
}
|
||||
|
|
|
@ -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<Readable>;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue