diff --git a/services/discord-gateway/src/modules/command-handler/media.handler.ts b/services/discord-gateway/src/modules/command-handler/media.handler.ts index d1249a2..b16ceab 100644 --- a/services/discord-gateway/src/modules/command-handler/media.handler.ts +++ b/services/discord-gateway/src/modules/command-handler/media.handler.ts @@ -186,19 +186,18 @@ export class MediaHandler { this.getVoiceStatus, // releaseVoice — disconnect the @discordjs/voice connection so the // dank074 Streamer can take over (Discord: one voice session/user). - async () => { + async (status) => { const vc = this.voiceControllerAccessor?.(); - const guildId = vc?.getStatus().activeGuildId ?? null; + const guildId = status.activeGuildId ?? null; if (vc && guildId) { await vc.disconnectGuild(guildId); } }, // restoreVoice — reconnect the @discordjs audio connection after // the stream ends so mic/listen keep working. - async () => { + async (status) => { const vc = this.voiceControllerAccessor?.(); - const status = vc?.getStatus(); - if (vc && status?.activeGuildId && status.activeChannelId) { + if (vc && status.activeGuildId && status.activeChannelId) { await vc.connect(status.activeGuildId, status.activeChannelId); } }, diff --git a/services/discord-gateway/src/modules/voice-recording/screenShareController.ts b/services/discord-gateway/src/modules/voice-recording/screenShareController.ts index d8eab1b..a4be7a6 100644 --- a/services/discord-gateway/src/modules/voice-recording/screenShareController.ts +++ b/services/discord-gateway/src/modules/voice-recording/screenShareController.ts @@ -41,9 +41,13 @@ export class ScreenShareController { /** Disconnect the @discordjs/voice connection so the Streamer can take * over the voice channel (Discord allows only ONE voice session per user * — two connections collide and the Streamer never gets VOICE_SERVER_UPDATE). */ - private readonly releaseVoice: () => void | Promise, + private readonly releaseVoice: ( + status: ScreenShareVoiceStatus, + ) => void | Promise, /** Reconnect the @discordjs/voice connection after the stream ends. */ - private readonly restoreVoice: () => void | Promise, + private readonly restoreVoice: ( + status: ScreenShareVoiceStatus, + ) => void | Promise, ) {} isActive(): boolean { @@ -79,7 +83,7 @@ export class ScreenShareController { // Free the @discordjs/voice connection BEFORE the Streamer joins, so // the user has only one voice session (Discord requirement). - await this.releaseVoice(); + await this.releaseVoice(status); await Promise.race([ this.streamer.joinVoiceChannel(channel), @@ -123,7 +127,7 @@ export class ScreenShareController { /* already gone */ } if (this.restoreVoice) { - Promise.resolve(this.restoreVoice()).catch((err) => { + 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",