fix(voice): delay voice restore after screen share — avoid session teardown race

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.
This commit is contained in:
asepharyana
2026-08-03 09:21:10 +07:00
parent 9fd4ded9c8
commit d36c8777fe
@@ -127,12 +127,17 @@ export class ScreenShareController {
/* already gone */ /* already gone */
} }
if (this.restoreVoice) { if (this.restoreVoice) {
// 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) => { Promise.resolve(this.restoreVoice(status)).catch((err) => {
this.logger.warn( this.logger.warn(
{ error: err instanceof Error ? err.message : String(err) }, { error: err instanceof Error ? err.message : String(err) },
"Failed to restore voice connection after screen share", "Failed to restore voice connection after screen share",
); );
}); });
}, 4000);
} }
}; };
const done = playStream(output, this.streamer, { const done = playStream(output, this.streamer, {