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