fix: re-send voice_join on WS reconnect to restore sidebar after server restart

This commit is contained in:
Jannis Braun
2026-03-05 00:35:26 +01:00
parent 09b9d1d55a
commit 39372980f7
+9 -6
View File
@@ -162,17 +162,20 @@ function handleEvent(origin: string, event: ServerEvent): void {
} }
} }
// Re-register in voice channel — DEFERRED to useLiveKit after LiveKit connects. // Re-register in voice channel after WS reconnect — the server lost
// Just keep currentVoiceChannelId set so AppLayout triggers LiveKit connection. // voice state on restart, so we must tell it we're still connected.
// The voice_join WS message will be sent by useLiveKit on connect/reconnect. // GUARD: Only re-register if LiveKit is actually connected. Background
// tabs can reconnect WS but not LiveKit — sending voice_join without
// an active media plane would create ghost users in the sidebar.
{ {
const { currentVoiceChannelId } = useVoiceStore.getState(); const { currentVoiceChannelId, isLiveKitConnected, isMuted, isDeafened, isCameraOn, isScreenSharing } = useVoiceStore.getState();
if (currentVoiceChannelId) { if (currentVoiceChannelId && isLiveKitConnected) {
const voiceOrigin = getChannelOrigin(currentVoiceChannelId); const voiceOrigin = getChannelOrigin(currentVoiceChannelId);
if (voiceOrigin === origin) { if (voiceOrigin === origin) {
// Optimistic: show self in sidebar immediately (local only)
const myId = isHome ? event.user.id : useAuthStore.getState().user?.id; const myId = isHome ? event.user.id : useAuthStore.getState().user?.id;
if (myId) addVoiceUser(currentVoiceChannelId, myId); if (myId) addVoiceUser(currentVoiceChannelId, myId);
wsSend({ type: 'voice_join', channelId: currentVoiceChannelId }, origin);
wsSend({ type: 'voice_status', isMuted, isDeafened, isCameraOn, isScreenSharing }, origin);
} }
} }
} }