Skip to content

Commit

Permalink
fix(client): getDevices getUserMedia to be called only for firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 committed Sep 27, 2023
1 parent 7e5a6aa commit f32bf9e
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions packages/client/src/devices/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,31 @@ import { isFirefox } from '../helpers/browsers';

const getDevices = (constraints?: MediaStreamConstraints) => {
return new Observable<MediaDeviceInfo[]>((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();
}
});
};
Expand Down

0 comments on commit f32bf9e

Please sign in to comment.