|
|
@@ -99,6 +99,13 @@ const isAudioOutputDeviceChangeAvailable
|
|
99
|
99
|
let availableDevices;
|
|
100
|
100
|
let availableDevicesPollTimer;
|
|
101
|
101
|
|
|
|
102
|
+/**
|
|
|
103
|
+ * An empty function.
|
|
|
104
|
+ */
|
|
|
105
|
+function emptyFuncton() {
|
|
|
106
|
+ // no-op
|
|
|
107
|
+}
|
|
|
108
|
+
|
|
102
|
109
|
/**
|
|
103
|
110
|
* Initialize wrapper function for enumerating devices.
|
|
104
|
111
|
* TODO: remove this, it should no longer be needed.
|
|
|
@@ -109,7 +116,13 @@ function initEnumerateDevicesWithCallback() {
|
|
109
|
116
|
if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
|
|
110
|
117
|
return callback => {
|
|
111
|
118
|
navigator.mediaDevices.enumerateDevices()
|
|
112
|
|
- .then(callback, () => callback([]));
|
|
|
119
|
+ .then(devices => {
|
|
|
120
|
+ updateKnownDevices(devices);
|
|
|
121
|
+ callback(devices);
|
|
|
122
|
+ }, () => {
|
|
|
123
|
+ updateKnownDevices([]);
|
|
|
124
|
+ callback([]);
|
|
|
125
|
+ });
|
|
113
|
126
|
};
|
|
114
|
127
|
}
|
|
115
|
128
|
}
|
|
|
@@ -621,6 +634,23 @@ function sendDeviceListToAnalytics(deviceList) {
|
|
621
|
634
|
});
|
|
622
|
635
|
}
|
|
623
|
636
|
|
|
|
637
|
+
|
|
|
638
|
+/**
|
|
|
639
|
+ * Update known devices.
|
|
|
640
|
+ *
|
|
|
641
|
+ * @param {Array<Object>} pds - The new devices.
|
|
|
642
|
+ * @returns {void}
|
|
|
643
|
+ *
|
|
|
644
|
+ * NOTE: Use this function as a shared callback to handle both the devicechange event and the polling implementations.
|
|
|
645
|
+ * This prevents duplication and works around a chrome bug (verified to occur on 68) where devicechange fires twice in
|
|
|
646
|
+ * a row, which can cause async post devicechange processing to collide.
|
|
|
647
|
+ */
|
|
|
648
|
+function updateKnownDevices(pds) {
|
|
|
649
|
+ if (compareAvailableMediaDevices(pds)) {
|
|
|
650
|
+ onMediaDevicesListChanged(pds);
|
|
|
651
|
+ }
|
|
|
652
|
+}
|
|
|
653
|
+
|
|
624
|
654
|
/**
|
|
625
|
655
|
* Event handler for the 'devicechange' event.
|
|
626
|
656
|
*
|
|
|
@@ -895,27 +925,15 @@ class RTCUtils extends Listenable {
|
|
895
|
925
|
RTCEvents.DEVICE_LIST_AVAILABLE,
|
|
896
|
926
|
availableDevices);
|
|
897
|
927
|
|
|
898
|
|
-
|
|
899
|
|
- // Use a shared callback to handle both the devicechange event
|
|
900
|
|
- // and the polling implementations. This prevents duplication
|
|
901
|
|
- // and works around a chrome bug (verified to occur on 68) where
|
|
902
|
|
- // devicechange fires twice in a row, which can cause async post
|
|
903
|
|
- // devicechange processing to collide.
|
|
904
|
|
- const updateKnownDevices = () => this.enumerateDevices(pds => {
|
|
905
|
|
- if (compareAvailableMediaDevices(pds)) {
|
|
906
|
|
- onMediaDevicesListChanged(pds);
|
|
907
|
|
- }
|
|
908
|
|
- });
|
|
909
|
|
-
|
|
910
|
928
|
if (browser.supportsDeviceChangeEvent()) {
|
|
911
|
929
|
navigator.mediaDevices.addEventListener(
|
|
912
|
930
|
'devicechange',
|
|
913
|
|
- updateKnownDevices);
|
|
|
931
|
+ () => this.enumerateDevices(emptyFuncton));
|
|
914
|
932
|
} else {
|
|
915
|
933
|
// Periodically poll enumerateDevices() method to check if
|
|
916
|
934
|
// list of media devices has changed.
|
|
917
|
935
|
availableDevicesPollTimer = window.setInterval(
|
|
918
|
|
- updateKnownDevices,
|
|
|
936
|
+ () => this.enumerateDevices(emptyFuncton),
|
|
919
|
937
|
AVAILABLE_DEVICES_POLL_INTERVAL_TIME);
|
|
920
|
938
|
}
|
|
921
|
939
|
});
|