diff --git a/src/livekit/useLiveKit.ts b/src/livekit/useLiveKit.ts index bf12669c..cc9aefaf 100644 --- a/src/livekit/useLiveKit.ts +++ b/src/livekit/useLiveKit.ts @@ -137,20 +137,32 @@ export function useLiveKit( // and setting tracks to be enabled during this time causes errors. if (room !== undefined && connectionState === ConnectionState.Connected) { const participant = room.localParticipant; - if (participant.isMicrophoneEnabled !== muteStates.audio.enabled) { - participant - .setMicrophoneEnabled(muteStates.audio.enabled) - .catch((e) => - logger.error("Failed to sync audio mute state with LiveKit", e) - ); - } - if (participant.isCameraEnabled !== muteStates.video.enabled) { - participant - .setCameraEnabled(muteStates.video.enabled) - .catch((e) => - logger.error("Failed to sync video mute state with LiveKit", e) - ); - } + + const syncMuteStateAudio = () => { + if (participant.isCameraEnabled !== muteStates.video.enabled) { + participant + .setCameraEnabled(muteStates.video.enabled) + .catch((e) => + logger.error("Failed to sync video mute state with LiveKit", e) + ) + // Run the check recursively. Because the user can update the state (presses mute button) + // while the device is enabling itself we need to check after we are done if its still in sync. + .then(() => syncMuteStateAudio()); + } + }; + const syncMuteStateVideo = () => { + if (participant.isMicrophoneEnabled !== muteStates.audio.enabled) { + participant + .setMicrophoneEnabled(muteStates.audio.enabled) + .catch((e) => + logger.error("Failed to sync audio mute state with LiveKit", e) + ) + // see above + .then(() => syncMuteStateVideo()); + } + }; + syncMuteStateAudio(); + syncMuteStateVideo(); } }, [room, muteStates, connectionState]); diff --git a/src/rtcSessionHelpers.ts b/src/rtcSessionHelpers.ts index 3cad5627..68baca6e 100644 --- a/src/rtcSessionHelpers.ts +++ b/src/rtcSessionHelpers.ts @@ -41,7 +41,7 @@ export function enterRTCSession(rtcSession: MatrixRTCSession) { // have started tracking by the time calls start getting created. //groupCallOTelMembership?.onJoinCall(); - // right now we asume everything is a room-scoped call + // right now we assume everything is a room-scoped call const livekitAlias = rtcSession.room.roomId; rtcSession.joinRoomSession([makeFocus(livekitAlias)]);