|
|
@@ -1,5 +1,4 @@
|
|
1
|
1
|
import { getLogger } from '@jitsi/logger';
|
|
2
|
|
-import EventEmitter from 'events';
|
|
3
|
2
|
import clonedeep from 'lodash.clonedeep';
|
|
4
|
3
|
import 'webrtc-adapter';
|
|
5
|
4
|
|
|
|
@@ -18,8 +17,6 @@ import screenObtainer from './ScreenObtainer';
|
|
18
|
17
|
|
|
19
|
18
|
const logger = getLogger(__filename);
|
|
20
|
19
|
|
|
21
|
|
-const eventEmitter = new EventEmitter();
|
|
22
|
|
-
|
|
23
|
20
|
const AVAILABLE_DEVICES_POLL_INTERVAL_TIME = 3000; // ms
|
|
24
|
21
|
|
|
25
|
22
|
/**
|
|
|
@@ -157,29 +154,6 @@ function getConstraints(um = [], options = {}) {
|
|
157
|
154
|
return constraints;
|
|
158
|
155
|
}
|
|
159
|
156
|
|
|
160
|
|
-/**
|
|
161
|
|
- * Updates the granted permissions based on the options we requested and the
|
|
162
|
|
- * streams we received.
|
|
163
|
|
- * @param um the options we requested to getUserMedia.
|
|
164
|
|
- * @param stream the stream we received from calling getUserMedia.
|
|
165
|
|
- */
|
|
166
|
|
-function updateGrantedPermissions(um, stream) {
|
|
167
|
|
- const audioTracksReceived
|
|
168
|
|
- = Boolean(stream) && stream.getAudioTracks().length > 0;
|
|
169
|
|
- const videoTracksReceived
|
|
170
|
|
- = Boolean(stream) && stream.getVideoTracks().length > 0;
|
|
171
|
|
- const grantedPermissions = {};
|
|
172
|
|
-
|
|
173
|
|
- if (um.indexOf('video') !== -1) {
|
|
174
|
|
- grantedPermissions.video = videoTracksReceived;
|
|
175
|
|
- }
|
|
176
|
|
- if (um.indexOf('audio') !== -1) {
|
|
177
|
|
- grantedPermissions.audio = audioTracksReceived;
|
|
178
|
|
- }
|
|
179
|
|
-
|
|
180
|
|
- eventEmitter.emit(RTCEvents.PERMISSIONS_CHANGED, grantedPermissions);
|
|
181
|
|
-}
|
|
182
|
|
-
|
|
183
|
157
|
/**
|
|
184
|
158
|
* Checks if new list of available media devices differs from previous one.
|
|
185
|
159
|
* @param {MediaDeviceInfo[]} newDevices - list of new devices.
|
|
|
@@ -247,52 +221,10 @@ function sendDeviceListToAnalytics(deviceList) {
|
|
247
|
221
|
});
|
|
248
|
222
|
}
|
|
249
|
223
|
|
|
250
|
|
-
|
|
251
|
|
-/**
|
|
252
|
|
- * Update known devices.
|
|
253
|
|
- *
|
|
254
|
|
- * @param {Array<Object>} pds - The new devices.
|
|
255
|
|
- * @returns {void}
|
|
256
|
|
- *
|
|
257
|
|
- * NOTE: Use this function as a shared callback to handle both the devicechange event and the polling implementations.
|
|
258
|
|
- * This prevents duplication and works around a chrome bug (verified to occur on 68) where devicechange fires twice in
|
|
259
|
|
- * a row, which can cause async post devicechange processing to collide.
|
|
260
|
|
- */
|
|
261
|
|
-function updateKnownDevices(pds) {
|
|
262
|
|
- if (compareAvailableMediaDevices(pds)) {
|
|
263
|
|
- onMediaDevicesListChanged(pds);
|
|
264
|
|
- }
|
|
265
|
|
-}
|
|
266
|
|
-
|
|
267
|
|
-/**
|
|
268
|
|
- * Event handler for the 'devicechange' event.
|
|
269
|
|
- *
|
|
270
|
|
- * @param {MediaDeviceInfo[]} devices - list of media devices.
|
|
271
|
|
- * @emits RTCEvents.DEVICE_LIST_CHANGED
|
|
272
|
|
- */
|
|
273
|
|
-function onMediaDevicesListChanged(devicesReceived) {
|
|
274
|
|
- availableDevices = devicesReceived.slice(0);
|
|
275
|
|
- logger.info('list of media devices has changed:', availableDevices);
|
|
276
|
|
-
|
|
277
|
|
- sendDeviceListToAnalytics(availableDevices);
|
|
278
|
|
-
|
|
279
|
|
- // Used by tracks to update the real device id before the consumer of lib-jitsi-meet receives the new device list.
|
|
280
|
|
- eventEmitter.emit(RTCEvents.DEVICE_LIST_WILL_CHANGE, availableDevices);
|
|
281
|
|
-
|
|
282
|
|
- eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, availableDevices);
|
|
283
|
|
-}
|
|
284
|
|
-
|
|
285
|
224
|
/**
|
|
286
|
225
|
*
|
|
287
|
226
|
*/
|
|
288
|
227
|
class RTCUtils extends Listenable {
|
|
289
|
|
- /**
|
|
290
|
|
- *
|
|
291
|
|
- */
|
|
292
|
|
- constructor() {
|
|
293
|
|
- super(eventEmitter);
|
|
294
|
|
- }
|
|
295
|
|
-
|
|
296
|
228
|
/**
|
|
297
|
229
|
* Depending on the browser, sets difference instance methods for
|
|
298
|
230
|
* interacting with user media and adds methods to native WebRTC-related
|
|
|
@@ -347,7 +279,7 @@ class RTCUtils extends Listenable {
|
|
347
|
279
|
logger.debug('Available devices: ', availableDevices);
|
|
348
|
280
|
sendDeviceListToAnalytics(availableDevices);
|
|
349
|
281
|
|
|
350
|
|
- eventEmitter.emit(
|
|
|
282
|
+ this.eventEmitter.emit(
|
|
351
|
283
|
RTCEvents.DEVICE_LIST_AVAILABLE,
|
|
352
|
284
|
availableDevices);
|
|
353
|
285
|
|
|
|
@@ -373,12 +305,12 @@ class RTCUtils extends Listenable {
|
|
373
|
305
|
enumerateDevices(callback) {
|
|
374
|
306
|
navigator.mediaDevices.enumerateDevices()
|
|
375
|
307
|
.then(devices => {
|
|
376
|
|
- updateKnownDevices(devices);
|
|
|
308
|
+ this._updateKnownDevices(devices);
|
|
377
|
309
|
callback(devices);
|
|
378
|
310
|
})
|
|
379
|
311
|
.catch(error => {
|
|
380
|
312
|
logger.warn(`Failed to enumerate devices. ${error}`);
|
|
381
|
|
- updateKnownDevices([]);
|
|
|
313
|
+ this._updateKnownDevices([]);
|
|
382
|
314
|
callback([]);
|
|
383
|
315
|
});
|
|
384
|
316
|
}
|
|
|
@@ -407,7 +339,7 @@ class RTCUtils extends Listenable {
|
|
407
|
339
|
navigator.mediaDevices.getUserMedia(constraints)
|
|
408
|
340
|
.then(stream => {
|
|
409
|
341
|
logger.log('onUserMediaSuccess');
|
|
410
|
|
- updateGrantedPermissions(umDevices, stream);
|
|
|
342
|
+ this._updateGrantedPermissions(umDevices, stream);
|
|
411
|
343
|
if (!timeoutExpired) {
|
|
412
|
344
|
if (typeof gumTimeout !== 'undefined') {
|
|
413
|
345
|
clearTimeout(gumTimeout);
|
|
|
@@ -427,7 +359,7 @@ class RTCUtils extends Listenable {
|
|
427
|
359
|
}
|
|
428
|
360
|
|
|
429
|
361
|
if (jitsiError.name === JitsiTrackErrors.PERMISSION_DENIED) {
|
|
430
|
|
- updateGrantedPermissions(umDevices, undefined);
|
|
|
362
|
+ this._updateGrantedPermissions(umDevices, undefined);
|
|
431
|
363
|
}
|
|
432
|
364
|
|
|
433
|
365
|
// else {
|
|
|
@@ -497,6 +429,65 @@ class RTCUtils extends Listenable {
|
|
497
|
429
|
return missingDevices;
|
|
498
|
430
|
}
|
|
499
|
431
|
|
|
|
432
|
+ /**
|
|
|
433
|
+ * Event handler for the 'devicechange' event.
|
|
|
434
|
+ *
|
|
|
435
|
+ * @param {MediaDeviceInfo[]} devices - list of media devices.
|
|
|
436
|
+ * @emits RTCEvents.DEVICE_LIST_CHANGED
|
|
|
437
|
+ */
|
|
|
438
|
+ _onMediaDevicesListChanged(devicesReceived) {
|
|
|
439
|
+ availableDevices = devicesReceived.slice(0);
|
|
|
440
|
+ logger.info('list of media devices has changed:', availableDevices);
|
|
|
441
|
+
|
|
|
442
|
+ sendDeviceListToAnalytics(availableDevices);
|
|
|
443
|
+
|
|
|
444
|
+ // Used by tracks to update the real device id before the consumer of lib-jitsi-meet receives the
|
|
|
445
|
+ // new device list.
|
|
|
446
|
+ this.eventEmitter.emit(RTCEvents.DEVICE_LIST_WILL_CHANGE, availableDevices);
|
|
|
447
|
+
|
|
|
448
|
+ this.eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, availableDevices);
|
|
|
449
|
+ }
|
|
|
450
|
+
|
|
|
451
|
+ /**
|
|
|
452
|
+ * Update known devices.
|
|
|
453
|
+ *
|
|
|
454
|
+ * @param {Array<Object>} pds - The new devices.
|
|
|
455
|
+ * @returns {void}
|
|
|
456
|
+ *
|
|
|
457
|
+ * NOTE: Use this function as a shared callback to handle both the devicechange event and the
|
|
|
458
|
+ * polling implementations.
|
|
|
459
|
+ * This prevents duplication and works around a chrome bug (verified to occur on 68) where devicechange
|
|
|
460
|
+ * fires twice in a row, which can cause async post devicechange processing to collide.
|
|
|
461
|
+ */
|
|
|
462
|
+ _updateKnownDevices(pds) {
|
|
|
463
|
+ if (compareAvailableMediaDevices(pds)) {
|
|
|
464
|
+ this._onMediaDevicesListChanged(pds);
|
|
|
465
|
+ }
|
|
|
466
|
+ }
|
|
|
467
|
+
|
|
|
468
|
+ /**
|
|
|
469
|
+ * Updates the granted permissions based on the options we requested and the
|
|
|
470
|
+ * streams we received.
|
|
|
471
|
+ * @param um the options we requested to getUserMedia.
|
|
|
472
|
+ * @param stream the stream we received from calling getUserMedia.
|
|
|
473
|
+ */
|
|
|
474
|
+ _updateGrantedPermissions(um, stream) {
|
|
|
475
|
+ const audioTracksReceived
|
|
|
476
|
+ = Boolean(stream) && stream.getAudioTracks().length > 0;
|
|
|
477
|
+ const videoTracksReceived
|
|
|
478
|
+ = Boolean(stream) && stream.getVideoTracks().length > 0;
|
|
|
479
|
+ const grantedPermissions = {};
|
|
|
480
|
+
|
|
|
481
|
+ if (um.indexOf('video') !== -1) {
|
|
|
482
|
+ grantedPermissions.video = videoTracksReceived;
|
|
|
483
|
+ }
|
|
|
484
|
+ if (um.indexOf('audio') !== -1) {
|
|
|
485
|
+ grantedPermissions.audio = audioTracksReceived;
|
|
|
486
|
+ }
|
|
|
487
|
+
|
|
|
488
|
+ this.eventEmitter.emit(RTCEvents.PERMISSIONS_CHANGED, grantedPermissions);
|
|
|
489
|
+ }
|
|
|
490
|
+
|
|
500
|
491
|
/**
|
|
501
|
492
|
* Gets streams from specified device types. This function intentionally
|
|
502
|
493
|
* ignores errors for upstream to catch and handle instead.
|
|
|
@@ -792,7 +783,7 @@ class RTCUtils extends Listenable {
|
|
792
|
783
|
|
|
793
|
784
|
logger.log(`Audio output device set to ${deviceId}`);
|
|
794
|
785
|
|
|
795
|
|
- eventEmitter.emit(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
|
|
|
786
|
+ this.eventEmitter.emit(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
|
|
796
|
787
|
deviceId);
|
|
797
|
788
|
});
|
|
798
|
789
|
}
|