Parcourir la source

Very raw version of ability to switch audio output device

master
Kostiantyn Tsaregradskyi il y a 9 ans
Parent
révision
ae4e7222b8
2 fichiers modifiés avec 33 ajouts et 1 suppressions
  1. 30
    0
      modules/RTC/JitsiTrack.js
  2. 3
    1
      modules/RTC/RTCUtils.js

+ 30
- 0
modules/RTC/JitsiTrack.js Voir le fichier

190
     return container;
190
     return container;
191
 };
191
 };
192
 
192
 
193
+JitsiTrack.prototype.changeAudioOutput = function (audioOutputDeviceId) {
194
+    return Promise.all(this.containers.map(function(element) {
195
+        if (typeof element.setSinkId !== 'undefined') {
196
+            try {
197
+                return element.setSinkId(audioOutputDeviceId)
198
+                    .then(function () {
199
+                        console.log('Audio output device changed on element ' + element);
200
+                    })
201
+                    .catch(function (error) {
202
+                        var errorMessage = error;
203
+
204
+                        if (error.name === 'SecurityError') {
205
+                            errorMessage = 'You need to use HTTPS for selecting audio output device: ' + error;
206
+                        }
207
+
208
+                        console.error('Failed to change audio output device on element ' + element + ': ' + errorMessage);
209
+
210
+                        return Promise.resolve();
211
+                    });
212
+            } catch(ex) {
213
+                console.error(ex);
214
+                return Promise.resolve();
215
+            }
216
+        } else {
217
+            console.warn('Browser does not support output device selection.');
218
+            return Promise.resolve();
219
+        }
220
+    }));
221
+};
222
+
193
 /**
223
 /**
194
  * Removes the track from the passed HTML container.
224
  * Removes the track from the passed HTML container.
195
  * @param container the HTML container. If <tt>null</tt> all containers are removed.
225
  * @param container the HTML container. If <tt>null</tt> all containers are removed.

+ 3
- 1
modules/RTC/RTCUtils.js Voir le fichier

330
             return {
330
             return {
331
                 facing: source.facing || null,
331
                 facing: source.facing || null,
332
                 label: source.label,
332
                 label: source.label,
333
-                kind: kind ? kind + 'input': null,
333
+                // theoretically deprecated MediaStreamTrack.getSources should not return 'audiooutput' devices but
334
+                // let's handle it in any case
335
+                kind: kind ? (kind === 'audiooutput' ? kind : kind + 'input') : null,
334
                 deviceId: source.id,
336
                 deviceId: source.id,
335
                 groupId: source.groupId || null
337
                 groupId: source.groupId || null
336
             };
338
             };

Chargement…
Annuler
Enregistrer