Request microphone permissions when unmuting
This commit is contained in:
+17
-4
@@ -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"})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user