Przeglądaj źródła

feat(BrowserCapabilities): introduce isChromiumBased

This function helps simplify the code when handling browsers that are pretty
much Chrome in disguise.
dev1
Saúl Ibarra Corretgé 7 lat temu
rodzic
commit
f9f379b62f

+ 4
- 15
modules/RTC/RTCUtils.js Wyświetl plik

@@ -814,10 +814,7 @@ class RTCUtils extends Listenable {
814 814
 
815 815
             this.getStreamID = ({ id }) => id;
816 816
             this.getTrackID = ({ id }) => id;
817
-        } else if (browser.isChrome() // this is chrome < 61
818
-                || browser.isOpera()
819
-                || browser.isNWJS()
820
-                || browser.isElectron()
817
+        } else if (browser.isChromiumBased() // this is chrome < 61
821 818
                 || browser.isReactNative()) {
822 819
 
823 820
             this.RTCPeerConnectionType = RTCPeerConnection;
@@ -946,11 +943,7 @@ class RTCUtils extends Listenable {
946 943
     _initPCConstraints(options) {
947 944
         if (browser.isFirefox()) {
948 945
             this.pcConstraints = {};
949
-        } else if (browser.isChrome()
950
-            || browser.isOpera()
951
-            || browser.isNWJS()
952
-            || browser.isElectron()
953
-            || browser.isReactNative()) {
946
+        } else if (browser.isChromiumBased() || browser.isReactNative()) {
954 947
             this.pcConstraints = { optional: [
955 948
                 { googHighStartBitrate: 0 },
956 949
                 { googPayloadPadding: true },
@@ -1457,12 +1450,8 @@ class RTCUtils extends Listenable {
1457 1450
     isDeviceChangeAvailable(deviceType) {
1458 1451
         return deviceType === 'output' || deviceType === 'audiooutput'
1459 1452
             ? isAudioOutputDeviceChangeAvailable
1460
-            : browser.isChrome()
1461
-                || browser.isFirefox()
1462
-                || browser.isOpera()
1463
-                || browser.isNWJS()
1464
-                || browser.isElectron()
1465
-                || browser.isEdge();
1453
+            : browser.isChromiumBased()
1454
+                || browser.isFirefox() || browser.isEdge();
1466 1455
     }
1467 1456
 
1468 1457
     /**

+ 1
- 2
modules/RTC/TraceablePeerConnection.js Wyświetl plik

@@ -581,8 +581,7 @@ TraceablePeerConnection.prototype._remoteStreamAdded = function(stream) {
581 581
     }
582 582
 
583 583
     // Bind 'addtrack'/'removetrack' event handlers
584
-    if (browser.isChrome() || browser.isNWJS()
585
-        || browser.isElectron() || browser.isEdge()) {
584
+    if (browser.isChromiumBased() || browser.isEdge()) {
586 585
         stream.onaddtrack = event => {
587 586
             this._remoteTrackAdded(stream, event.track);
588 587
         };

+ 25
- 17
modules/browser/BrowserCapabilities.js Wyświetl plik

@@ -47,6 +47,25 @@ export default class BrowserCapabilities extends BrowserDetection {
47 47
         return !this.isEdge() && !this.isFirefox();
48 48
     }
49 49
 
50
+    /**
51
+     * Checks if the current browser is Chromium based, that is, it's either
52
+     * Chrome / Chromium or uses it as its engine, but doesn't identify as
53
+     * Chrome.
54
+     *
55
+     * This includes the following browsers:
56
+     * - Chrome and Chromium
57
+     * - Other browsers which use the Chrome engine, but are detected as Chrome,
58
+     *   such as Brave and Vivaldi
59
+     * - Browsers which are NOT Chrome but use it as their engine, and have
60
+     *   custom detection code: Opera, Electron and NW.JS
61
+     */
62
+    isChromiumBased() {
63
+        return this.isChrome()
64
+            || this.isElectron()
65
+            || this.isNWJS()
66
+            || this.isOpera();
67
+    }
68
+
50 69
     /**
51 70
      * Checks if current browser is a Safari and a version of Safari that
52 71
      * supports native webrtc.
@@ -64,12 +83,9 @@ export default class BrowserCapabilities extends BrowserDetection {
64 83
      * @returns {boolean} true if the browser is supported, false otherwise.
65 84
      */
66 85
     isSupported() {
67
-        return this.isChrome()
86
+        return this.isChromiumBased()
68 87
             || this.isEdge()
69
-            || this.isElectron()
70 88
             || this.isFirefox()
71
-            || this.isNWJS()
72
-            || this.isOpera()
73 89
             || this.isReactNative()
74 90
             || this.isSafariWithWebrtc();
75 91
     }
@@ -81,7 +97,7 @@ export default class BrowserCapabilities extends BrowserDetection {
81 97
      * otherwise.
82 98
      */
83 99
     supportsVideoMuteOnConnInterrupted() {
84
-        return this.isChrome() || this.isElectron() || this.isReactNative();
100
+        return this.isChromiumBased() || this.isReactNative();
85 101
     }
86 102
 
87 103
     /**
@@ -132,12 +148,9 @@ export default class BrowserCapabilities extends BrowserDetection {
132 148
      * @returns {boolean} true if they are supported, false otherwise.
133 149
      */
134 150
     supportsRtpStatistics() {
135
-        return this.isChrome()
151
+        return this.isChromiumBased()
136 152
             || this.isEdge()
137
-            || this.isElectron()
138 153
             || this.isFirefox()
139
-            || this.isNWJS()
140
-            || this.isOpera()
141 154
             || this.isReactNative()
142 155
             || this.isSafariWithWebrtc();
143 156
     }
@@ -147,9 +160,7 @@ export default class BrowserCapabilities extends BrowserDetection {
147 160
      * candidates through the legacy getStats() API.
148 161
      */
149 162
     supportsLocalCandidateRttStatistics() {
150
-        return this.isChrome()
151
-            || this.isElectron()
152
-            || this.isReactNative();
163
+        return this.isChromiumBased() || this.isReactNative();
153 164
     }
154 165
 
155 166
     /**
@@ -192,11 +203,8 @@ export default class BrowserCapabilities extends BrowserDetection {
192 203
      * @returns {boolean}
193 204
      */
194 205
     supportsSimulcast() {
195
-        return this.isChrome()
196
-            || this.isFirefox()
197
-            || this.isElectron()
198
-            || this.isNWJS()
199
-            || this.isReactNative();
206
+        return this.isChromiumBased()
207
+            || this.isFirefox() || this.isReactNative();
200 208
     }
201 209
 
202 210
     /**

Ładowanie…
Anuluj
Zapisz