Kaynağa Gözat

feat(TS) Migrate BrowserCapabilities to TS.

master
Jaya Allamsetty 5 ay önce
ebeveyn
işleme
ef7b7db0b2
1 değiştirilmiş dosya ile 95 ekleme ve 97 silme
  1. 95
    97
      modules/browser/BrowserCapabilities.ts

modules/browser/BrowserCapabilities.js → modules/browser/BrowserCapabilities.ts Dosyayı Görüntüle

1
-import { BrowserDetection } from '@jitsi/js-utils';
1
+import BrowserDetection from '@jitsi/js-utils/browser-detection/BrowserDetection';
2
 
2
 
3
 /* Minimum required Chrome / Chromium version. This applies also to derivatives. */
3
 /* Minimum required Chrome / Chromium version. This applies also to derivatives. */
4
 const MIN_REQUIRED_CHROME_VERSION = 72;
4
 const MIN_REQUIRED_CHROME_VERSION = 72;
20
  * Implements browser capabilities for lib-jitsi-meet.
20
  * Implements browser capabilities for lib-jitsi-meet.
21
  */
21
  */
22
 export default class BrowserCapabilities extends BrowserDetection {
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
      * Tells whether or not the <tt>MediaStream/tt> is removed from the <tt>PeerConnection</tt> and disposed on video
50
      * Tells whether or not the <tt>MediaStream/tt> is removed from the <tt>PeerConnection</tt> and disposed on video
25
      * mute (in order to turn off the camera device). This is needed on Firefox because of the following bug
51
      * mute (in order to turn off the camera device). This is needed on Firefox because of the following bug
27
      *
53
      *
28
      * @return {boolean} <tt>true</tt> if the current browser supports this strategy or <tt>false</tt> otherwise.
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
         return this.isChromiumBased() || this.isWebKitBased() || this.isFirefox();
57
         return this.isChromiumBased() || this.isWebKitBased() || this.isFirefox();
32
     }
58
     }
33
 
59
 
36
      *
62
      *
37
      * @returns {boolean}
63
      * @returns {boolean}
38
      */
64
      */
39
-    isAndroidBrowser() {
65
+    isAndroidBrowser(): boolean {
40
         return !this.isReactNative() && this.getOS() === 'Android';
66
         return !this.isReactNative() && this.getOS() === 'Android';
41
     }
67
     }
42
 
68
 
45
      *
71
      *
46
      * @returns {boolean}
72
      * @returns {boolean}
47
      */
73
      */
48
-    isIosBrowser() {
74
+    isIosBrowser(): boolean {
49
         return !this.isReactNative() && this.getOS() === 'iOS';
75
         return !this.isReactNative() && this.getOS() === 'iOS';
50
     }
76
     }
51
 
77
 
52
     /**
78
     /**
53
      * Checks if the client is running on a mobile device.
79
      * Checks if the client is running on a mobile device.
80
+     *
81
+     * @returns {boolean}
54
      */
82
      */
55
-    isMobileDevice() {
83
+    isMobileDevice(): boolean {
56
         return this.isAndroidBrowser() || this.isIosBrowser() || this.isReactNative();
84
         return this.isAndroidBrowser() || this.isIosBrowser() || this.isReactNative();
57
     }
85
     }
58
 
86
 
61
      *
89
      *
62
      * @returns {boolean} Whether the current context is a TWA.
90
      * @returns {boolean} Whether the current context is a TWA.
63
      */
91
      */
64
-    isTwa() {
92
+    isTwa(): boolean {
65
         return 'matchMedia' in window && window.matchMedia('(display-mode:standalone)').matches;
93
         return 'matchMedia' in window && window.matchMedia('(display-mode:standalone)').matches;
66
     }
94
     }
67
 
95
 
70
      *
98
      *
71
      * @returns {boolean} true if the browser is supported, false otherwise.
99
      * @returns {boolean} true if the browser is supported, false otherwise.
72
      */
100
      */
