feat(Player): add connectionTimeout option

This commit is contained in:
DevAndromeda 2021-08-07 21:19:31 +05:45
parent 5ce8e99d01
commit 5a5e308105
No known key found for this signature in database
GPG key ID: FA40E3EC5CB6DCD6
4 changed files with 9 additions and 5 deletions

View file

@ -24,7 +24,8 @@ class Player extends EventEmitter<PlayerEvents> {
autoRegisterExtractor: true,
ytdlOptions: {
highWaterMark: 1 << 25
}
},
connectionTimeout: 20000
};
public readonly queues = new Collection<Snowflake, Queue>();
public readonly voiceUtils = new VoiceUtils();

View file

@ -146,7 +146,8 @@ class Queue<T = unknown> {
if (!["GUILD_STAGE_VOICE", "GUILD_VOICE"].includes(_channel?.type))
throw new PlayerError(`Channel type must be GUILD_VOICE or GUILD_STAGE_VOICE, got ${_channel?.type}!`, ErrorStatusCode.INVALID_ARG_TYPE);
const connection = await this.player.voiceUtils.connect(_channel, {
deaf: this.options.autoSelfDeaf
deaf: this.options.autoSelfDeaf,
maxTime: this.player.options.connectionTimeout || 20000
});
this.connection = connection;

View file

@ -41,7 +41,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
* @param {VoiceChannel|StageChannel} channel The connected channel
* @private
*/
constructor(connection: VoiceConnection, channel: VoiceChannel | StageChannel) {
constructor(connection: VoiceConnection, channel: VoiceChannel | StageChannel, public readonly connectionTimeout: number = 20000) {
super();
/**
@ -72,7 +72,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
if (newState.status === VoiceConnectionStatus.Disconnected) {
if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
try {
await entersState(this.voiceConnection, VoiceConnectionStatus.Connecting, 5000);
await entersState(this.voiceConnection, VoiceConnectionStatus.Connecting, this.connectionTimeout);
} catch {
this.voiceConnection.destroy();
}
@ -87,7 +87,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
} else if (!this.readyLock && (newState.status === VoiceConnectionStatus.Connecting || newState.status === VoiceConnectionStatus.Signalling)) {
this.readyLock = true;
try {
await entersState(this.voiceConnection, VoiceConnectionStatus.Ready, 20000);
await entersState(this.voiceConnection, VoiceConnectionStatus.Ready, this.connectionTimeout);
} catch {
if (this.voiceConnection.state.status !== VoiceConnectionStatus.Destroyed) this.voiceConnection.destroy();
} finally {

View file

@ -454,8 +454,10 @@ export interface PlaylistJSON {
* @typedef {object} PlayerInitOptions
* @property {boolean} [autoRegisterExtractor=true] If it should automatically register `@discord-player/extractor`
* @property {YTDLDownloadOptions} [ytdlOptions={}] The options passed to `ytdl-core`
* @property {number} [connectionTimeout=20000] The voice connection timeout
*/
export interface PlayerInitOptions {
autoRegisterExtractor?: boolean;
ytdlOptions?: downloadOptions;
connectionTimeout?: number;
}