瀏覽代碼

Very raw version of ability to switch audio output device

master
Kostiantyn Tsaregradskyi 9 年之前
父節點
當前提交
2bd600aeaf
共有 5 個檔案被更改,包括 91 行新增4 行删除
  1. 37
    0
      conference.js
  2. 4
    0
      index.html
  3. 30
    4
      modules/UI/side_pannels/settings/SettingsMenu.js
  4. 19
    0
      modules/settings/Settings.js
  5. 1
    0
      service/UI/UIEvents.js

+ 37
- 0
conference.js 查看文件

1103
             }
1103
             }
1104
         );
1104
         );
1105
 
1105
 
1106
+        APP.UI.addListener(
1107
+            UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
1108
+            (audioOutputDeviceId) => {
1109
+                APP.settings.setAudioOutputDeviceId(audioOutputDeviceId);
1110
+
1111
+                let promises = [],
1112
+                    track;
1113
+
1114
+                for (let key in room.rtc.remoteTracks) {
1115
+                    track = room.rtc.remoteTracks[key].video;
1116
+
1117
+                    if (track && track.containers.length) {
1118
+                        promises.push(
1119
+                            track.changeAudioOutput(audioOutputDeviceId));
1120
+                    }
1121
+
1122
+                    track = room.rtc.remoteTracks[key].audio;
1123
+
1124
+                    if (track && track.containers.length) {
1125
+                        promises.push(
1126
+                            track.changeAudioOutput(audioOutputDeviceId));
1127
+                    }
1128
+                }
1129
+
1130
+                room.rtc.localTracks.forEach((track) => {
1131
+                    if (track.containers.length) {
1132
+                        promises.push(
1133
+                            track.changeAudioOutput(audioOutputDeviceId));
1134
+                    }
1135
+                });
1136
+
1137
+                Promise.all(promises).then(
1138
+                    () => console.log('audio devices switched'),
1139
+                    (err) => console.error(err));
1140
+            }
1141
+        );
1142
+
1106
         APP.UI.addListener(
1143
         APP.UI.addListener(
1107
             UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
1144
             UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
1108
         );
1145
         );

+ 4
- 0
index.html 查看文件

258
                     <span data-i18n="settings.selectMic"></span>
258
                     <span data-i18n="settings.selectMic"></span>
259
                     <select id="selectMic"></select>
259
                     <select id="selectMic"></select>
260
                 </label>
260
                 </label>
261
+                <label className="devicesOptionsLabel">
262
+                    <span data-i18n="settings.selectAudioOutput"></span>
263
+                    <select id="selectAudioOutput"></select>
264
+                </label>
261
             </div>
265
             </div>
262
             <div id="followMeOptions">
266
             <div id="followMeOptions">
263
                 <label class = "followMeLabel">
267
                 <label class = "followMeLabel">

+ 30
- 4
modules/UI/side_pannels/settings/SettingsMenu.js 查看文件

124
                 emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
124
                 emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
125
             }
125
             }
126
         });
126
         });
127
+        $('#selectAudioOutput').change(function () {
128
+            let audioOutputDeviceId = $(this).val();
129
+            if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
130
+                emitter.emit(UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
131
+                    audioOutputDeviceId);
132
+            }
133
+        });
127
     },
134
     },
128
 
135
 
129
     /**
136
     /**
186
      * @param {{ deviceId, label, kind }[]} devices list of available devices
193
      * @param {{ deviceId, label, kind }[]} devices list of available devices
187
      */
194
      */
