Browse Source

feat(ts) migrate JitsiMeetJS to TS

tags/v0.0.2
Saúl Ibarra Corretgé 2 years ago
parent
commit
268772b0b8
3 changed files with 38 additions and 16 deletions
  1. 31
    15
      JitsiMeetJS.ts
  2. 7
    0
      globals.d.ts
  3. 0
    1
      modules/connectivity/NetworkInfo.js

JitsiMeetJS.js → JitsiMeetJS.ts View File

@@ -55,14 +55,11 @@ const USER_MEDIA_SLOW_PROMISE_TIMEOUT = 1000;
55 55
  * @returns {*} the attributes to attach to analytics events.
56 56
  */
57 57
 function getAnalyticsAttributesFromOptions(options) {
58
-    const attributes = {
59
-        'audio_requested':
60
-            options.devices.includes('audio'),
61
-        'video_requested':
62
-            options.devices.includes('video'),
63
-        'screen_sharing_requested':
64
-            options.devices.includes('desktop')
65
-    };
58
+    const attributes: any = {};
59
+
60
+    attributes['audio_requested'] = options.devices.includes('audio');
61
+    attributes['video_requested'] = options.devices.includes('video');
62
+    attributes['screen_sharing_requested'] = options.devices.includes('desktop');
66 63
 
67 64
     if (attributes.video_requested) {
68 65
         attributes.resolution = options.resolution;
@@ -71,6 +68,25 @@ function getAnalyticsAttributesFromOptions(options) {
71 68
     return attributes;
72 69
 }
73 70
 
71
+interface ICreateLocalTrackOptions {
72
+    cameraDeviceId?: string;
73
+    devices?: any[];
74
+    firePermissionPromptIsShownEvent?: boolean;
75
+    fireSlowPromiseEvent?: boolean;
76
+    micDeviceId?: string;
77
+    resolution?: string;
78
+}
79
+
80
+interface IJitsiMeetJSOptions {
81
+    enableAnalyticsLogging?: boolean;
82
+    enableUnifiedOnChrome?: boolean;
83
+    enableWindowOnErrorHandler?: boolean;
84
+    externalStorage?: Storage;
85
+    flags?: {
86
+        enableUnifiedOnChrome?: boolean;
87
+    }
88
+}
89
+
74 90
 /**
75 91
  * The public API of the Jitsi Meet library (a.k.a. {@code JitsiMeetJS}).
76 92
  */
@@ -114,9 +130,9 @@ export default {
114 130
         JitsiTrackError
115 131
     },
116 132
     logLevels: Logger.levels,
117
-    mediaDevices: JitsiMediaDevices,
118
-    analytics: Statistics.analytics,
119
-    init(options = {}) {
133
+    mediaDevices: JitsiMediaDevices as unknown,
134
+    analytics: Statistics.analytics as unknown,
135
+    init(options: IJitsiMeetJSOptions = {}) {
120 136
         Settings.init(options.externalStorage);
121 137
         Statistics.init(options);
122 138
         const flags = options.flags || {};
@@ -265,16 +281,15 @@ export default {
265 281
      * that returns an array of created JitsiTracks if resolved, or a
266 282
      * JitsiConferenceError if rejected.
267 283
      */
268
-    createLocalTracks(options = {}, oldfirePermissionPromptIsShownEvent) {
284
+    createLocalTracks(options: ICreateLocalTrackOptions = {}, oldfirePermissionPromptIsShownEvent) {
269 285
         let promiseFulfilled = false;
270 286
 
271 287
         const { firePermissionPromptIsShownEvent, fireSlowPromiseEvent, ...restOptions } = options;
272 288
         const firePermissionPrompt = firePermissionPromptIsShownEvent || oldfirePermissionPromptIsShownEvent;
273 289
 
274 290
         if (firePermissionPrompt && !RTC.arePermissionsGrantedForAvailableDevices()) {
275
-            JitsiMediaDevices.emitEvent(
276
-                JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN,
277
-                browser.getName());
291
+            // @ts-ignore
292
+            JitsiMediaDevices.emitEvent(JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN, browser.getName());
278 293
         } else if (fireSlowPromiseEvent) {
279 294
             window.setTimeout(() => {
280 295
                 if (!promiseFulfilled) {
@@ -289,6 +304,7 @@ export default {
289 304
         window.connectionTimes['obtainPermissions.start']
290 305
             = window.performance.now();
291 306
 
307
+        // @ts-ignore
292 308
         return RTC.obtainAudioAndVideoPermissions(restOptions)
293 309
             .then(tracks => {
294 310
                 promiseFulfilled = true;

+ 7
- 0
globals.d.ts View File

@@ -0,0 +1,7 @@
1
+export {};
2
+
3
+declare global {
4
+    interface Window {
5
+        connectionTimes: any;
6
+    }
7
+}

+ 0
- 1
modules/connectivity/NetworkInfo.js View File

@@ -26,7 +26,6 @@ export class NetworkInfo extends Listenable {
26 26
 
27 27
     /**
28 28
      * Updates the network info state.
29
-     * @param {boolean} isOnline - {@code true} if internet is online or {@code false} otherwise.
30 29
      */
31 30
     updateNetworkInfo({ isOnline }) {
32 31
         logger.debug('updateNetworkInfo', { isOnline });

Loading…
Cancel
Save