Request microphone permissions when unmuting

This commit is contained in:
mplorentz
2026-03-10 12:13:05 -04:00
committed by hodlbod
parent 697804c621
commit 25228f785d
+17 -4
View File
@@ -168,13 +168,15 @@ export const joinVoiceRoom = async (
throw e
}
let muted = false
try {
await room.localParticipant.setMicrophoneEnabled(true)
} catch (e) {
muted = true
pushToast({theme: "error", message: "Could not access microphone"})
}
currentVoiceSession.set({url, h, room, muted: false})
currentVoiceSession.set({url, h, room, muted})
startPresenceHeartbeat(url, h)
}
@@ -190,11 +192,22 @@ export const leaveVoiceRoom = async () => {
currentVoiceSession.set(undefined)
}
export const toggleMute = () => {
export const toggleMute = async () => {
const session = get(currentVoiceSession)
if (!session) return
const muted = !session.muted
session.room.localParticipant.setMicrophoneEnabled(!muted)
currentVoiceSession.set({...session, muted})
if (muted) {
// Disable and re-enable microphone to trigger permission prompt
session.room.localParticipant.setMicrophoneEnabled(false)
currentVoiceSession.set({...session, muted})
return
}
try {
await session.room.localParticipant.setMicrophoneEnabled(true)
currentVoiceSession.set({...session, muted})
} catch (e) {
pushToast({theme: "error", message: "Could not access microphone"})
}
}