188
     changeDevicesList (devices) {
195
     changeDevicesList (devices) {
196
+        let $devicesOptions =  $('#devicesOptions');
197
+
189
         if (!devices.length) {
198
         if (!devices.length) {
190
-            $('#devicesOptions').hide();
199
+            $devicesOptions.hide();
191
             return;
200
             return;
192
         }
201
         }
193
 
202
 
203
+        let $selectCamera= $('#selectCamera'),
204
+            $selectMic = $('#selectMic'),
205
+            $selectAudioOutput = $('#selectAudioOutput');
206
+
194
         let audio = devices.filter(device => device.kind === 'audioinput');
207
         let audio = devices.filter(device => device.kind === 'audioinput');
195
         let video = devices.filter(device => device.kind === 'videoinput');
208
         let video = devices.filter(device => device.kind === 'videoinput');
209
+        let audioOutput = devices
210
+            .filter(device => device.kind === 'audiooutput');
196
 
211
 
197
-        $('#selectCamera').html(
212
+        $selectCamera.html(
198
             generateDevicesOptions(video, Settings.getCameraDeviceId())
213
             generateDevicesOptions(video, Settings.getCameraDeviceId())
199
         );
214
         );
200
-        $('#selectMic').html(
215
+        $selectMic.html(
201
             generateDevicesOptions(audio, Settings.getMicDeviceId())
216
             generateDevicesOptions(audio, Settings.getMicDeviceId())
202
         );
217
         );
203
 
218
 
204
-        $('#devicesOptions').show();
219
+        if (audioOutput.length) {
220
+            $selectAudioOutput.html(
221
+                generateDevicesOptions(audioOutput,
222
+                    Settings.getAudioOutputDeviceId())
223
+            ).show();
224
+        } else {
225
+            // if we have no audiooutput devices, that means current browser
226
+            // doesn't support it, so don't show the select box at all
227
+            $selectAudioOutput.hide();
228
+        }
229
+
230
+        $devicesOptions.show();
205
     }
231
     }
206
 };
232
 };

+ 19
- 0
modules/settings/Settings.js 查看文件

5
 let language = null;
5
 let language = null;
6
 let cameraDeviceId = '';
6
 let cameraDeviceId = '';
7
 let micDeviceId = '';
7
 let micDeviceId = '';
8
+let audioOutputDeviceId = '';
8
 let welcomePageDisabled = false;
9
 let welcomePageDisabled = false;
9
 
10
 
10
 function supportsLocalStorage() {
11
 function supportsLocalStorage() {
123
         window.localStorage.micDeviceId = newId;
124
         window.localStorage.micDeviceId = newId;
124
     },
125
     },
125
 
126
 
127
+    /**
128
+     * Get device id of the audio output device which is currently in use.
129
+     * Empty string stands for default device.
130
+     * @returns {String}
131
+     */
132
+    getAudioOutputDeviceId: function () {
133
+        return audioOutputDeviceId;
134
+    },
135
+    /**
136
+     * Set device id of the audio output device which is currently in use.
137
+     * Empty string stands for default device.
138
+     * @param {string} newId new audio output device id
139
+     */
140
+    setAudioOutputDeviceId: function (newId = '') {
141
+        audioOutputDeviceId = newId;
142
+        window.localStorage.audioOutputDeviceId = newId;
143
+    },
144
+
126
     /**
145
     /**
127
      * Check if welcome page is enabled or not.
146
      * Check if welcome page is enabled or not.
128
      * @returns {boolean}
147
      * @returns {boolean}

+ 1
- 0
service/UI/UIEvents.js 查看文件

67
     SUBJECT_CHANGED: "UI.subject_changed",
67
     SUBJECT_CHANGED: "UI.subject_changed",
68
     VIDEO_DEVICE_CHANGED: "UI.video_device_changed",
68
     VIDEO_DEVICE_CHANGED: "UI.video_device_changed",
69
     AUDIO_DEVICE_CHANGED: "UI.audio_device_changed",
69
     AUDIO_DEVICE_CHANGED: "UI.audio_device_changed",
70
+    AUDIO_OUTPUT_DEVICE_CHANGED: "UI.audio_output_device_changed",
70
     /**
71
     /**
71
      * Notifies interested listeners that the follow-me feature is enabled or
72
      * Notifies interested listeners that the follow-me feature is enabled or
72
      * disabled.
73
      * disabled.

Loading…
取消
儲存