From d36c8777fe9287efc192d8e0a54c1f63dd287e25 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Mon, 3 Aug 2026 09:21:10 +0700 Subject: [PATCH] =?UTF-8?q?fix(voice):=20delay=20voice=20restore=20after?= =?UTF-8?q?=20screen=20share=20=E2=80=94=20avoid=20session=20teardown=20ra?= =?UTF-8?q?ce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Immediate reconnect after Streamer.stop() races Discord's voice session teardown → AbortError. Wait 4s so the old session is fully released before re-joining with @discordjs/voice. --- .../voice-recording/screenShareController.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/services/discord-gateway/src/modules/voice-recording/screenShareController.ts b/services/discord-gateway/src/modules/voice-recording/screenShareController.ts index a4be7a6..42f3764 100644 --- a/services/discord-gateway/src/modules/voice-recording/screenShareController.ts +++ b/services/discord-gateway/src/modules/voice-recording/screenShareController.ts @@ -127,12 +127,17 @@ export class ScreenShareController { /* already gone */ } if (this.restoreVoice) { - Promise.resolve(this.restoreVoice(status)).catch((err) => { - this.logger.warn( - { error: err instanceof Error ? err.message : String(err) }, - "Failed to restore voice connection after screen share", - ); - }); + // Wait for Discord to fully release the Streamer's voice session + // before re-joining with @discordjs/voice — an immediate join races + // the session teardown and times out with AbortError. + setTimeout(() => { + Promise.resolve(this.restoreVoice(status)).catch((err) => { + this.logger.warn( + { error: err instanceof Error ? err.message : String(err) }, + "Failed to restore voice connection after screen share", + ); + }); + }, 4000); } }; const done = playStream(output, this.streamer, {