8000 fix(useDevicesList): Check for device availability before requesting … · vueuse/vueuse@c424f98 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c424f98

Browse files
authored
fix(useDevicesList): Check for device availability before requesting permissions (#4818)
1 parent c6469d5 commit c424f98

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/core/useDevicesList/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export function useDevicesList(options: UseDevicesListOptions = {}): UseDevicesL
8686
if (state.value !== 'granted') {
8787
let granted = true
8888
try {
89+
const allDevices = await navigator!.mediaDevices.enumerateDevices()
90+
const hasCamera = allDevices.some(device => device.kind === 'videoinput')
91+
const hasMicrophone = allDevices.some(device => device.kind === 'audioinput' || device.kind === 'audiooutput')
92+
constraints.video = hasCamera ? constraints.video : false
93+
constraints.audio = hasMicrophone ? constraints.audio : false
8994
stream = await navigator!.mediaDevices.getUserMedia(constraints)
9095
}
9196
catch {

0 commit comments

Comments
 (0)
0