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,
|
autoRegisterExtractor: true,
|
||||||
ytdlOptions: {
|
ytdlOptions: {
|
||||||
highWaterMark: 1 << 25
|
highWaterMark: 1 << 25
|
||||||
}
|
},
|
||||||
|
connectionTimeout: 20000
|
||||||
};
|
};
|
||||||
public readonly queues = new Collection<Snowflake, Queue>();
|
public readonly queues = new Collection<Snowflake, Queue>();
|
||||||
public readonly voiceUtils = new VoiceUtils();
|
public readonly voiceUtils = new VoiceUtils();
|
||||||
|
|
|
@ -146,7 +146,8 @@ class Queue<T = unknown> {
|
||||||
if (!["GUILD_STAGE_VOICE", "GUILD_VOICE"].includes(_channel?.type))
|
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);
|
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, {
|
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;
|
this.connection = connection;
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
* @param {VoiceChannel|StageChannel} channel The connected channel
|
* @param {VoiceChannel|StageChannel} channel The connected channel
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
constructor(connection: VoiceConnection, channel: VoiceChannel | StageChannel) {
|
constructor(connection: VoiceConnection, channel: VoiceChannel | StageChannel, public readonly connectionTimeout: number = 20000) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
if (newState.status === VoiceConnectionStatus.Disconnected) {
|
if (newState.status === VoiceConnectionStatus.Disconnected) {
|
||||||
if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
|
if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
|
||||||
try {
|
try {
|
||||||
await entersState(this.voiceConnection, VoiceConnectionStatus.Connecting, 5000);
|
await entersState(this.voiceConnection, VoiceConnectionStatus.Connecting, this.connectionTimeout);
|
||||||
} catch {
|
} catch {
|
||||||
this.voiceConnection.destroy();
|
this.voiceConnection.destroy();
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
} else if (!this.readyLock && (newState.status === VoiceConnectionStatus.Connecting || newState.status === VoiceConnectionStatus.Signalling)) {
|
} else if (!this.readyLock && (newState.status === VoiceConnectionStatus.Connecting || newState.status === VoiceConnectionStatus.Signalling)) {
|
||||||
this.readyLock = true;
|
this.readyLock = true;
|
||||||
try {
|
try {
|
||||||
await entersState(this.voiceConnection, VoiceConnectionStatus.Ready, 20000);
|
await entersState(this.voiceConnection, VoiceConnectionStatus.Ready, this.connectionTimeout);
|
||||||
} catch {
|
} catch {
|
||||||
if (this.voiceConnection.state.status !== VoiceConnectionStatus.Destroyed) this.voiceConnection.destroy();
|
if (this.voiceConnection.state.status !== VoiceConnectionStatus.Destroyed) this.voiceConnection.destroy();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -454,8 +454,10 @@ export interface PlaylistJSON {
|
||||||
* @typedef {object} PlayerInitOptions
|
* @typedef {object} PlayerInitOptions
|
||||||
* @property {boolean} [autoRegisterExtractor=true] If it should automatically register `@discord-player/extractor`
|
* @property {boolean} [autoRegisterExtractor=true] If it should automatically register `@discord-player/extractor`
|
||||||
* @property {YTDLDownloadOptions} [ytdlOptions={}] The options passed to `ytdl-core`
|
* @property {YTDLDownloadOptions} [ytdlOptions={}] The options passed to `ytdl-core`
|
||||||
|
* @property {number} [connectionTimeout=20000] The voice connection timeout
|
||||||
*/
|
*/
|
||||||
export interface PlayerInitOptions {
|
export interface PlayerInitOptions {
|
||||||
autoRegisterExtractor?: boolean;
|
autoRegisterExtractor?: boolean;
|
||||||
ytdlOptions?: downloadOptions;
|
ytdlOptions?: downloadOptions;
|
||||||
|
connectionTimeout?: number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue