Browse Source

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 years ago
parent
commit
f9f379b62f

+ 4
- 15
modules/RTC/RTCUtils.js View File

814
 
814
 
815
             this.getStreamID = ({ id }) => id;
815
             this.getStreamID = ({ id }) => id;
816
             this.getTrackID = ({ id }) => id;
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
                 || browser.isReactNative()) {
818
                 || browser.isReactNative()) {
822
 
819
 
823
             this.RTCPeerConnectionType = RTCPeerConnection;
820
             this.RTCPeerConnectionType = RTCPeerConnection;
946
     _initPCConstraints(options) {
943
     _initPCConstraints(options) {
947
         if (browser.isFirefox()) {
944
         if (browser.isFirefox()) {
948
             this.pcConstraints = {};
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
             this.pcConstraints = { optional: [
947
             this.pcConstraints = { optional: [
955
                 { googHighStartBitrate: 0 },
948
                 { googHighStartBitrate: 0 },
956
                 { googPayloadPadding: true },
949
                 { googPayloadPadding: true },
1457
     isDeviceChangeAvailable(deviceType) {
1450
     isDeviceChangeAvailable(deviceType) {
1458
         return deviceType === 'output' || deviceType === 'audiooutput'
1451
         return deviceType === 'output' || deviceType === 'audiooutput'
1459
             ? isAudioOutputDeviceChangeAvailable
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 View File

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

+ 25
- 17
modules/browser/BrowserCapabilities.js View File

47
         return !this.isEdge() && !this.isFirefox();
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
      * Checks if current browser is a Safari and a version of Safari that
70
      * Checks if current browser is a Safari and a version of Safari that
52
      * supports native webrtc.
71
      * supports native webrtc.
64
      * @returns {boolean} true if the browser is supported, false otherwise.
83
      * @returns {boolean} true if the browser is supported, false otherwise.
65
      */
84
      */
66
     isSupported() {
85
     isSupported() {
67
-        return this.isChrome()
86
+        return this.isChromiumBased()
68
             || this.isEdge()
87
             || this.isEdge()
69
-            || this.isElectron()
70
             || this.isFirefox()
88
             || this.isFirefox()
71
-            || this.isNWJS()
72
-            || this.isOpera()
73
             || this.isReactNative()
89
             || this.isReactNative()
74
             || this.isSafariWithWebrtc();
90
             || this.isSafariWithWebrtc();
75
     }
91
     }
81
      * otherwise.
97
      * otherwise.
82
      */
98
      */
83
     supportsVideoMuteOnConnInterrupted() {
99
     supportsVideoMuteOnConnInterrupted() {
84
-        return this.isChrome() || this.isElectron() || this.isReactNative();
100
+        return this.isChromiumBased() || this.isReactNative();
85
     }
101
     }
86
 
102
 
87
     /**
103
     /**
132
      * @returns {boolean} true if they are supported, false otherwise.
148
      * @returns {boolean} true if they are supported, false otherwise.
133
      */
149
      */
134
     supportsRtpStatistics() {
150
     supportsRtpStatistics() {
135
-        return this.isChrome()
151
+        return this.isChromiumBased()
136
             || this.isEdge()
152
             || this.isEdge()
137
-            || this.isElectron()
138
             || this.isFirefox()
153
             || this.isFirefox()
139
-            || this.isNWJS()
140
-            || this.isOpera()
141
             || this.isReactNative()
154
             || this.isReactNative()
142
             || this.isSafariWithWebrtc();
155
             || this.isSafariWithWebrtc();
143
     }
156
     }
147
      * candidates through the legacy getStats() API.
160
      * candidates through the legacy getStats() API.
148
      */
161
      */
149
     supportsLocalCandidateRttStatistics() {
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
      * @returns {boolean}
203
      * @returns {boolean}
193
      */
204
      */
194
     supportsSimulcast() {
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
     /**

Loading…
Cancel
Save