From 0648e29770b74302a44d5a7148299844af5bf425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Mon, 25 Jun 2018 13:47:57 +0200 Subject: [PATCH] Fix for failure to get webcams in msedge. --- app/lib/RoomClient.js | 58 ++++++++++++++++----------------- app/lib/components/Settings.jsx | 4 +-- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/app/lib/RoomClient.js b/app/lib/RoomClient.js index fb6ed29..d41fdc0 100644 --- a/app/lib/RoomClient.js +++ b/app/lib/RoomClient.js @@ -81,9 +81,9 @@ export default class RoomClient // Map of webcam MediaDeviceInfos indexed by deviceId. // @type {Map} - this._webcams = {}; + this._webcams = new Map(); - this._audioDevices = {}; + this._audioDevices = new Map(); // Local Webcam. Object with: // - {MediaDeviceInfo} [device] @@ -386,7 +386,7 @@ export default class RoomClient return Promise.resolve() .then(() => { - this._audioDevice.device = this._audioDevices[deviceId]; + this._audioDevice.device = this._audioDevices.get(deviceId); logger.debug( 'changeAudioDevice() | new selected webcam [device:%o]', @@ -452,7 +452,7 @@ export default class RoomClient return Promise.resolve() .then(() => { - this._webcam.device = this._webcams[deviceId]; + this._webcam.device = this._webcams.get(deviceId); logger.debug( 'changeWebcam() | new selected webcam [device:%o]', @@ -1640,7 +1640,7 @@ export default class RoomClient logger.debug('_updateAudioDevices()'); // Reset the list. - this._audioDevices = {}; + this._audioDevices = new Map(); return Promise.resolve() .then(() => @@ -1656,28 +1656,27 @@ export default class RoomClient if (device.kind !== 'audioinput') continue; - this._audioDevices[device.deviceId] = { - value : device.deviceId, - label : device.label, - deviceId : device.deviceId - }; + device.value = device.deviceId; + + this._audioDevices.set(device.deviceId, device); } }) .then(() => { + const array = Array.from(this._audioDevices.values()); + const len = array.length; const currentAudioDeviceId = this._audioDevice.device ? this._audioDevice.device.deviceId : undefined; - logger.debug('_updateAudioDevices() [audiodevices:%o]', this._audioDevices); - - const len = Object.keys(this._audioDevices).length; + logger.debug('_updateAudioDevices() [audiodevices:%o]', array); if (len === 0) this._audioDevice.device = null; - else if (!this._audioDevices[currentAudioDeviceId]) - for (this._audioDevice.device in this._audioDevices) - if (this._audioDevices.hasOwnProperty(this._audioDevice.device)) - break; + else if (!this._audioDevices.has(currentAudioDeviceId)) + this._audioDevice.device = array[0]; + + this._dispatch( + stateActions.setCanChangeWebcam(this._webcams.size >= 2)); this._dispatch( stateActions.setCanChangeAudioDevice(len >= 2)); @@ -1692,7 +1691,7 @@ export default class RoomClient logger.debug('_updateWebcams()'); // Reset the list. - this._webcams = {}; + this._webcams = new Map(); return Promise.resolve() .then(() => @@ -1708,28 +1707,27 @@ export default class RoomClient if (device.kind !== 'videoinput') continue; - this._webcams[device.deviceId] = { - value : device.deviceId, - label : device.label, - deviceId : device.deviceId - }; + device.value = device.deviceId; + + this._webcams.set(device.deviceId, device); } }) .then(() => { + const array = Array.from(this._webcams.values()); + const len = array.length; const currentWebcamId = this._webcam.device ? this._webcam.device.deviceId : undefined; - logger.debug('_updateWebcams() [webcams:%o]', this._webcams); - - const len = Object.keys(this._webcams).length; + logger.debug('_updateWebcams() [webcams:%o]', array); if (len === 0) this._webcam.device = null; - else if (!this._webcams[currentWebcamId]) - for (this._webcam.device in this._webcams) - if (this._webcams.hasOwnProperty(this._webcam.device)) - break; + else if (!this._webcams.has(currentWebcamId)) + this._webcam.device = array[0]; + + this._dispatch( + stateActions.setCanChangeWebcam(this._webcams.size >= 2)); this._dispatch( stateActions.setCanChangeWebcam(len >= 2)); diff --git a/app/lib/components/Settings.jsx b/app/lib/components/Settings.jsx index e4bacb0..0f4c3b6 100644 --- a/app/lib/components/Settings.jsx +++ b/app/lib/components/Settings.jsx @@ -32,7 +32,7 @@ class Settings extends React.Component webcamText = 'Unable to select camera'; if (me.webcamDevices) - webcams = Object.values(me.webcamDevices); + webcams = Array.from(me.webcamDevices.values()); else webcams = []; @@ -45,7 +45,7 @@ class Settings extends React.Component audioDevicesText = 'Unable to select audio input device'; if (me.audioDevices) - audioDevices = Object.values(me.audioDevices); + audioDevices = Array.from(me.audioDevices.values()); else audioDevices = [];