fix: Fallback to a video-only stream if getUserMedia fails when requesting audio.

This commit is contained in:
wj-xiao
2026-02-04 15:49:53 +08:00
parent 5d32386f2c
commit dc710a4b1d
2 changed files with 12 additions and 2 deletions

View File

@@ -40,7 +40,12 @@ class Camera {
this.width = width;
this.height = height;
if (audioId) this.audioId = audioId;
this.stream = await navigator.mediaDevices.getUserMedia({ video, audio });
try {
this.stream = await navigator.mediaDevices.getUserMedia({ video, audio });
} catch {
this.stream = await navigator.mediaDevices.getUserMedia({ video, audio: false });
}
}
public async updateResolution(width: number, height: number) {

View File

@@ -40,7 +40,12 @@ class Camera {
this.width = width
this.height = height
if (audioId) this.audioId = audioId
this.stream = await navigator.mediaDevices.getUserMedia({ video, audio })
try {
this.stream = await navigator.mediaDevices.getUserMedia({ video, audio })
} catch {
this.stream = await navigator.mediaDevices.getUserMedia({ video, audio: false })
}
}
public async updateResolution(width: number, height: number): Promise<void> {