feat(Player): add connectionTimeout option
This commit is contained in:
parent
5ce8e99d01
commit
5a5e308105
4 changed files with 9 additions and 5 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue