fix: derive voice sidebar from LiveKit participants to eliminate desync
The channel sidebar voice user list was maintained by a separate voiceUsers Map (fed by WS events + fragile hydration code) that diverged from reality after server restarts — users shown in wrong channels, duplicated across channels. The VoiceGrid was always correct because it reads LiveKit participants directly. Now VoiceChannel.tsx derives its user list from LiveKit participants for the connected channel (single source of truth) and only falls back to server-provided voiceUsers for channels the user is not connected to. Removed all hydration band-aids that tried to sync the two systems: - useLiveKit ParticipantDisconnected → removeVoiceUser - useLiveKit ConnectionStateChanged → addVoiceUser hydration loop - useWebSocket ready handler → dynamic import LiveKit hydration Also includes: voice channel settings gear icon on hover, persist per-user volume/mute prefs across sessions, default screen share audio off on Electron (no system audio capture support).
This commit is contained in:
@@ -122,7 +122,7 @@ export function setCameraSubscription(room: Room | null, targetIdentity: string,
|
||||
});
|
||||
}
|
||||
|
||||
function parseIdentity(identity: string): { userId: string; username: string } {
|
||||
export function parseIdentity(identity: string): { userId: string; username: string } {
|
||||
const parts = identity.split(':');
|
||||
return { userId: parts[0] ?? identity, username: parts[1] ?? identity };
|
||||
}
|
||||
@@ -414,14 +414,9 @@ export function useLiveKit() {
|
||||
});
|
||||
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);
|
||||
}
|
||||
// Clean up stale WS-based voice status for the departed participant
|
||||
const { userId } = parseIdentity(participant.identity);
|
||||
useVoiceStore.getState().clearVoiceUserStatus(userId);
|
||||
});
|
||||
newRoom.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
|
||||
// LiveKit auto-attaches a hidden <audio> element for subscribed audio tracks.
|
||||
|
||||
Reference in New Issue
Block a user