Enumerating devices after video preview gUM

This commit is contained in:
Pedro Beschorner Marin 2020-05-08 13:43:29 -03:00
parent ef48ea2e8c
commit 362317e8d0
2 changed files with 22 additions and 9 deletions

View File

@ -234,6 +234,8 @@ class VideoPreview extends Component {
const webcams = [];
let initialDeviceId;
VideoService.updateNumberOfDevices(devices);
if (!this._isMounted) return;
// set webcam

View File

@ -70,16 +70,26 @@ class VideoService {
});
}
updateNumberOfDevices() {
navigator.mediaDevices.enumerateDevices().then((devices) => {
const deviceIds = [];
devices.forEach((d) => {
if (d.kind === 'videoinput' && !deviceIds.includes(d.deviceId)) {
deviceIds.push(d.deviceId);
}
});
this.numberOfDevices = deviceIds.length;
fetchNumberOfDevices(devices) {
const deviceIds = [];
devices.forEach(d => {
const validDeviceId = d.deviceId !== '' && !deviceIds.includes(d.deviceId)
if (d.kind === 'videoinput' && validDeviceId) {
deviceIds.push(d.deviceId);
}
});
return deviceIds.length;
}
updateNumberOfDevices(devices = null) {
if (devices) {
this.numberOfDevices = this.fetchNumberOfDevices(devices);
} else {
navigator.mediaDevices.enumerateDevices().then(devices => {
this.numberOfDevices = this.fetchNumberOfDevices(devices);
});
}
}
joinVideo(deviceId) {
@ -426,4 +436,5 @@ export default {
monitor: conn => videoService.monitor(conn),
onBeforeUnload: () => videoService.onBeforeUnload(),
notify: message => notify(message, 'error', 'video'),
updateNumberOfDevices: devices => videoService.updateNumberOfDevices(devices),
};