From 5241f9784aeda72095cd189e08f3aa1aec8e3d4b Mon Sep 17 00:00:00 2001 From: asepharyana Date: Sun, 30 Aug 2026 21:51:14 +0700 Subject: [PATCH] feat(gateway): close video burst promptly when a user's SSRC is removed ssrcMap emits "delete" when a VoiceUserData is removed (user stops sharing / leaves voice). Hook it to close the user's open video burst ~500ms later so the ffmpeg mux starts as soon as they stop, instead of waiting up to 5s for the idle sweep. No-op if no burst exists; safe on normal teardown. --- .../src/modules/voice-recording/videoReceiver.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/discord-gateway/src/modules/voice-recording/videoReceiver.ts b/services/discord-gateway/src/modules/voice-recording/videoReceiver.ts index 2f7c0f64..5b46b398 100644 --- a/services/discord-gateway/src/modules/voice-recording/videoReceiver.ts +++ b/services/discord-gateway/src/modules/voice-recording/videoReceiver.ts @@ -336,6 +336,14 @@ export function hookVideoReceiver( // If a user's video SSRC disappears, close their burst after a short grace so // the tail flushes. + receiver.ssrcMap.on("delete", (data) => { + // data = the deleted VoiceUserData (userId + audioSSRC). Close any open + // video burst for that user so the mux starts as soon as they stop sharing. + if (data?.userId) { + setTimeout(() => closeBurst(data.userId), 500); + } + }); + setInterval(() => { const now = Date.now(); for (const [userId, burst] of bursts) {