Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed none camera or microphone at browser #20

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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