Skip to content

Commit

Permalink
fix(useDevicesList): show devices for Firefox (#2798)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixzapata committed Mar 28, 2023
1 parent d6d35a0 commit 0823d68
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/useDevicesList/index.ts
Expand Up @@ -58,13 +58,18 @@ export function useDevicesList(options: UseDevicesListOptions = {}): UseDevicesL
const audioOutputs = computed(() => devices.value.filter(i => i.kind === 'audiooutput'))
const isSupported = useSupported(() => navigator && navigator.mediaDevices && navigator.mediaDevices.enumerateDevices)
const permissionGranted = ref(false)
let stream: MediaStream | null

async function update() {
if (!isSupported.value)
return

devices.value = await navigator!.mediaDevices.enumerateDevices()
onUpdated?.(devices.value)
if (stream) {
stream.getTracks().forEach(t => t.stop())
stream = null
}
}

async function ensurePermissions() {
Expand All @@ -77,8 +82,7 @@ export function useDevicesList(options: UseDevicesListOptions = {}): UseDevicesL
const { state, query } = usePermission('camera', { controls: true })
await query()
if (state.value !== 'granted') {
const stream = await navigator!.mediaDevices.getUserMedia(constraints)
stream.getTracks().forEach(t => t.stop())
stream = await navigator!.mediaDevices.getUserMedia(constraints)
update()
permissionGranted.value = true
}
Expand Down

0 comments on commit 0823d68

Please sign in to comment.