From e809adff3ec531a48c88ead4cb77bd634da4ef89 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Mon, 16 Mar 2026 20:41:36 +0100 Subject: [PATCH] fix: sync channel sidebar voice users with LiveKit participant disconnects The sidebar used voiceStore.voiceUsers (WebSocket-driven, 5s delay) while voice panels used LiveKit's real-time participants. Now ParticipantDisconnected also removes the user from voiceUsers for immediate sidebar updates. --- packages/web/src/hooks/useLiveKit.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/web/src/hooks/useLiveKit.ts b/packages/web/src/hooks/useLiveKit.ts index 05ee5117..26b36aa0 100644 --- a/packages/web/src/hooks/useLiveKit.ts +++ b/packages/web/src/hooks/useLiveKit.ts @@ -412,7 +412,17 @@ export function useLiveKit() { ).catch(() => { }); } }); - newRoom.on(RoomEvent.ParticipantDisconnected, guardedUpdate); + newRoom.on(RoomEvent.ParticipantDisconnected, (participant: RemoteParticipant) => { + guardedUpdate(); + // Sync voiceUsers so channel sidebar updates immediately + // (don't wait for server's 5s grace-period WS event) + const chId = connectedChannelRef.current; + if (chId && !chId.startsWith('dm-')) { + const { userId } = parseIdentity(participant.identity); + useVoiceStore.getState().removeVoiceUser(chId, userId); + useVoiceStore.getState().clearVoiceUserStatus(userId); + } + }); newRoom.on(RoomEvent.TrackSubscribed, (track, publication, participant) => { // LiveKit auto-attaches a hidden