Skip to content

Commit

Permalink
Merge pull request #20 from xdzqyyds/fix-only-one-device
Browse files Browse the repository at this point in the history
Fixed none camera or microphone at browser
  • Loading branch information
a-wing authored Nov 19, 2024
2 parents b370d12 + 7a9724a commit e233362
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/CLA.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ Example:
- Hongcha Zhang, @hongcha98, 2024/10/24
- Winter Zhang, @WinterJack002, 2024/10/26
- Rocket Aaron, @rocka, 2024/11/06
- xdzqyyds, @xdzqyyds, 2024/11/19
25 changes: 22 additions & 3 deletions webapp/components/device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,18 @@ export default function DeviceBar(props: { streamId: string }) {
const updateDeviceList = async () => {
// to obtain non-empty device label, there needs to be an active media stream or persistent permission
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/label#value
await navigator.mediaDevices.getUserMedia({ audio: true, video: true })

try {
await navigator.mediaDevices.getUserMedia({ audio: true, video: true })
} catch {
try {
await navigator.mediaDevices.getUserMedia({ audio: true })
} catch { /* empty */ }

try {
await navigator.mediaDevices.getUserMedia({ video: true })
} catch { /* empty */ }
}

const devices = (await navigator.mediaDevices.enumerateDevices()).filter(i => !!i.deviceId)

const audios = devices.filter(i => i.kind === 'audioinput').map(toDevice)
Expand Down Expand Up @@ -97,7 +107,16 @@ export default function DeviceBar(props: { streamId: string }) {
// - Android Web Browser
// - Wechat WebView
await permissionsQuery()
} catch { /* empty */ }
} catch {
try {
(await navigator.mediaDevices.getUserMedia({ audio: true })).getTracks().map(track => track.stop())
await permissionsQuery()
} catch { /* empty */ }
try {
(await navigator.mediaDevices.getUserMedia({ video: true })).getTracks().map(track => track.stop())
await permissionsQuery()
} catch { /* empty */ }
}
await updateDeviceList()
}

Expand Down

0 comments on commit e233362

Please sign in to comment.