From ab04e1571894147c30067743c040d4515367c12e Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 16 Sep 2024 17:21:08 +0200 Subject: [PATCH] console: Add fallback deviceId when videoTracks getSetting fails --- pkg/webui/components/qr/input/video/index.js | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/webui/components/qr/input/video/index.js b/pkg/webui/components/qr/input/video/index.js index 56799be456..b12c3c3c2c 100644 --- a/pkg/webui/components/qr/input/video/index.js +++ b/pkg/webui/components/qr/input/video/index.js @@ -76,14 +76,20 @@ const Camera = props => { } }, [cameras]) - const setDeviceIdFromStream = useCallback(userStream => { - const videoTracks = userStream.getVideoTracks() - - if (videoTracks.length > 0) { - const { deviceId } = videoTracks[0].getSettings() - setDeviceId(deviceId) - } - }, []) + const setDeviceIdFromStream = useCallback( + userStream => { + const videoTracks = userStream.getVideoTracks() + if (videoTracks.length > 0) { + const { deviceId } = videoTracks[0].getSettings() + if (deviceId) { + setDeviceId(deviceId) + } else if (cameras.length > 0) { + setDeviceId(cameras[0].deviceId) + } + } + }, + [cameras], + ) useEffect(() => { setHasFrontCamera(cameras.some(device => device.label.toLowerCase().includes('front')))