From f8dcc4a17721cb54449bb882e82e44fbaaf75c5d Mon Sep 17 00:00:00 2001 From: Yaroslav Poletaev Date: Thu, 21 May 2026 16:17:39 +0300 Subject: [PATCH] Fix error handling in getMobileDevices to reject promises on failure --- src/webrtc-media-provider.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/webrtc-media-provider.js b/src/webrtc-media-provider.js index 869f3f32..2d68eed2 100644 --- a/src/webrtc-media-provider.js +++ b/src/webrtc-media-provider.js @@ -1717,12 +1717,13 @@ const getMobileDevices = async function (kind, deviceConstraints = null) { if (stream.getVideoTracks().length > 0) { deviceId = stream.getVideoTracks()[0].getSettings().deviceId; } - stream.getTracks().forEach((track) => { + stream.getTracks().forEach((track) => { track.stop(); }); } } catch (error) { logger.error(LOG_PREFIX, "Can't get device access with video constraints " + JSON.stringify(constraints.video) + ", error " + error); + throw error; } return deviceId; } @@ -1752,6 +1753,11 @@ const getMobileDevices = async function (kind, deviceConstraints = null) { } } catch (error) { logger.error(LOG_PREFIX, "Can't get device access with constraints " + JSON.stringify(constraints) + ", error " + error); + throw error; + } + + if (!list) { + throw new Error("No media devices found"); } return list; @@ -1894,4 +1900,4 @@ module.exports = { getAudioSourceDevice: getAudioSourceDevice, getCacheInstance: getCacheInstance, getVideoElement: getVideoElement -}; \ No newline at end of file +};