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)) {
|
if (this.requiredEvents.includes(eventName) && !super.eventNames().includes(eventName)) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(...args);
|
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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return super.emit(eventName, ...args);
|
return super.emit(eventName, ...args);
|
||||||
|
|
|
@ -106,7 +106,8 @@ class Queue<T = unknown> {
|
||||||
},
|
},
|
||||||
initialVolume: 100,
|
initialVolume: 100,
|
||||||
bufferingTimeout: 3000,
|
bufferingTimeout: 3000,
|
||||||
spotifyBridge: true
|
spotifyBridge: true,
|
||||||
|
disableVolume: false
|
||||||
} as PlayerOptions,
|
} as PlayerOptions,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
@ -695,7 +696,8 @@ class Queue<T = unknown> {
|
||||||
|
|
||||||
const resource: AudioResource<Track> = this.connection.createStream(stream, {
|
const resource: AudioResource<Track> = this.connection.createStream(stream, {
|
||||||
type: StreamType.Raw,
|
type: StreamType.Raw,
|
||||||
data: track
|
data: track,
|
||||||
|
disableVolume: Boolean(this.options.disableVolume)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.seek) this._streamTime = options.seek;
|
if (options.seek) this._streamTime = options.seek;
|
||||||
|
|
|
@ -133,11 +133,12 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
* @returns {AudioResource}
|
* @returns {AudioResource}
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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, {
|
this.audioResource = createAudioResource(src, {
|
||||||
inputType: ops?.type ?? StreamType.Arbitrary,
|
inputType: ops?.type ?? StreamType.Arbitrary,
|
||||||
metadata: ops?.data,
|
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;
|
return this.audioResource;
|
||||||
|
@ -223,9 +224,8 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
setVolume(value: number) {
|
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);
|
this.audioResource.volume.setVolumeLogarithmic(value / 100);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get volume() {
|
get volume() {
|
||||||
if (!this.audioResource || !this.audioResource.volume) return 100;
|
if (!this.audioResource?.volume) return 100;
|
||||||
const currentVol = this.audioResource.volume.volume;
|
const currentVol = this.audioResource.volume.volume;
|
||||||
return Math.round(Math.pow(currentVol, 1 / 1.660964) * 100);
|
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} [initialVolume=100] The initial player volume
|
||||||
* @property {number} [bufferingTimeout=3000] Buffering timeout for the stream
|
* @property {number} [bufferingTimeout=3000] Buffering timeout for the stream
|
||||||
* @property {boolean} [spotifyBridge=true] If player should bridge spotify source to youtube
|
* @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
|
* @property {Function} [onBeforeCreateStream] Runs before creating stream
|
||||||
*/
|
*/
|
||||||
export interface PlayerOptions {
|
export interface PlayerOptions {
|
||||||
|
@ -146,6 +147,7 @@ export interface PlayerOptions {
|
||||||
initialVolume?: number;
|
initialVolume?: number;
|
||||||
bufferingTimeout?: number;
|
bufferingTimeout?: number;
|
||||||
spotifyBridge?: boolean;
|
spotifyBridge?: boolean;
|
||||||
|
disableVolume?: boolean;
|
||||||
onBeforeCreateStream?: (track: Track, source: TrackSource, queue: Queue) => Promise<Readable>;
|
onBeforeCreateStream?: (track: Track, source: TrackSource, queue: Queue) => Promise<Readable>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue