Bläddra i källkod

Very raw version of ability to switch audio output device

master
Kostiantyn Tsaregradskyi 9 år sedan
förälder
incheckning
2bd600aeaf
5 ändrade filer med 91 tillägg och 4 borttagningar
  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 Visa fil

@@ -1103,6 +1103,43 @@ export default {
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 1143
         APP.UI.addListener(
1107 1144
             UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
1108 1145
         );

+ 4
- 0
index.html Visa fil

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

+ 30
- 4
modules/UI/side_pannels/settings/SettingsMenu.js Visa fil

@@ -124,6 +124,13 @@ export default {
124 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,21 +193,40 @@ export default {
186 193
      * @param {{ deviceId, label, kind }[]} devices list of available devices
187 194
      */
188 195
     changeDevicesList (devices) {
196
+        let $devicesOptions =  $('#devicesOptions');
197
+
189 198
         if (!devices.length) {
190
-            $('#devicesOptions').hide();
199
+            $devicesOptions.hide();
191 200
             return;
192 201
         }
193 202
 
203
+        let $selectCamera= $('#selectCamera'),
204
+            $selectMic = $('#selectMic'),
205
+            $selectAudioOutput = $('#selectAudioOutput');
206
+
194 207
         let audio = devices.filter(device => device.kind === 'audioinput');
195 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 213
             generateDevicesOptions(video, Settings.getCameraDeviceId())
199 214
         );
200
-        $('#selectMic').html(
215
+        $selectMic.html(
201 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 Visa fil

@@ -5,6 +5,7 @@ let displayName = '';
5 5
 let language = null;
6 6
 let cameraDeviceId = '';
7 7
 let micDeviceId = '';
8
+let audioOutputDeviceId = '';
8 9
 let welcomePageDisabled = false;
9 10
 
10 11
 function supportsLocalStorage() {
@@ -123,6 +124,24 @@ export default {
123 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 146
      * Check if welcome page is enabled or not.
128 147
      * @returns {boolean}

+ 1
- 0
service/UI/UIEvents.js Visa fil

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

Laddar…
Avbryt
Spara