73
-    isSupported() {
101
+    isSupported(): boolean {
74
         // First check for WebRTC APIs because some "security" extensions are dumb.
102
         // First check for WebRTC APIs because some "security" extensions are dumb.
75
         if (typeof RTCPeerConnection === 'undefined'
103
         if (typeof RTCPeerConnection === 'undefined'
76
                 || !navigator?.mediaDevices?.enumerateDevices || !navigator?.mediaDevices?.getUserMedia) {
104
                 || !navigator?.mediaDevices?.enumerateDevices || !navigator?.mediaDevices?.getUserMedia) {
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
         return this.isChromiumBased() || this.isFirefox();
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
         // After iPadOS 13 we have no way to know the Safari or iPadOS version, so YOLO.
133
         // After iPadOS 13 we have no way to know the Safari or iPadOS version, so YOLO.
104
         if (!this.isSafari() && this.isWebKitBased() && this.getOSVersion() === FROZEN_MACOS_VERSION) {
134
         if (!this.isSafari() && this.isWebKitBased() && this.getOSVersion() === FROZEN_MACOS_VERSION) {
105
             return true;
135
             return true;
115
      *
145
      *
116
      * @returns {boolean}
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
      * Checks if the current browser triggers 'onmute'/'onunmute' events when
153
      * Checks if the current browser triggers 'onmute'/'onunmute' events when
124
      * user's connection is interrupted and the video stops playback.
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
         return this.isChromiumBased() || this.isReactNative();
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
      * @return {boolean}
165
      * @return {boolean}
136
      */
166
      */
137
-    supportsBandwidthStatistics() {
167
+    supportsBandwidthStatistics(): boolean {
138
         // FIXME bandwidth stats are currently not implemented for FF on our
168
         // FIXME bandwidth stats are currently not implemented for FF on our
139
         // side, but not sure if not possible ?
169
         // side, but not sure if not possible ?
140
         return !this.isFirefox() && !this.isWebKitBased();
170
         return !this.isFirefox() && !this.isWebKitBased();
142
 
172
 
143
     /**
173
     /**
144
      * Checks if the current browser supports setting codec preferences on the transceiver.
174
      * Checks if the current browser supports setting codec preferences on the transceiver.
175
+     *
145
      * @returns {boolean}
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
             // this is not working on Safari because of the following bug
182
             // this is not working on Safari because of the following bug
154
             // https://bugs.webkit.org/show_bug.cgi?id=215567
183
             // https://bugs.webkit.org/show_bug.cgi?id=215567
167
      *
196
      *
168
      * @returns {boolean}
197
      * @returns {boolean}
169
      */
198
      */
170
-    supportsCodecSelectionAPI() {
199
+    supportsCodecSelectionAPI(): boolean {
171
         return this.isChromiumBased() && this.isEngineVersionGreaterThan(125);
200
         return this.isChromiumBased() && this.isEngineVersionGreaterThan(125);
172
     }
201
     }
173
 
202
 
176
      *
205
      *
177
      * @returns {boolean}
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
      * Checks if the current browser support the device change event.
213
      * Checks if the current browser support the device change event.
185
      * @return {boolean}
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
      * Checks if the current browser supports audio level stats on the receivers.
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
         return typeof window.RTCRtpReceiver !== 'undefined'
227
         return typeof window.RTCRtpReceiver !== 'undefined'
208
             && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1;
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
      * @return {boolean}
234
      * @return {boolean}
215
      */
235
      */
216
-    supportsRTTStatistics() {
236
+    supportsRTTStatistics(): boolean {
217
         // Firefox does not seem to report RTT for ICE candidate pair:
237
         // Firefox does not seem to report RTT for ICE candidate pair:
218
         // eslint-disable-next-line max-len
238
         // eslint-disable-next-line max-len
219
         // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
239
         // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
232
      *
252
      *
233
      * @returns {boolean}
253
      * @returns {boolean}
234
      */
254
      */
235
-    supportsScalabilityModeAPI() {
255
+    supportsScalabilityModeAPI(): boolean {
236
         return this.isChromiumBased() && this.isEngineVersionGreaterThan(112);
256
         return this.isChromiumBased() && this.isEngineVersionGreaterThan(112);
237
     }
257
     }
238
 
258
 
239
     /**
259
     /**
240
      * Returns true if the browser supports track based statistics for the local video track. Otherwise,
260
      * Returns true if the browser supports track based statistics for the local video track. Otherwise,
241
      * track resolution and framerate will be calculated based on the 'outbound-rtp' statistics.
261
      * track resolution and framerate will be calculated based on the 'outbound-rtp' statistics.
262
+     *
242
      * @returns {boolean}
263
      * @returns {boolean}
243
      */
264
      */
244
-    supportsTrackBasedStats() {
265
+    supportsTrackBasedStats(): boolean {
245
         return this.isChromiumBased() && this.isEngineVersionLessThan(112);
266
         return this.isChromiumBased() && this.isEngineVersionLessThan(112);
246
     }
267
     }
247
 
268
 
249
      * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Safari
270
      * Returns true if VP9 is supported by the client on the browser. VP9 is currently disabled on Safari
250
      * and older versions of Firefox because of issues. Please check https://bugs.webkit.org/show_bug.cgi?id=231074 for
271
      * and older versions of Firefox because of issues. Please check https://bugs.webkit.org/show_bug.cgi?id=231074 for
251
      * details.
272
      * details.
273
+     *
274
+     * @returns {boolean}
252
      */
275
      */
253
-    supportsVP9() {
276
+    supportsVP9(): boolean {
254
         // Keep this disabled for FF because simulcast is disabled by default.
277
         // Keep this disabled for FF because simulcast is disabled by default.
255
         // For versions 136+ if the media.webrtc.simulcast.vp9.enabled config is set to true it will work.
278
         // For versions 136+ if the media.webrtc.simulcast.vp9.enabled config is set to true it will work.
256
         // TODO: enable for FF with version 136+ once media.webrtc.simulcast.vp9.enabled is set to true by default.
279
         // TODO: enable for FF with version 136+ once media.webrtc.simulcast.vp9.enabled is set to true by default.
262
      *
285
      *
263
      * @returns {boolean}
286
      * @returns {boolean}
264
      */
287
      */
265
-    supportsSVC() {
288
+    supportsSVC(): boolean {
266
         return !this.isFirefox();
289
         return !this.isFirefox();
267
     }
290
     }
268
 
291
 
271
      *
294
      *
272
      * @returns {boolean}
295
      * @returns {boolean}
273
      */
296
      */
274
-    usesSdpMungingForSimulcast() {
297
+    usesSdpMungingForSimulcast(): boolean {
275
         return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
298
         return this.isChromiumBased() || this.isReactNative() || this.isWebKitBased();
276
     }
299
     }
277
 
300
 
278
     /**
301
     /**
279
      * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
302
      * Checks if the browser uses RIDs/MIDs for siganling the simulcast streams
280
      * to the bridge instead of the ssrcs.
303
      * to the bridge instead of the ssrcs.
304
+     *
305
+     * @returns {boolean}
281
      */
306
      */
282
-    usesRidsForSimulcast() {
307
+    usesRidsForSimulcast(): boolean {
283
         return false;
308
         return false;
284
     }
309
     }
285
 
310
 
286
     /**
311
     /**
287
      * Checks if the browser supports getDisplayMedia.
312
      * Checks if the browser supports getDisplayMedia.
313
+     *
288
      * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
314
      * @returns {boolean} {@code true} if the browser supports getDisplayMedia.
289
      */
315
      */
290
-    supportsGetDisplayMedia() {
316
+    supportsGetDisplayMedia(): boolean {
317
+        // @ts-ignore
291
         return typeof navigator.getDisplayMedia !== 'undefined'
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
      *
328
      *
304
      * @returns {boolean} {@code true} if the browser supports it.
329
      * @returns {boolean} {@code true} if the browser supports it.
305
      */
330
      */
306
-    supportsEncodedTransform() {
331
+    supportsEncodedTransform(): boolean {
307
         return Boolean(window.RTCRtpScriptTransform);
332
         return Boolean(window.RTCRtpScriptTransform);
308
     }
333
     }
309
 
334
 
310
     /**
335
     /**
311
      * Checks if the browser supports insertable streams, needed for E2EE.
336
      * Checks if the browser supports insertable streams, needed for E2EE.
337
+     *
312
      * @returns {boolean} {@code true} if the browser supports insertable streams.
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
             return false;
343
             return false;
318
         }
344
         }
319
 
345
 
332
 
358
 
333
     /**
359
     /**
334
      * Whether the browser supports the RED format for audio.
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
      *
371
      *
348
      * @returns {boolean}
372
      * @returns {boolean}
349
      */
373
      */
350
-    supportsVADDetection() {
374
+    supportsVADDetection(): boolean {
351
         return this.isChromiumBased();
375
         return this.isChromiumBased();
352
     }
376
     }
353
 
377
 
356
      *
380
      *
357
      * @returns {boolean}
381
      * @returns {boolean}
358
      */
382
      */
359
-    supportsRTX() {
383
+    supportsRTX(): boolean {
360
         // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
384
         // Disable RTX on Firefox up to 96 because we prefer simulcast over RTX
361
         // see https://bugzilla.mozilla.org/show_bug.cgi?id=1738504
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…
İptal
Kaydet