





















@@ -35,8 +35,10 @@ import {
3535CAPTURE_FINALIZE_GRACE_MS,
3636isVoiceChannel,
3737logVoiceVerbose,
38+resolveVoiceTimeoutMs,
3839MIN_SEGMENT_SECONDS,
3940VOICE_CONNECT_READY_TIMEOUT_MS,
41+VOICE_RECONNECT_GRACE_MS,
4042type VoiceOperationResult,
4143type VoiceSessionEntry,
4244} from "./session.js";
@@ -172,13 +174,22 @@ export class DiscordVoiceManager {
172174return { ok: false, message: "Discord voice plugin is not available." };
173175}
174176177+const voiceConfig = this.params.discordConfig.voice;
175178const adapterCreator = voicePlugin.getGatewayAdapterCreator(guildId);
176-const daveEncryption = this.params.discordConfig.voice?.daveEncryption;
177-const decryptionFailureTolerance = this.params.discordConfig.voice?.decryptionFailureTolerance;
179+const daveEncryption = voiceConfig?.daveEncryption;
180+const decryptionFailureTolerance = voiceConfig?.decryptionFailureTolerance;
181+const connectReadyTimeoutMs = resolveVoiceTimeoutMs(
182+voiceConfig?.connectTimeoutMs,
183+VOICE_CONNECT_READY_TIMEOUT_MS,
184+);
185+const reconnectGraceMs = resolveVoiceTimeoutMs(
186+voiceConfig?.reconnectGraceMs,
187+VOICE_RECONNECT_GRACE_MS,
188+);
178189logVoiceVerbose(
179190`join: DAVE settings encryption=${daveEncryption === false ? "off" : "on"} tolerance=${
180191 decryptionFailureTolerance ?? "default"
181- }`,
192+ } connectTimeout=${connectReadyTimeoutMs}ms reconnectGrace=${reconnectGraceMs}ms`,
182193);
183194const voiceSdk = loadDiscordVoiceSdk();
184195const connection = voiceSdk.joinVoiceChannel({
@@ -195,10 +206,13 @@ export class DiscordVoiceManager {
195206await voiceSdk.entersState(
196207connection,
197208voiceSdk.VoiceConnectionStatus.Ready,
198-VOICE_CONNECT_READY_TIMEOUT_MS,
209+connectReadyTimeoutMs,
199210);
200211logVoiceVerbose(`join: connected to guild ${guildId} channel ${channelId}`);
201212} catch (err) {
213+logger.warn(
214+`discord voice: join failed before ready: guild ${guildId} channel ${channelId} timeout=${connectReadyTimeoutMs}ms error=${formatErrorMessage(err)}`,
215+);
202216connection.destroy();
203217return { ok: false, message: `Failed to join voice channel: ${formatErrorMessage(err)}` };
204218}
@@ -289,11 +303,26 @@ export class DiscordVoiceManager {
289303290304disconnectedHandler = async () => {
291305try {
306+logVoiceVerbose(
307+`disconnected: attempting recovery guild ${guildId} channel ${channelId} grace=${reconnectGraceMs}ms`,
308+);
292309await Promise.race([
293-voiceSdk.entersState(connection, voiceSdk.VoiceConnectionStatus.Signalling, 5_000),
294-voiceSdk.entersState(connection, voiceSdk.VoiceConnectionStatus.Connecting, 5_000),
310+voiceSdk.entersState(
311+connection,
312+voiceSdk.VoiceConnectionStatus.Signalling,
313+reconnectGraceMs,
314+),
315+voiceSdk.entersState(
316+connection,
317+voiceSdk.VoiceConnectionStatus.Connecting,
318+reconnectGraceMs,
319+),
295320]);
296-} catch {
321+logVoiceVerbose(`disconnected: recovery started guild ${guildId} channel ${channelId}`);
322+} catch (err) {
323+logger.warn(
324+`discord voice: disconnect recovery failed: guild ${guildId} channel ${channelId} timeout=${reconnectGraceMs}ms error=${formatErrorMessage(err)}; destroying connection`,
325+);
297326clearSessionIfCurrent();
298327connection.destroy();
299328}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。