Selaa lähdekoodia

Added ability to switch audio output device

efficient_tiling
Kostiantyn Tsaregradskyi 9 vuotta sitten
vanhempi
commit
d34adb67dd
4 muutettua tiedostoa jossa 32 lisäystä ja 43 poistoa
  1. 5
    31
      conference.js
  2. 1
    0
      lang/main.json
  3. 9
    8
      modules/UI/side_pannels/settings/SettingsMenu.js
  4. 17
    4
      modules/settings/Settings.js

+ 5
- 31
conference.js Näytä tiedosto

@@ -1106,37 +1106,11 @@ export default {
1106 1106
         APP.UI.addListener(
1107 1107
             UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
1108 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));
1109
+                APP.settings.setAudioOutputDeviceId(audioOutputDeviceId)
1110
+                    .then(() => console.log('changed output device'))
1111
+                    .catch((err) => {
1112
+                        console.error('failed to set audio output device', err);
1113
+                    });
1140 1114
             }
1141 1115
         );
1142 1116
 

+ 1
- 0
lang/main.json Näytä tiedosto

@@ -89,6 +89,7 @@
89 89
         "startVideoMuted": "Start without video",
90 90
         "selectCamera": "Select camera",
91 91
         "selectMic": "Select microphone",
92
+        "selectAudioOutput": "Select audio output",
92 93
         "followMe": "Enable follow me"
93 94
     },
94 95
     "videothumbnail":

+ 9
- 8
modules/UI/side_pannels/settings/SettingsMenu.js Näytä tiedosto

@@ -1,4 +1,4 @@
1
-/* global APP, $ */
1
+/* global APP, $, JitsiMeetJS */
2 2
 import UIUtil from "../../util/UIUtil";
3 3
 import UIEvents from "../../../../service/UI/UIEvents";
4 4
 import languages from "../../../../service/translation/languages";
@@ -202,7 +202,8 @@ export default {
202 202
 
203 203
         let $selectCamera= $('#selectCamera'),
204 204
             $selectMic = $('#selectMic'),
205
-            $selectAudioOutput = $('#selectAudioOutput');
205
+            $selectAudioOutput = $('#selectAudioOutput'),
206
+            $selectAudioOutputParent = $selectAudioOutput.parent();
206 207
 
207 208
         let audio = devices.filter(device => device.kind === 'audioinput');
208 209
         let video = devices.filter(device => device.kind === 'videoinput');
@@ -216,15 +217,15 @@ export default {
216 217
             generateDevicesOptions(audio, Settings.getMicDeviceId())
217 218
         );
218 219
 
219
-        if (audioOutput.length) {
220
+        if (audioOutput.length &&
221
+            JitsiMeetJS.isAudioOutputDeviceChangeAvailable()) {
220 222
             $selectAudioOutput.html(
221 223
                 generateDevicesOptions(audioOutput,
222
-                    Settings.getAudioOutputDeviceId())
223
-            ).show();
224
+                    Settings.getAudioOutputDeviceId()));
225
+
226
+            $selectAudioOutputParent.show();
224 227
         } 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
+            $selectAudioOutputParent.hide();
228 229
         }
229 230
 
230 231
         $devicesOptions.show();

+ 17
- 4
modules/settings/Settings.js Näytä tiedosto

@@ -1,3 +1,5 @@
1
+/* global JitsiMeetJS */
2
+
1 3
 import UIUtil from '../UI/util/UIUtil';
2 4
 
3 5
 let email = '';
@@ -5,7 +7,6 @@ let displayName = '';
5 7
 let language = null;
6 8
 let cameraDeviceId = '';
7 9
 let micDeviceId = '';
8
-let audioOutputDeviceId = '';
9 10
 let welcomePageDisabled = false;
10 11
 
11 12
 function supportsLocalStorage() {
@@ -39,6 +40,17 @@ if (supportsLocalStorage()) {
39 40
     welcomePageDisabled = JSON.parse(
40 41
         window.localStorage.welcomePageDisabled || false
41 42
     );
43
+
44
+    var audioOutputDeviceId = window.localStorage.audioOutputDeviceId;
45
+
46
+    if (typeof audioOutputDeviceId !== 'undefined' &&
47
+        audioOutputDeviceId !== JitsiMeetJS.getAudioOutputDevice()) {
48
+        JitsiMeetJS.setAudioOutputDevice(
49
+            window.localStorage.audioOutputDeviceId).catch((ex) => {
50
+                console.error('failed to set audio output device from local ' +
51
+                    'storage', ex);
52
+            });
53
+    }
42 54
 } else {
43 55
     console.log("local storage is not supported");
44 56
 }
@@ -130,16 +142,17 @@ export default {
130 142
      * @returns {String}
131 143
      */
132 144
     getAudioOutputDeviceId: function () {
133
-        return audioOutputDeviceId;
145
+        return JitsiMeetJS.getAudioOutputDevice();
134 146
     },
135 147
     /**
136 148
      * Set device id of the audio output device which is currently in use.
137 149
      * Empty string stands for default device.
138 150
      * @param {string} newId new audio output device id
151
+     * @returns {Promise}
139 152
      */
140 153
     setAudioOutputDeviceId: function (newId = '') {
141
-        audioOutputDeviceId = newId;
142
-        window.localStorage.audioOutputDeviceId = newId;
154
+        return JitsiMeetJS.setAudioOutputDevice(newId)
155
+            .then(() => window.localStorage.audioOutputDeviceId = newId);
143 156
     },
144 157
 
145 158
     /**

Loading…
Peruuta
Tallenna