fix: add invite button, voice join dedup, voice panel immediate render

This commit is contained in:
2026-06-29 15:28:05 -04:00
parent a8a09cf7b4
commit 2d3bf48e66
3 changed files with 52 additions and 12 deletions
+22 -4
View File
@@ -35,6 +35,7 @@ interface VoiceState {
participants: VoiceParticipant[];
error: string | null;
_room: Room | null;
isJoining: boolean;
joinVoice: (channelId: string, channelName: string) => Promise<void>;
leaveVoice: () => Promise<void>;
toggleMute: () => void;
@@ -64,8 +65,15 @@ export const useVoiceStore = create<VoiceState>((set, get) => ({
participants: [],
error: null,
_room: null,
isJoining: false,
joinVoice: async (channelId, channelName) => {
if (get().isJoining) {
console.log("[voice] already joining, ignoring duplicate click");
return;
}
set({ isJoining: true });
console.log("[voice] joinVoice called:", channelId);
const existing = get()._room;
if (existing) {
await get().leaveVoice();
@@ -74,9 +82,11 @@ export const useVoiceStore = create<VoiceState>((set, get) => ({
set({ error: null });
try {
console.log("[voice] requesting token for:", channelId);
const resp = await api.post<VoiceTokenResponse>('/voice/token', {
room_name: channelId,
});
console.log("[voice] got token response:", resp);
const room = new Room({
adaptiveStream: true,
@@ -153,16 +163,24 @@ export const useVoiceStore = create<VoiceState>((set, get) => ({
await room.connect(resp.livekit_url, resp.token);
// Mute mic by default on join
await room.localParticipant.setMicrophoneEnabled(false);
set({ isMuted: true });
// Set state immediately so the UI renders the voice panel
set({
_room: room,
currentRoom: channelId,
currentRoomName: channelName,
error: null,
});
// Mute mic by default on join (best effort; don't fail join if this errors)
try {
await room.localParticipant.setMicrophoneEnabled(false);
set({ isMuted: true });
} catch (micErr) {
console.warn("[voice] failed to set initial mute state:", micErr);
}
set({ isJoining: false });
// Notify WebSocket peers
const wsSend = useWebSocketStore.getState().send;
wsSend({