瀏覽代碼

fix(conference) avoid double prompts in Firefox after choosing non-default device.

* fix(conference) avoid double prompts in Firefox after choosing non-default device

* addressed linting errors
master
Nils Ohlmeier 3 年之前
父節點
當前提交
84f37b1777
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 45 行新增8 行删除
  1. 6
    1
      conference.js
  2. 39
    7
      modules/devices/mediaDeviceHelper.js

+ 6
- 1
conference.js 查看文件

@@ -2642,12 +2642,17 @@ export default {
2642 2642
 
2643 2643
         APP.store.dispatch(updateDeviceList(devices));
2644 2644
 
2645
+        // Firefox users can choose their preferred device in the gUM prompt. In that case
2646
+        // we should respect that and not attempt to switch to the preferred device from
2647
+        // our settings.
2648
+        const newLabelsOnly = mediaDeviceHelper.newDeviceListAddedLabelsOnly(oldDevices, devices);
2645 2649
         const newDevices
2646 2650
             = mediaDeviceHelper.getNewMediaDevicesAfterDeviceListChanged(
2647 2651
                 devices,
2648 2652
                 this.isSharingScreen,
2649 2653
                 localVideo,
2650
-                localAudio);
2654
+                localAudio,
2655
+                newLabelsOnly);
2651 2656
         const promises = [];
2652 2657
         const audioWasMuted = this.isLocalAudioMuted();
2653 2658
         const videoWasMuted = this.isLocalVideoMuted();

+ 39
- 7
modules/devices/mediaDeviceHelper.js 查看文件

@@ -51,10 +51,11 @@ function getNewAudioOutputDevice(newDevices) {
51 51
  * list of available devices has been changed.
52 52
  * @param {MediaDeviceInfo[]} newDevices
53 53
  * @param {JitsiLocalTrack} localAudio
54
+ * @param {boolean} newLabel
54 55
  * @returns {string|undefined} - ID of new microphone device to use, undefined
55 56
  *      if audio input device should not be changed.
56 57
  */
57
-function getNewAudioInputDevice(newDevices, localAudio) {
58
+function getNewAudioInputDevice(newDevices, localAudio, newLabel) {
58 59
     const availableAudioInputDevices = newDevices.filter(
59 60
         d => d.kind === 'audioinput');
60 61
     const selectedAudioInputDeviceId = getUserSelectedMicDeviceId(APP.store.getState());
@@ -75,7 +76,8 @@ function getNewAudioInputDevice(newDevices, localAudio) {
75 76
             return availableAudioInputDevices[0].deviceId;
76 77
         }
77 78
     } else if (selectedAudioInputDevice
78
-        && selectedAudioInputDeviceId !== localAudio.getDeviceId()) {
79
+        && selectedAudioInputDeviceId !== localAudio.getDeviceId()
80
+        && !newLabel) {
79 81
 
80 82
         // And here we handle case when we already have some device working,
81 83
         // but we plug-in a "preferred" (previously selected in settings, stored
@@ -89,10 +91,11 @@ function getNewAudioInputDevice(newDevices, localAudio) {
89 91
  * list of available devices has been changed.
90 92
  * @param {MediaDeviceInfo[]} newDevices
91 93
  * @param {JitsiLocalTrack} localVideo
94
+ * @param {boolean} newLabel
92 95
  * @returns {string|undefined} - ID of new camera device to use, undefined
93 96
  *      if video input device should not be changed.
94 97
  */
95
-function getNewVideoInputDevice(newDevices, localVideo) {
98
+function getNewVideoInputDevice(newDevices, localVideo, newLabel) {
96 99
     const availableVideoInputDevices = newDevices.filter(
97 100
         d => d.kind === 'videoinput');
98 101
     const selectedVideoInputDeviceId = getUserSelectedCameraDeviceId(APP.store.getState());
@@ -113,7 +116,8 @@ function getNewVideoInputDevice(newDevices, localVideo) {
113 116
             return availableVideoInputDevices[0].deviceId;
114 117
         }
115 118
     } else if (selectedVideoInputDevice
116
-            && selectedVideoInputDeviceId !== localVideo.getDeviceId()) {
119
+            && selectedVideoInputDeviceId !== localVideo.getDeviceId()
120
+            && !newLabel) {
117 121
         // And here we handle case when we already have some device working,
118 122
         // but we plug-in a "preferred" (previously selected in settings, stored
119 123
         // in local storage) device.
@@ -139,14 +143,42 @@ export default {
139 143
             newDevices,
140 144
             isSharingScreen,
141 145
             localVideo,
142
-            localAudio) {
146
+            localAudio,
147
+            newLabels) {
143 148
         return {
144
-            audioinput: getNewAudioInputDevice(newDevices, localAudio),
145
-            videoinput: isSharingScreen ? undefined : getNewVideoInputDevice(newDevices, localVideo),
149
+            audioinput: getNewAudioInputDevice(newDevices, localAudio, newLabels),
150
+            videoinput: isSharingScreen ? undefined : getNewVideoInputDevice(newDevices, localVideo, newLabels),
146 151
             audiooutput: getNewAudioOutputDevice(newDevices)
147 152
         };
148 153
     },
149 154
 
155
+    /**
156
+     * Checks if the only difference between an object of known devices compared
157
+     * to an array of new devices are only the labels for the devices.
158
+     * @param {Object} oldDevices
159
+     * @param {MediaDeviceInfo[]} newDevices
160
+     * @returns {boolean}
161
+     */
162
+    newDeviceListAddedLabelsOnly(oldDevices, newDevices) {
163
+        const oldDevicesFlattend = oldDevices.audioInput.concat(oldDevices.audioOutput).concat(oldDevices.videoInput);
164
+
165
+        if (oldDevicesFlattend.length !== newDevices.length) {
166
+            return false;
167
+        }
168
+        oldDevicesFlattend.forEach(oldDevice => {
169
+            if (oldDevice.label !== '') {
170
+                return false;
171
+            }
172
+            const newDevice = newDevices.find(nd => nd.deviceId === oldDevice.deviceId);
173
+
174
+            if (!newDevice || newDevice.label === '') {
175
+                return false;
176
+            }
177
+        });
178
+
179
+        return true;
180
+    },
181
+
150 182
     /**
151 183
      * Tries to create new local tracks for new devices obtained after device
152 184
      * list changed. Shows error dialog in case of failures.

Loading…
取消
儲存