From f32bf9eeec8ded63bfb6290f058023aa23f955f1 Mon Sep 17 00:00:00 2001 From: Khushal Agarwal Date: Wed, 27 Sep 2023 14:14:50 +0530 Subject: [PATCH] fix(client): getDevices getUserMedia to be called only for firefox --- packages/client/src/devices/devices.ts | 33 ++++++++++++-------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/client/src/devices/devices.ts b/packages/client/src/devices/devices.ts index 573c78f24a..b75754e3d6 100644 --- a/packages/client/src/devices/devices.ts +++ b/packages/client/src/devices/devices.ts @@ -15,34 +15,31 @@ import { isFirefox } from '../helpers/browsers'; const getDevices = (constraints?: MediaStreamConstraints) => { return new Observable((subscriber) => { - // in Firefox, devices can be enumerated after userMedia is requested - // and permissions granted. Otherwise, device labels are empty - if (isFirefox()) { - navigator.mediaDevices - .getUserMedia(constraints) - .then((media) => { - navigator.mediaDevices.enumerateDevices().then((devices) => { - subscriber.next(devices); - // If we stop the tracks before enumerateDevices -> the labels won't show up in Firefox - disposeOfMediaStream(media); - subscriber.complete(); - }); - }) - .catch((error) => { - getLogger(['devices'])('error', 'Failed to get devices', error); - subscriber.error(error); - }); - } else { + const enumerateDevices = (media?: MediaStream) => { navigator.mediaDevices .enumerateDevices() .then((devices) => { subscriber.next(devices); + if (isFirefox() && media) { + // If we stop the tracks before enumerateDevices -> the labels won't show up in Firefox + disposeOfMediaStream(media); + } subscriber.complete(); }) .catch((error) => { getLogger(['devices'])('error', 'Failed to get devices', error); subscriber.error(error); }); + }; + + // in Firefox, devices can be enumerated after userMedia is requested + // and permissions granted. Otherwise, device labels are empty + if (isFirefox()) { + navigator.mediaDevices.getUserMedia(constraints).then((media) => { + enumerateDevices(media); + }); + } else { + enumerateDevices(); } }); };