Request microphone permissions when unmuting

This commit is contained in:
mplorentz
2026-03-10 12:13:05 -04:00
parent 64617f585b
commit fc4e1281d9
+17 -4
View File
@@ -168,13 +168,15 @@ export const joinVoiceRoom = async (
throw e throw e
} }
let muted = false
try { try {
await room.localParticipant.setMicrophoneEnabled(true) await room.localParticipant.setMicrophoneEnabled(true)
} catch (e) { } catch (e) {
muted = true
pushToast({theme: "error", message: "Could not access microphone"}) pushToast({theme: "error", message: "Could not access microphone"})
} }
currentVoiceSession.set({url, h, room, muted: false}) currentVoiceSession.set({url, h, room, muted})
startPresenceHeartbeat(url, h) startPresenceHeartbeat(url, h)
} }
@@ -190,11 +192,22 @@ export const leaveVoiceRoom = async () => {
currentVoiceSession.set(undefined) currentVoiceSession.set(undefined)
} }
export const toggleMute = () => { export const toggleMute = async () => {
const session = get(currentVoiceSession) const session = get(currentVoiceSession)
if (!session) return if (!session) return
const muted = !session.muted const muted = !session.muted
session.room.localParticipant.setMicrophoneEnabled(!muted) if (muted) {
currentVoiceSession.set({...session, 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"})
}
} }