浏览代码

Very raw version of ability to switch audio output device

master
Kostiantyn Tsaregradskyi 9 年前
父节点
当前提交
ae4e7222b8
共有 2 个文件被更改,包括 33 次插入1 次删除
  1. 30
    0
      modules/RTC/JitsiTrack.js
  2. 3
    1
      modules/RTC/RTCUtils.js

+ 30
- 0
modules/RTC/JitsiTrack.js 查看文件

@@ -190,6 +190,36 @@ JitsiTrack.prototype.attach = function (container) {
190 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 224
  * Removes the track from the passed HTML container.
195 225
  * @param container the HTML container. If <tt>null</tt> all containers are removed.

+ 3
- 1
modules/RTC/RTCUtils.js 查看文件

@@ -330,7 +330,9 @@ function enumerateDevicesThroughMediaStreamTrack (callback) {
330 330
             return {
331 331
                 facing: source.facing || null,
332 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 336
                 deviceId: source.id,
335 337
                 groupId: source.groupId || null
336 338
             };

正在加载...
取消
保存