|
|
@@ -468,14 +468,9 @@ function maybeApply(fn, args) {
|
|
468
|
468
|
fn && fn(...args);
|
|
469
|
469
|
}
|
|
470
|
470
|
|
|
471
|
|
-const getUserMediaStatus = {
|
|
472
|
|
- initialized: false,
|
|
473
|
|
- callbacks: []
|
|
474
|
|
-};
|
|
475
|
|
-
|
|
476
|
471
|
/**
|
|
477
|
|
- * Wrap `getUserMedia` to allow others to know if it was executed at least
|
|
478
|
|
- * once or not. Wrapper function uses `getUserMediaStatus` object.
|
|
|
472
|
+ * Wrap `getUserMedia` in order to convert between callback and Promise based
|
|
|
473
|
+ * APIs.
|
|
479
|
474
|
* @param {Function} getUserMedia native function
|
|
480
|
475
|
* @returns {Function} wrapped function
|
|
481
|
476
|
*/
|
|
|
@@ -487,12 +482,6 @@ function wrapGetUserMedia(getUserMedia, usePromises = false) {
|
|
487
|
482
|
return getUserMedia(constraints)
|
|
488
|
483
|
.then(stream => {
|
|
489
|
484
|
maybeApply(successCallback, [ stream ]);
|
|
490
|
|
- if (!getUserMediaStatus.initialized) {
|
|
491
|
|
- getUserMediaStatus.initialized = true;
|
|
492
|
|
- getUserMediaStatus.callbacks.forEach(
|
|
493
|
|
- callback => callback());
|
|
494
|
|
- getUserMediaStatus.callbacks.length = 0;
|
|
495
|
|
- }
|
|
496
|
485
|
|
|
497
|
486
|
return stream;
|
|
498
|
487
|
})
|
|
|
@@ -506,12 +495,6 @@ function wrapGetUserMedia(getUserMedia, usePromises = false) {
|
|
506
|
495
|
gUM = function(constraints, successCallback, errorCallback) {
|
|
507
|
496
|
getUserMedia(constraints, stream => {
|
|
508
|
497
|
maybeApply(successCallback, [ stream ]);
|
|
509
|
|
- if (!getUserMediaStatus.initialized) {
|
|
510
|
|
- getUserMediaStatus.initialized = true;
|
|
511
|
|
- getUserMediaStatus.callbacks.forEach(
|
|
512
|
|
- callback => callback());
|
|
513
|
|
- getUserMediaStatus.callbacks.length = 0;
|
|
514
|
|
- }
|
|
515
|
498
|
}, error => {
|
|
516
|
499
|
maybeApply(errorCallback, [ error ]);
|
|
517
|
500
|
});
|
|
|
@@ -521,36 +504,6 @@ function wrapGetUserMedia(getUserMedia, usePromises = false) {
|
|
521
|
504
|
return gUM;
|
|
522
|
505
|
}
|
|
523
|
506
|
|
|
524
|
|
-/**
|
|
525
|
|
- * Execute function after getUserMedia was executed at least once.
|
|
526
|
|
- * @param {Function} callback function to execute after getUserMedia
|
|
527
|
|
- */
|
|
528
|
|
-function afterUserMediaInitialized(callback) {
|
|
529
|
|
- if (getUserMediaStatus.initialized) {
|
|
530
|
|
- callback();
|
|
531
|
|
- } else {
|
|
532
|
|
- getUserMediaStatus.callbacks.push(callback);
|
|
533
|
|
- }
|
|
534
|
|
-}
|
|
535
|
|
-
|
|
536
|
|
-/**
|
|
537
|
|
- * Wrapper function which makes enumerateDevices to wait
|
|
538
|
|
- * until someone executes getUserMedia first time.
|
|
539
|
|
- * @param {Function} enumerateDevices native function
|
|
540
|
|
- * @returns {Funtion} wrapped function
|
|
541
|
|
- */
|
|
542
|
|
-function wrapEnumerateDevices(enumerateDevices) {
|
|
543
|
|
- return function(callback) {
|
|
544
|
|
- // enumerate devices only after initial getUserMedia
|
|
545
|
|
- afterUserMediaInitialized(() => {
|
|
546
|
|
- enumerateDevices().then(callback, err => {
|
|
547
|
|
- logger.error('cannot enumerate devices: ', err);
|
|
548
|
|
- callback([]);
|
|
549
|
|
- });
|
|
550
|
|
- });
|
|
551
|
|
- };
|
|
552
|
|
-}
|
|
553
|
|
-
|
|
554
|
507
|
/**
|
|
555
|
508
|
* Use old MediaStreamTrack to get devices list and
|
|
556
|
509
|
* convert it to enumerateDevices format.
|
|
|
@@ -760,6 +713,9 @@ class RTCUtils extends Listenable {
|
|
760
|
713
|
logger.info(`Disable HPF: ${disableHPF}`);
|
|
761
|
714
|
}
|
|
762
|
715
|
|
|
|
716
|
+ // Initialize rawEnumerateDevicesWithCallback
|
|
|
717
|
+ initRawEnumerateDevicesWithCallback();
|
|
|
718
|
+
|
|
763
|
719
|
return new Promise((resolve, reject) => {
|
|
764
|
720
|
if (RTCBrowserType.isFirefox()) {
|
|
765
|
721
|
const FFversion = RTCBrowserType.getFirefoxVersion();
|
|
|
@@ -776,10 +732,7 @@ class RTCUtils extends Listenable {
|
|
776
|
732
|
this.getUserMedia
|
|
777
|
733
|
= wrapGetUserMedia(
|
|
778
|
734
|
navigator.mozGetUserMedia.bind(navigator));
|
|
779
|
|
- this.enumerateDevices
|
|
780
|
|
- = wrapEnumerateDevices(
|
|
781
|
|
- navigator.mediaDevices.enumerateDevices.bind(
|
|
782
|
|
- navigator.mediaDevices));
|
|
|
735
|
+ this.enumerateDevices = rawEnumerateDevicesWithCallback;
|
|
783
|
736
|
this.pcConstraints = {};
|
|
784
|
737
|
this.attachMediaStream
|
|
785
|
738
|
= wrapAttachMediaStream((element, stream) => {
|
|
|
@@ -833,17 +786,9 @@ class RTCUtils extends Listenable {
|
|
833
|
786
|
const getUserMedia
|
|
834
|
787
|
= navigator.webkitGetUserMedia.bind(navigator);
|
|
835
|
788
|
|
|
836
|
|
- if (navigator.mediaDevices) {
|
|
837
|
|
- this.getUserMedia = wrapGetUserMedia(getUserMedia);
|
|
838
|
|
- this.enumerateDevices
|
|
839
|
|
- = wrapEnumerateDevices(
|
|
840
|
|
- navigator.mediaDevices.enumerateDevices.bind(
|
|
841
|
|
- navigator.mediaDevices));
|
|
842
|
|
- } else {
|
|
843
|
|
- this.getUserMedia = getUserMedia;
|
|
844
|
|
- this.enumerateDevices
|
|
845
|
|
- = enumerateDevicesThroughMediaStreamTrack;
|
|
846
|
|
- }
|
|
|
789
|
+ this.getUserMedia = wrapGetUserMedia(getUserMedia);
|
|
|
790
|
+ this.enumerateDevices = rawEnumerateDevicesWithCallback;
|
|
|
791
|
+
|
|
847
|
792
|
this.attachMediaStream
|
|
848
|
793
|
= wrapAttachMediaStream((element, stream) => {
|
|
849
|
794
|
defaultSetVideoSrc(element, stream);
|
|
|
@@ -910,10 +855,7 @@ class RTCUtils extends Listenable {
|
|
910
|
855
|
navigator.mediaDevices.getUserMedia.bind(
|
|
911
|
856
|
navigator.mediaDevices),
|
|
912
|
857
|
true);
|
|
913
|
|
- this.enumerateDevices
|
|
914
|
|
- = wrapEnumerateDevices(
|
|
915
|
|
- navigator.mediaDevices.enumerateDevices.bind(
|
|
916
|
|
- navigator.mediaDevices));
|
|
|
858
|
+ this.enumerateDevices = rawEnumerateDevicesWithCallback;
|
|
917
|
859
|
this.attachMediaStream
|
|
918
|
860
|
= wrapAttachMediaStream((element, stream) => {
|
|
919
|
861
|
defaultSetVideoSrc(element, stream);
|
|
|
@@ -1511,9 +1453,6 @@ function onReady(options, GUM) {
|
|
1511
|
1453
|
eventEmitter.emit(RTCEvents.RTC_READY, true);
|
|
1512
|
1454
|
screenObtainer.init(options, GUM);
|
|
1513
|
1455
|
|
|
1514
|
|
- // Initialize rawEnumerateDevicesWithCallback
|
|
1515
|
|
- initRawEnumerateDevicesWithCallback();
|
|
1516
|
|
-
|
|
1517
|
1456
|
if (rtcUtils.isDeviceListAvailable() && rawEnumerateDevicesWithCallback) {
|
|
1518
|
1457
|
rawEnumerateDevicesWithCallback(ds => {
|
|
1519
|
1458
|
currentlyAvailableMediaDevices = ds.splice(0);
|