Browse Source

feat(TS) Migrate BrowserCapabilities to TS.

master
Jaya Allamsetty 5 months ago
parent
commit
ef7b7db0b2
1 changed files with 95 additions and 97 deletions
  1. 95
    97
      modules/browser/BrowserCapabilities.ts

modules/browser/BrowserCapabilities.js → modules/browser/BrowserCapabilities.ts View File

@@ -1,4 +1,4 @@
1
-import { BrowserDetection } from '@jitsi/js-utils';
1
+import BrowserDetection from '@jitsi/js-utils/browser-detection/BrowserDetection';
2 2
 
3 3
 /* Minimum required Chrome / Chromium version. This applies also to derivatives. */
4 4
 const MIN_REQUIRED_CHROME_VERSION = 72;
@@ -20,6 +20,32 @@ const FROZEN_MACOS_VERSION = '10.15.7';
20 20
  * Implements browser capabilities for lib-jitsi-meet.
21 21
  */
22 22
 export default class BrowserCapabilities extends BrowserDetection {
23
+    /**
24
+     * Returns the version of an ios browser.
25
+     *
26
+     * @returns {Number}
27
+     */
28
+    _getIOSVersion(): number {
29
+        if (this.isWebKitBased()) {
30
+            return Number.parseInt(this.getOSVersion(), 10);
31
+        }
32
+
33
+        return -1;
34
+    }
35
+
36
+    /**
37
+     * Returns the version of a Safari browser.
38
+     *
39
+     * @returns {Number}
40
+     */
41
+    _getSafariVersion(): number {
42
+        if (this.isSafari()) {
43
+            return Number.parseInt(this.getVersion(), 10);
44
+        }
45
+
46
+        return -1;
47
+    }
48
+
23 49
     /**
24 50
      * Tells whether or not the <tt>MediaStream/tt> is removed from the <tt>PeerConnection</tt> and disposed on video
25 51
      * mute (in order to turn off the camera device). This is needed on Firefox because of the following bug
@@ -27,7 +53,7 @@ export default class BrowserCapabilities extends BrowserDetection {
27 53
      *
28 54
      * @return {boolean} <tt>true</tt> if the current browser supports this strategy or <tt>false</tt> otherwise.
29 55
      */
30
-    doesVideoMuteByStreamRemove() {
56
+    doesVideoMuteByStreamRemove(): boolean {
31 57
         return this.isChromiumBased() || this.isWebKitBased() || this.isFirefox();
32 58
     }
33 59
 
@@ -36,7 +62,7 @@ export default class BrowserCapabilities extends BrowserDetection {
36 62
      *
37 63
      * @returns {boolean}
38 64
      */
39
-    isAndroidBrowser() {
65
+    isAndroidBrowser(): boolean {
40 66
         return !this.isReactNative() && this.getOS() === 'Android';
41 67
     }
42 68
 
@@ -45,14 +71,16 @@ export default class BrowserCapabilities extends BrowserDetection {
45 71
      *
46 72
      * @returns {boolean}
47 73
      */
48
-    isIosBrowser() {
74
+    isIosBrowser(): boolean {
49 75
         return !this.isReactNative() && this.getOS() === 'iOS';
50 76
     }
51 77
 
52 78
     /**
53 79
      * Checks if the client is running on a mobile device.
80
+     *
81
+     * @returns {boolean}
54 82
      */
55
-    isMobileDevice() {
83
+    isMobileDevice(): boolean {
56 84
         return this.isAndroidBrowser() || this.isIosBrowser() || this.isReactNative();
57 85
     }
58 86
 
@@ -61,7 +89,7 @@ export default class BrowserCapabilities extends BrowserDetection {
61 89
      *
62 90
      * @returns {boolean} Whether the current context is a TWA.
63 91
      */
64
-    isTwa() {
92
+    isTwa(): boolean {
65 93
         return 'matchMedia' in window && window.matchMedia('(display-mode:standalone)').matches;
66 94
     }
67 95
 
@@ -70,7 +98,7 @@ export default class BrowserCapabilities extends BrowserDetection {
70 98
      *
71 99
      * @returns {boolean} true if the browser is supported, false otherwise.
72 100
      */
73
-    isSupported() {
101
+    isSupported(): boolean {
74 102
         // First check for WebRTC APIs because some "security" extensions are dumb.
75 103
         if (typeof RTCPeerConnection === 'undefined'
76 104
                 || !navigator?.mediaDevices?.enumerateDevices || !navigator?.mediaDevices?.getUserMedia) {
@@ -88,18 +116,20 @@ export default class BrowserCapabilities extends BrowserDetection {
88 116
     }
89 117
 
90 118
     /**
91
-     * Returns whether the browser is supported for Android
92
-     * @returns {boolean} true if the browser is supported for Android devices
119
+     * Returns whether the browser is supported for Android.
120
+     *
121
+     * @returns {boolean} true if the browser is supported for Android devices.
93 122
      */
94
-    isSupportedAndroidBrowser() {
123
+    isSupportedAndroidBrowser(): boolean {
95 124
         return this.isChromiumBased() || this.isFirefox();
96 125
     }
97 126
 
98 127
     /**
99
-     * Returns whether the browser is supported for iOS
100
-     * @returns {boolean} true if the browser is supported for iOS devices
128
+     * Returns whether the browser is supported for iOS.
129
+     *
130
+     * @returns {boolean} true if the browser is supported for iOS devices.
101 131
      */
102
-    isSupportedIOSBrowser() {
132
+    isSupportedIOSBrowser(): boolean {
103 133
         // After iPadOS 13 we have no way to know the Safari or iPadOS version, so YOLO.
104 134
         if (!this.isSafari() && this.isWebKitBased() && this.getOSVersion() === FROZEN_MACOS_VERSION) {
105 135
             return true;
@@ -115,26 +145,26 @@ export default class BrowserCapabilities extends BrowserDetection {
115 145
      *
116 146
      * @returns {boolean}
117 147
      */
118
-    isUserInteractionRequiredForUnmute() {
119
-        return this.isFirefox() && this.isVersionLessThan('68');
148
+    isUserInteractionRequiredForUnmute(): boolean {
149
+        return this.isFirefox() && this.isVersionLessThan(68);
120 150
     }
121 151
 
122 152
     /**
123 153
      * Checks if the current browser triggers 'onmute'/'onunmute' events when
124 154
      * user's connection is interrupted and the video stops playback.
125
-     * @returns {*|boolean} 'true' if the event is supported or 'false'
126
-     * otherwise.
155
+     *
156
+     * @returns {*|boolean} 'true' if the event is supported or 'false' otherwise.
127 157
      */
128
-    supportsVideoMuteOnConnInterrupted() {
158
+    supportsVideoMuteOnConnInterrupted(): any | boolean {
129 159
         return this.isChromiumBased() || this.isReactNative();
130 160
     }
131 161
 
132 162
     /**
133
-     * Checks if the current browser reports upload and download bandwidth
134
-     * statistics.
163
+     * Checks if the current browser reports upload and download bandwidth statistics.
164
+     *
135 165
      * @return {boolean}
136 166
      */
137
-    supportsBandwidthStatistics() {
167
+    supportsBandwidthStatistics(): boolean {
138 168
         // FIXME bandwidth stats are currently not implemented for FF on our
139 169
         // side, but not sure if not possible ?
140 170
         return !this.isFirefox() && !this.isWebKitBased();
@@ -142,13 +172,12 @@ export default class BrowserCapabilities extends BrowserDetection {
142 172
 
143 173
     /**
144 174
      * Checks if the current browser supports setting codec preferences on the transceiver.
175
+     *
145 176
      * @returns {boolean}
146 177
      */
147
-    supportsCodecPreferences() {
148
-        return Boolean(window.RTCRtpTransceiver
149
-            && 'setCodecPreferences' in window.RTCRtpTransceiver.prototype
150
-            && window.RTCRtpReceiver
151
-            && typeof window.RTCRtpReceiver.getCapabilities !== 'undefined')
178
+    supportsCodecPreferences(): boolean {
179
+        return Boolean('setCodecPreferences' in window.RTCRtpTransceiver?.prototype
180
+            && typeof window.RTCRtpReceiver?.getCapabilities !== 'undefined')
152 181
 
153 182
             // this is not working on Safari because of the following bug
154 183
             // https://bugs.webkit.org/show_bug.cgi?id=215567
@@ -167,7 +196,7 @@ export default class BrowserCapabilities extends BrowserDetection {
167 196
      *
168 197
      * @returns {boolean}
169 198
      */
170
-    supportsCodecSelectionAPI() {
199
+    supportsCodecSelectionAPI(): boolean {
171 200
         return this.isChromiumBased() && this.isEngineVersionGreaterThan(125);
172 201
     }
173 202
 
@@ -176,44 +205,35 @@ export default class BrowserCapabilities extends BrowserDetection {
176 205
      *
177 206
      * @returns {boolean}
178 207
      */
179
-    supportsDDExtHeaders() {
180
-        return !(this.isFirefox() && this.isVersionLessThan('136'));
208
+    supportsDDExtHeaders(): boolean {
209
+        return !(this.isFirefox() && this.isVersionLessThan(136));
181 210
     }
182 211
 
183 212
     /**
184 213
      * Checks if the current browser support the device change event.
185 214
      * @return {boolean}
186 215
      */
187
-    supportsDeviceChangeEvent() {
188
-        return navigator.mediaDevices
189
-            && typeof navigator.mediaDevices.ondevicechange !== 'undefined'
190
-            && typeof navigator.mediaDevices.addEventListener !== 'undefined';
191
-    }
192
-
193
-    /**
194
-     * Checks if the current browser supports the Long Tasks API that lets us observe
195
-     * performance measurement events and be notified of tasks that take longer than
196
-     * 50ms to execute on the main thread.
197
-     */
198
-    supportsPerformanceObserver() {
199
-        return typeof window.PerformanceObserver !== 'undefined'
200
-            && PerformanceObserver.supportedEntryTypes.indexOf('longtask') > -1;
216
+    supportsDeviceChangeEvent(): boolean {
217
+        return typeof navigator.mediaDevices?.ondevicechange !== 'undefined'
218
+            && typeof navigator.mediaDevices?.addEventListener !== 'undefined';
201 219
     }
202 220
 
203 221
     /**
204 222
      * Checks if the current browser supports audio level stats on the receivers.
223
+     *
224
+     * @return {boolean}
205 225
      */
206
-    supportsReceiverStats() {
226
+    supportsReceiverStats(): boolean {
207 227
         return typeof window.RTCRtpReceiver !== 'undefined'
208 228
             && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1;
209 229
     }
210 230
 
211 231
     /**
212
-     * Checks if the current browser reports round trip time statistics for
213
-     * the ICE candidate pair.
232
+     * Checks if the current browser reports round trip time statistics for the ICE candidate pair.
233
+     *
214 234
      * @return {boolean}
215 235
      */
216
-    supportsRTTStatistics() {
236
+    supportsRTTStatistics(): boolean {
217 237
         // Firefox does not seem to report RTT for ICE candidate pair:
218 238
         // eslint-disable-next-line max-len
219 239
         // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
@@ -232,16 +252,17 @@ export default class BrowserCapabilities extends BrowserDetection {
232 252
      *
233 253
      * @returns {boolean}
234 254
      */
235
-    supportsScalabilityModeAPI() {
255
+    supportsScalabilityModeAPI(): boolean {
236 256
         return this.isChromiumBased() && this.isEngineVersionGreaterThan(112);
237 257
     }
238 258
 
239 259
     /**
240 260
      * Returns true if the browser supports track based statistics for the local video track. Otherwise,
241 261
      * track resolution and framerate will be calculated based on the 'outbound-rtp' statistics.
262
+     *
242 263
      * @returns {boolean}
243 264
      */
244
-    supportsTrackBasedStats() {
265
+    supportsTrackBasedStats(): boolean {
245 266
         return this.isChromiumBased() && this.isEngineVersionLessThan(112);
246 267
     }
247 268
 
@@ -249,8 +270,10 @@ export default class BrowserCapabilities extends BrowserDetection {
249 270
      * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Safari
250 271
      * and older versions of Firefox because of issues. Please check https://bugs.webkit.org/show_bug.cgi?id=231074 for
251 272
      * details.
273
+     *
274
+     * @returns {boolean}
252 275
      */
253
-    supportsVP9() {
276
+    supportsVP9(): boolean {
254 277
         // Keep this disabled for FF because simulcast is disabled by default.
255 278
         // For versions 136+ if the media.webrtc.simulcast.vp9.enabled config is set to true it will work.
256 279
         // TODO: enable for FF with version 136+ once media.webrtc.simulcast.vp9.enabled is set to true by default.
@@ -262,7 +285,7 @@ export default class BrowserCapabilities extends BrowserDetection {
262 285
      *
263 286
      * @returns {boolean}
264 287
      */
265
-    supportsSVC() {
288
+    supportsSVC(): boolean {
266 289
         return !this.isFirefox();
267 290
     }
268 291
 
@@ -271,27 +294,29 @@ export default class BrowserCapabilities extends BrowserDetection {
271 294
      *
272 295
      * @returns {boolean}
273 296
      */
274
-    usesSdpMungingForSimulcast() {
297
+    usesSdpMungingForSimulcast(): boolean {
275 298
         return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
276 299
     }
277 300
 
278 301
     /**
279 302
      * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
280 303
      * to the bridge instead of the ssrcs.
304
+     *
305
+     * @returns {boolean}
281 306
      */
282
-    usesRidsForSimulcast() {
307
+    usesRidsForSimulcast(): boolean {
283 308
         return false;
284 309
     }
285 310
 
286 311
     /**
287 312
      * Checks if the browser supports getDisplayMedia.
313
+     *
288 314
      * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
289 315
      */
290
-    supportsGetDisplayMedia() {
316
+    supportsGetDisplayMedia(): boolean {
317
+        // @ts-ignore
291 318
         return typeof navigator.getDisplayMedia !== 'undefined'
292
-            || (typeof navigator.mediaDevices !== 'undefined'
293
-                && typeof navigator.mediaDevices.getDisplayMedia
294
-                    !== 'undefined');
319
+            || (typeof navigator.mediaDevices?.getDisplayMedia !== 'undefined');
295 320
     }
296 321
 
297 322
     /**
@@ -303,17 +328,18 @@ export default class BrowserCapabilities extends BrowserDetection {
303 328
      *
304 329
      * @returns {boolean} {@code true} if the browser supports it.
305 330
      */
306
-    supportsEncodedTransform() {
331
+    supportsEncodedTransform(): boolean {
307 332
         return Boolean(window.RTCRtpScriptTransform);
308 333
     }
309 334
 
310 335
     /**
311 336
      * Checks if the browser supports insertable streams, needed for E2EE.
337
+     *
312 338
      * @returns {boolean} {@code true} if the browser supports insertable streams.
313 339
      */
314
-    supportsInsertableStreams() {
315
-        if (!(typeof window.RTCRtpSender !== 'undefined'
316
-            && window.RTCRtpSender.prototype.createEncodedStreams)) {
340
+    supportsInsertableStreams(): boolean {
341
+        // @ts-ignore
342
+        if (!window.RTCRtpSender?.prototype.createEncodedStreams) {
317 343
             return false;
318 344
         }
319 345
 
@@ -332,14 +358,12 @@ export default class BrowserCapabilities extends BrowserDetection {
332 358
 
333 359
     /**
334 360
      * Whether the browser supports the RED format for audio.
361
+     *
362
+     * @returns {boolean} {@code true} if the browser supports RED.
335 363
      */
336
-    supportsAudioRed() {
337
-        return Boolean(window.RTCRtpSender
338
-            && window.RTCRtpSender.getCapabilities
339
-            && window.RTCRtpSender.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red')
340
-            && window.RTCRtpReceiver
341
-            && window.RTCRtpReceiver.getCapabilities
342
-            && window.RTCRtpReceiver.getCapabilities('audio').codecs.some(codec => codec.mimeType === 'audio/red'));
364
+    supportsAudioRed(): boolean {
365
+        return Boolean(window.RTCRtpSender?.getCapabilities('audio')?.codecs.some(codec => codec.mimeType === 'audio/red')
366
+            && window.RTCRtpReceiver?.getCapabilities('audio')?.codecs.some(codec => codec.mimeType === 'audio/red'));
343 367
     }
344 368
 
345 369
     /**
@@ -347,7 +371,7 @@ export default class BrowserCapabilities extends BrowserDetection {
347 371
      *
348 372
      * @returns {boolean}
349 373
      */
350
-    supportsVADDetection() {
374
+    supportsVADDetection(): boolean {
351 375
         return this.isChromiumBased();
352 376
     }
353 377
 
@@ -356,35 +380,9 @@ export default class BrowserCapabilities extends BrowserDetection {
356 380
      *
357 381
      * @returns {boolean}
358 382
      */
359
-    supportsRTX() {
383
+    supportsRTX(): boolean {
360 384
         // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
361 385
         // see https://bugzilla.mozilla.org/show_bug.cgi?id=1738504
362
-        return !(this.isFirefox() && this.isVersionLessThan('96'));
363
-    }
364
-
365
-    /**
366
-     * Returns the version of a Safari browser.
367
-     *
368
-     * @returns {Number}
369
-     */
370
-    _getSafariVersion() {
371
-        if (this.isSafari()) {
372
-            return Number.parseInt(this.getVersion(), 10);
373
-        }
374
-
375
-        return -1;
376
-    }
377
-
378
-    /**
379
-     * Returns the version of an ios browser.
380
-     *
381
-     * @returns {Number}
382
-     */
383
-    _getIOSVersion() {
384
-        if (this.isWebKitBased()) {
385
-            return Number.parseInt(this.getOSVersion(), 10);
386
-        }
387
-
388
-        return -1;
386
+        return !(this.isFirefox() && this.isVersionLessThan(96));
389 387
     }
390 388
 }

Loading…
Cancel
Save