Переглянути джерело

Unify events and output single TypeScript declaration (#2407)

* fix(events): unify events to a single EventManager type, add support for single typescript declaration

* fix(lint): fix lint

* fix(events): fix incorrect instatiation

* fix(events): clean up redundant methods

* fix(events): keep EventEmitter name, alias NodeEventEmitter

* fix(events): fix loose reference

* fix(EventEmitter): remove on/off alias as redundant

* fix(RTCUtils): bring event handlers under class to use same event emitter

* fix(RTCUtils): fix lint
release-8443
Daniel McAssey 1 рік тому
джерело
коміт
0e9a4e2428
Аккаунт користувача з таким Email не знайдено

+ 1
- 0
.gitignore Переглянути файл

@@ -14,6 +14,7 @@ npm-*.log
14 14
 stats.json
15 15
 .vscode
16 16
 dist
17
+index.d.ts
17 18
 types/auto
18 19
 types/types-comparer/auto.json
19 20
 types/types-comparer/hand-crafted.json

+ 1
- 1
JitsiConference.js Переглянути файл

@@ -1,5 +1,4 @@
1 1
 import { getLogger } from '@jitsi/logger';
2
-import EventEmitter from 'events';
3 2
 import $ from 'jquery';
4 3
 import isEqual from 'lodash.isequal';
5 4
 import { Strophe } from 'strophe.js';
@@ -38,6 +37,7 @@ import AvgRTPStatsReporter from './modules/statistics/AvgRTPStatsReporter';
38 37
 import LocalStatsCollector from './modules/statistics/LocalStatsCollector';
39 38
 import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
40 39
 import Statistics from './modules/statistics/statistics';
40
+import EventEmitter from './modules/util/EventEmitter';
41 41
 import { safeSubtract } from './modules/util/MathUtil';
42 42
 import RandomUtil from './modules/util/RandomUtil';
43 43
 import ComponentsVersions from './modules/version/ComponentsVersions';

+ 5
- 32
JitsiMediaDevices.js Переглянути файл

@@ -1,8 +1,7 @@
1
-import EventEmitter from 'events';
2
-
3 1
 import * as JitsiMediaDevicesEvents from './JitsiMediaDevicesEvents';
4 2
 import RTC from './modules/RTC/RTC';
5 3
 import browser from './modules/browser';
4
+import Listenable from './modules/util/Listenable';
6 5
 import { MediaType } from './service/RTC/MediaType';
7 6
 import RTCEvents from './service/RTC/RTCEvents';
8 7
 
@@ -13,19 +12,19 @@ const VIDEO_PERMISSION_NAME = 'camera';
13 12
 /**
14 13
  * Media devices utilities for Jitsi.
15 14
  */
16
-class JitsiMediaDevices {
15
+class JitsiMediaDevices extends Listenable {
17 16
     /**
18 17
      * Initializes a {@code JitsiMediaDevices} object. There will be a single
19 18
      * instance of this class.
20 19
      */
21 20
     constructor() {
22
-        this._eventEmitter = new EventEmitter();
21
+        super();
23 22
         this._permissions = {};
24 23
 
25 24
         RTC.addListener(
26 25
             RTCEvents.DEVICE_LIST_CHANGED,
27 26
             devices =>
28
-                this._eventEmitter.emit(
27
+                this.eventEmitter.emit(
29 28
                     JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
30 29
                     devices));
31 30
 
@@ -128,7 +127,7 @@ class JitsiMediaDevices {
128 127
                 ...this._permissions,
129 128
                 ...permissions
130 129
             };
131
-            this._eventEmitter.emit(JitsiMediaDevicesEvents.PERMISSIONS_CHANGED, this._permissions);
130
+            this.eventEmitter.emit(JitsiMediaDevicesEvents.PERMISSIONS_CHANGED, this._permissions);
132 131
 
133 132
             if (this._permissions[MediaType.AUDIO] || this._permissions[MediaType.VIDEO]) {
134 133
                 // Triggering device list update when the permissiions are granted in order to update
@@ -265,32 +264,6 @@ class JitsiMediaDevices {
265 264
     setAudioOutputDevice(deviceId) {
266 265
         return RTC.setAudioOutputDevice(deviceId);
267 266
     }
268
-
269
-    /**
270
-     * Adds an event handler.
271
-     * @param {string} event - event name
272
-     * @param {function} handler - event handler
273
-     */
274
-    addEventListener(event, handler) {
275
-        this._eventEmitter.addListener(event, handler);
276
-    }
277
-
278
-    /**
279
-     * Removes event handler.
280
-     * @param {string} event - event name
281
-     * @param {function} handler - event handler
282
-     */
283
-    removeEventListener(event, handler) {
284
-        this._eventEmitter.removeListener(event, handler);
285
-    }
286
-
287
-    /**
288
-     * Emits an event.
289
-     * @param {string} event - event name
290
-     */
291
-    emitEvent(event, ...args) {
292
-        this._eventEmitter.emit(event, ...args);
293
-    }
294 267
 }
295 268
 
296 269
 export default new JitsiMediaDevices();

+ 2
- 2
JitsiMeetJS.ts Переглянути файл

@@ -318,11 +318,11 @@ export default {
318 318
 
319 319
         if (firePermissionPrompt && !RTC.arePermissionsGrantedForAvailableDevices()) {
320 320
             // @ts-ignore
321
-            JitsiMediaDevices.emitEvent(JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN, browser.getName());
321
+            JitsiMediaDevices.emit(JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN, browser.getName());
322 322
         } else if (fireSlowPromiseEvent) {
323 323
             window.setTimeout(() => {
324 324
                 if (!promiseFulfilled) {
325
-                    JitsiMediaDevices.emitEvent(JitsiMediaDevicesEvents.SLOW_GET_USER_MEDIA);
325
+                    JitsiMediaDevices.emit(JitsiMediaDevicesEvents.SLOW_GET_USER_MEDIA);
326 326
                 }
327 327
             }, USER_MEDIA_SLOW_PROMISE_TIMEOUT);
328 328
         }

+ 0
- 3
modules/RTC/CodecSelection.spec.js Переглянути файл

@@ -1,5 +1,3 @@
1
-import EventEmitter from 'events';
2
-
3 1
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents.ts';
4 2
 import Listenable from '../util/Listenable.js';
5 3
 import JingleSessionPC from '../xmpp/JingleSessionPC.js';
@@ -42,7 +40,6 @@ class MockConference extends Listenable {
42 40
         };
43 41
 
44 42
         this.activeMediaSession = undefined;
45
-        this.eventEmitter = new EventEmitter();
46 43
         this.mediaSessions = [];
47 44
         this.participants = [];
48 45
         this._signalingLayer = new MockSignalingLayerImpl();

+ 1
- 5
modules/RTC/JitsiTrack.js Переглянути файл

@@ -1,9 +1,9 @@
1 1
 import { getLogger } from '@jitsi/logger';
2
-import EventEmitter from 'events';
3 2
 
4 3
 import * as JitsiTrackEvents from '../../JitsiTrackEvents';
5 4
 import { MediaType } from '../../service/RTC/MediaType';
6 5
 import browser from '../browser';
6
+import EventEmitter from '../util/EventEmitter';
7 7
 
8 8
 import RTCUtils from './RTCUtils';
9 9
 
@@ -44,10 +44,6 @@ export default class JitsiTrack extends EventEmitter {
44 44
             videoType) {
45 45
         super();
46 46
 
47
-        // aliases for addListener/removeListener
48
-        this.addEventListener = this.addListener;
49
-        this.removeEventListener = this.off = this.removeListener;
50
-
51 47
         /**
52 48
          * Array with the HTML elements that are displaying the streams.
53 49
          * @type {Array}

+ 65
- 74
modules/RTC/RTCUtils.js Переглянути файл

@@ -1,5 +1,4 @@
1 1
 import { getLogger } from '@jitsi/logger';
2
-import EventEmitter from 'events';
3 2
 import clonedeep from 'lodash.clonedeep';
4 3
 import 'webrtc-adapter';
5 4
 
@@ -18,8 +17,6 @@ import screenObtainer from './ScreenObtainer';
18 17
 
19 18
 const logger = getLogger(__filename);
20 19
 
21
-const eventEmitter = new EventEmitter();
22
-
23 20
 const AVAILABLE_DEVICES_POLL_INTERVAL_TIME = 3000; // ms
24 21
 
25 22
 /**
@@ -157,29 +154,6 @@ function getConstraints(um = [], options = {}) {
157 154
     return constraints;
158 155
 }
159 156
 
160
-/**
161
- * Updates the granted permissions based on the options we requested and the
162
- * streams we received.
163
- * @param um the options we requested to getUserMedia.
164
- * @param stream the stream we received from calling getUserMedia.
165
- */
166
-function updateGrantedPermissions(um, stream) {
167
-    const audioTracksReceived
168
-        = Boolean(stream) && stream.getAudioTracks().length > 0;
169
-    const videoTracksReceived
170
-        = Boolean(stream) && stream.getVideoTracks().length > 0;
171
-    const grantedPermissions = {};
172
-
173
-    if (um.indexOf('video') !== -1) {
174
-        grantedPermissions.video = videoTracksReceived;
175
-    }
176
-    if (um.indexOf('audio') !== -1) {
177
-        grantedPermissions.audio = audioTracksReceived;
178
-    }
179
-
180
-    eventEmitter.emit(RTCEvents.PERMISSIONS_CHANGED, grantedPermissions);
181
-}
182
-
183 157
 /**
184 158
  * Checks if new list of available media devices differs from previous one.
185 159
  * @param {MediaDeviceInfo[]} newDevices - list of new devices.
@@ -247,52 +221,10 @@ function sendDeviceListToAnalytics(deviceList) {
247 221
     });
248 222
 }
249 223
 
250
-
251
-/**
252
- * Update known devices.
253
- *
254
- * @param {Array<Object>} pds - The new devices.
255
- * @returns {void}
256
- *
257
- * NOTE: Use this function as a shared callback to handle both the devicechange event  and the polling implementations.
258
- * This prevents duplication and works around a chrome bug (verified to occur on 68) where devicechange fires twice in
259
- * a row, which can cause async post devicechange processing to collide.
260
- */
261
-function updateKnownDevices(pds) {
262
-    if (compareAvailableMediaDevices(pds)) {
263
-        onMediaDevicesListChanged(pds);
264
-    }
265
-}
266
-
267
-/**
268
- * Event handler for the 'devicechange' event.
269
- *
270
- * @param {MediaDeviceInfo[]} devices - list of media devices.
271
- * @emits RTCEvents.DEVICE_LIST_CHANGED
272
- */
273
-function onMediaDevicesListChanged(devicesReceived) {
274
-    availableDevices = devicesReceived.slice(0);
275
-    logger.info('list of media devices has changed:', availableDevices);
276
-
277
-    sendDeviceListToAnalytics(availableDevices);
278
-
279
-    // Used by tracks to update the real device id before the consumer of lib-jitsi-meet receives the new device list.
280
-    eventEmitter.emit(RTCEvents.DEVICE_LIST_WILL_CHANGE, availableDevices);
281
-
282
-    eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, availableDevices);
283
-}
284
-
285 224
 /**
286 225
  *
287 226
  */
288 227
 class RTCUtils extends Listenable {
289
-    /**
290
-     *
291
-     */
292
-    constructor() {
293
-        super(eventEmitter);
294
-    }
295
-
296 228
     /**
297 229
      * Depending on the browser, sets difference instance methods for
298 230
      * interacting with user media and adds methods to native WebRTC-related
@@ -347,7 +279,7 @@ class RTCUtils extends Listenable {
347 279
                 logger.debug('Available devices: ', availableDevices);
348 280
                 sendDeviceListToAnalytics(availableDevices);
349 281
 
350
-                eventEmitter.emit(
282
+                this.eventEmitter.emit(
351 283
                     RTCEvents.DEVICE_LIST_AVAILABLE,
352 284
                     availableDevices);
353 285
 
@@ -373,12 +305,12 @@ class RTCUtils extends Listenable {
373 305
     enumerateDevices(callback) {
374 306
         navigator.mediaDevices.enumerateDevices()
375 307
             .then(devices => {
376
-                updateKnownDevices(devices);
308
+                this._updateKnownDevices(devices);
377 309
                 callback(devices);
378 310
             })
379 311
             .catch(error => {
380 312
                 logger.warn(`Failed to  enumerate devices. ${error}`);
381
-                updateKnownDevices([]);
313
+                this._updateKnownDevices([]);
382 314
                 callback([]);
383 315
             });
384 316
     }
@@ -407,7 +339,7 @@ class RTCUtils extends Listenable {
407 339
             navigator.mediaDevices.getUserMedia(constraints)
408 340
                 .then(stream => {
409 341
                     logger.log('onUserMediaSuccess');
410
-                    updateGrantedPermissions(umDevices, stream);
342
+                    this._updateGrantedPermissions(umDevices, stream);
411 343
                     if (!timeoutExpired) {
412 344
                         if (typeof gumTimeout !== 'undefined') {
413 345
                             clearTimeout(gumTimeout);
@@ -427,7 +359,7 @@ class RTCUtils extends Listenable {
427 359
                     }
428 360
 
429 361
                     if (jitsiError.name === JitsiTrackErrors.PERMISSION_DENIED) {
430
-                        updateGrantedPermissions(umDevices, undefined);
362
+                        this._updateGrantedPermissions(umDevices, undefined);
431 363
                     }
432 364
 
433 365
                     // else {
@@ -497,6 +429,65 @@ class RTCUtils extends Listenable {
497 429
         return missingDevices;
498 430
     }
499 431
 
432
+    /**
433
+     * Event handler for the 'devicechange' event.
434
+     *
435
+     * @param {MediaDeviceInfo[]} devices - list of media devices.
436
+     * @emits RTCEvents.DEVICE_LIST_CHANGED
437
+     */
438
+    _onMediaDevicesListChanged(devicesReceived) {
439
+        availableDevices = devicesReceived.slice(0);
440
+        logger.info('list of media devices has changed:', availableDevices);
441
+
442
+        sendDeviceListToAnalytics(availableDevices);
443
+
444
+        // Used by tracks to update the real device id before the consumer of lib-jitsi-meet receives the
445
+        // new device list.
446
+        this.eventEmitter.emit(RTCEvents.DEVICE_LIST_WILL_CHANGE, availableDevices);
447
+
448
+        this.eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, availableDevices);
449
+    }
450
+
451
+    /**
452
+     * Update known devices.
453
+     *
454
+     * @param {Array<Object>} pds - The new devices.
455
+     * @returns {void}
456
+     *
457
+     * NOTE: Use this function as a shared callback to handle both the devicechange event and the
458
+     * polling implementations.
459
+     * This prevents duplication and works around a chrome bug (verified to occur on 68) where devicechange
460
+     * fires twice in a row, which can cause async post devicechange processing to collide.
461
+     */
462
+    _updateKnownDevices(pds) {
463
+        if (compareAvailableMediaDevices(pds)) {
464
+            this._onMediaDevicesListChanged(pds);
465
+        }
466
+    }
467
+
468
+    /**
469
+     * Updates the granted permissions based on the options we requested and the
470
+     * streams we received.
471
+     * @param um the options we requested to getUserMedia.
472
+     * @param stream the stream we received from calling getUserMedia.
473
+     */
474
+    _updateGrantedPermissions(um, stream) {
475
+        const audioTracksReceived
476
+            = Boolean(stream) && stream.getAudioTracks().length > 0;
477
+        const videoTracksReceived
478
+            = Boolean(stream) && stream.getVideoTracks().length > 0;
479
+        const grantedPermissions = {};
480
+
481
+        if (um.indexOf('video') !== -1) {
482
+            grantedPermissions.video = videoTracksReceived;
483
+        }
484
+        if (um.indexOf('audio') !== -1) {
485
+            grantedPermissions.audio = audioTracksReceived;
486
+        }
487
+
488
+        this.eventEmitter.emit(RTCEvents.PERMISSIONS_CHANGED, grantedPermissions);
489
+    }
490
+
500 491
     /**
501 492
      * Gets streams from specified device types. This function intentionally
502 493
      * ignores errors for upstream to catch and handle instead.
@@ -792,7 +783,7 @@ class RTCUtils extends Listenable {
792 783
 
793 784
                 logger.log(`Audio output device set to ${deviceId}`);
794 785
 
795
-                eventEmitter.emit(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
786
+                this.eventEmitter.emit(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
796 787
                     deviceId);
797 788
             });
798 789
     }

+ 1
- 1
modules/RTCStats/RTCStats.ts Переглянути файл

@@ -2,7 +2,6 @@ import { getLogger } from '@jitsi/logger';
2 2
 
3 3
 import rtcstatsInit from '@jitsi/rtcstats/rtcstats';
4 4
 import traceInit from '@jitsi/rtcstats/trace-ws';
5
-import EventEmitter from 'events';
6 5
 
7 6
 import {
8 7
     CONFERENCE_JOINED,
@@ -12,6 +11,7 @@ import {
12 11
 import JitsiConference from '../../JitsiConference';
13 12
 import { IRTCStatsConfiguration } from './interfaces';
14 13
 import { RTC_STATS_PC_EVENT, RTC_STATS_WC_DISCONNECTED } from './RTCStatsEvents';
14
+import EventEmitter from '../util/EventEmitter';
15 15
 
16 16
 const logger = getLogger(__filename);
17 17
 

+ 1
- 2
modules/detection/NoAudioSignalDetection.js Переглянути файл

@@ -1,7 +1,6 @@
1
-import EventEmitter from 'events';
2
-
3 1
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
4 2
 import * as JitsiTrackEvents from '../../JitsiTrackEvents';
3
+import EventEmitter from '../util/EventEmitter';
5 4
 
6 5
 import * as DetectionEvents from './DetectionEvents';
7 6
 

+ 1
- 2
modules/detection/TrackVADEmitter.js Переглянути файл

@@ -1,6 +1,5 @@
1
-import EventEmitter from 'events';
2
-
3 1
 import RTC from '../RTC/RTC';
2
+import EventEmitter from '../util/EventEmitter';
4 3
 import { createAudioContext } from '../webaudio/WebAudioUtils';
5 4
 
6 5
 import { VAD_SCORE_PUBLISHED } from './DetectionEvents';

+ 1
- 1
modules/detection/VADAudioAnalyser.js Переглянути файл

@@ -1,7 +1,7 @@
1 1
 import { getLogger } from '@jitsi/logger';
2
-import { EventEmitter } from 'events';
3 2
 
4 3
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
4
+import EventEmitter from '../util/EventEmitter';
5 5
 
6 6
 import { DETECTOR_STATE_CHANGE, VAD_SCORE_PUBLISHED } from './DetectionEvents';
7 7
 import TrackVADEmitter from './TrackVADEmitter';

+ 1
- 2
modules/detection/VADNoiseDetection.js Переглянути файл

@@ -1,5 +1,4 @@
1
-import { EventEmitter } from 'events';
2
-
1
+import EventEmitter from '../util/EventEmitter';
3 2
 import { calculateAverage, filterPositiveValues } from '../util/MathUtil';
4 3
 
5 4
 import { DETECTOR_STATE_CHANGE, VAD_NOISY_DEVICE } from './DetectionEvents';

+ 2
- 1
modules/detection/VADReportingService.js Переглянути файл

@@ -1,5 +1,6 @@
1 1
 import { getLogger } from '@jitsi/logger';
2
-import EventEmitter from 'events';
2
+
3
+import EventEmitter from '../util/EventEmitter';
3 4
 
4 5
 import * as DetectionEvents from './DetectionEvents';
5 6
 import TrackVADEmitter from './TrackVADEmitter';

+ 1
- 2
modules/detection/VADTalkMutedDetection.js Переглянути файл

@@ -1,5 +1,4 @@
1
-import { EventEmitter } from 'events';
2
-
1
+import EventEmitter from '../util/EventEmitter';
3 2
 import { calculateAverage } from '../util/MathUtil';
4 3
 
5 4
 import { DETECTOR_STATE_CHANGE, VAD_TALK_WHILE_MUTED } from './DetectionEvents';

+ 1
- 2
modules/statistics/SpeakerStatsCollector.spec.js Переглянути файл

@@ -1,8 +1,7 @@
1
-import EventEmitter from 'events';
2
-
3 1
 import JitsiConference from '../../JitsiConference';
4 2
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
5 3
 import JitsiParticipant from '../../JitsiParticipant';
4
+import EventEmitter from '../util/EventEmitter';
6 5
 
7 6
 import SpeakerStats from './SpeakerStats';
8 7
 import SpeakerStatsCollector from './SpeakerStatsCollector';

+ 1
- 2
modules/statistics/statistics.js Переглянути файл

@@ -1,11 +1,10 @@
1
-import EventEmitter from 'events';
2
-
3 1
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
4 2
 import { JitsiTrackEvents } from '../../JitsiTrackEvents';
5 3
 import { FEEDBACK } from '../../service/statistics/AnalyticsEvents';
6 4
 import * as StatisticsEvents from '../../service/statistics/Events';
7 5
 import RTCStats from '../RTCStats/RTCStats';
8 6
 import browser from '../browser';
7
+import EventEmitter from '../util/EventEmitter';
9 8
 import WatchRTC from '../watchRTC/WatchRTC';
10 9
 
11 10
 import analytics from './AnalyticsAdapter';

+ 18
- 0
modules/util/EventEmitter.js Переглянути файл

@@ -0,0 +1,18 @@
1
+import { EventEmitter as NodeEventEmitter } from 'events';
2
+
3
+/**
4
+ * The class creates our own EventEmitter instance
5
+ */
6
+export default class EventEmitter extends NodeEventEmitter {
7
+    /**
8
+     * Creates new instance.
9
+     * @constructor
10
+     */
11
+    constructor() {
12
+        super();
13
+
14
+        // aliases for addListener/removeListener
15
+        this.addEventListener = this.addListener;
16
+        this.removeEventListener = this.removeListener;
17
+    }
18
+}

+ 27
- 9
modules/util/Listenable.js Переглянути файл

@@ -1,4 +1,4 @@
1
-import EventEmitter from 'events';
1
+import EventEmitter from './EventEmitter';
2 2
 
3 3
 /**
4 4
  * The class implements basic event operations - add/remove listener.
@@ -8,11 +8,10 @@ import EventEmitter from 'events';
8 8
 export default class Listenable {
9 9
     /**
10 10
      * Creates new instance.
11
-     * @param {EventEmitter} eventEmitter
12 11
      * @constructor
13 12
      */
14
-    constructor(eventEmitter = new EventEmitter()) {
15
-        this.eventEmitter = eventEmitter;
13
+    constructor() {
14
+        this.eventEmitter = new EventEmitter();
16 15
 
17 16
         // aliases for addListener/removeListener
18 17
         this.addEventListener = this.on = this.addListener;
@@ -20,15 +19,25 @@ export default class Listenable {
20 19
     }
21 20
 
22 21
     /**
23
-     * Adds new listener.
22
+     * Adds new cancellable listener.
24 23
      * @param {String} eventName the name of the event
25 24
      * @param {Function} listener the listener.
26 25
      * @returns {Function} - The unsubscribe function.
27 26
      */
28
-    addListener(eventName, listener) {
29
-        this.eventEmitter.addListener(eventName, listener);
27
+    addCancellableListener(eventName, listener) {
28
+        this.addListener(eventName, listener);
29
+
30
+        return () => this.removeListener(eventName, listener);
31
+    }
30 32
 
31
-        return () => this.removeEventListener(eventName, listener);
33
+    /**
34
+     * Adds new listener.
35
+     * @param {String} eventName the name of the event
36
+     * @param {Function} listener the listener.
37
+     * @returns {EventEmitter} - The unsubscribe function.
38
+     */
39
+    addListener(eventName, listener) {
40
+        return this.eventEmitter.addListener(eventName, listener);
32 41
     }
33 42
 
34 43
     /**
@@ -36,8 +45,17 @@ export default class Listenable {
36 45
      * @param {String} eventName the name of the event that triggers the
37 46
      * listener
38 47
      * @param {Function} listener the listener.
48
+     * @returns {EventEmitter} - The unsubscribe function.
39 49
      */
40 50
     removeListener(eventName, listener) {
41
-        this.eventEmitter.removeListener(eventName, listener);
51
+        return this.eventEmitter.removeListener(eventName, listener);
52
+    }
53
+
54
+    /**
55
+     * Emits an event.
56
+     * @param {string} event - event name
57
+     */
58
+    emit(event, ...args) {
59
+        this.eventEmitter.emit(event, ...args);
42 60
     }
43 61
 }

+ 1
- 1
modules/xmpp/ResumeTask.js Переглянути файл

@@ -51,7 +51,7 @@ export default class ResumeTask {
51 51
         this._resumeRetryN += 1;
52 52
 
53 53
         this._networkOnlineListener
54
-            = NetworkInfo.addEventListener(
54
+            = NetworkInfo.addCancellableListener(
55 55
                 NETWORK_INFO_EVENT,
56 56
                 ({ isOnline }) => {
57 57
                     if (isOnline) {

+ 3
- 2
package.json Переглянути файл

@@ -69,7 +69,7 @@
69 69
     "build:webpack": "LIB_JITSI_MEET_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null) webpack",
70 70
     "build:webpack-dev": "webpack --mode development",
71 71
     "build:tsc": "tsc --build --clean && tsc",
72
-    "gen-types": "tsc --declaration --declarationDir types/auto --emitDeclarationOnly",
72
+    "gen-types": "tsc --declaration --emitDeclarationOnly --out index.js",
73 73
     "lint": "eslint .",
74 74
     "lint-fix": "eslint . --fix",
75 75
     "postinstall": "patch-package",
@@ -83,7 +83,8 @@
83 83
   "module": "dist/esm/JitsiMeetJS.js",
84 84
   "files": [
85 85
     "dist",
86
-    "types"
86
+    "types",
87
+    "index.d.ts"
87 88
   ],
88 89
   "license": "Apache-2.0"
89 90
 }

+ 1
- 4
types/hand-crafted/JitsiMediaDevices.d.ts Переглянути файл

@@ -8,10 +8,7 @@ declare class JitsiMediaDevices {
8 8
   isMultipleAudioInputSupported: () => boolean;
9 9
   getAudioOutputDevice: () => string;
10 10
   setAudioOutputDevice: ( deviceId: string ) => Promise<unknown>; // TODO:
11
-  addEventListener: ( event: string, handler: unknown ) => void; // TODO: identify the enum for the event types and the strongly typed handlers
12
-  removeEventListener: ( event: string, handler: unknown ) => void; // TODO: identify the enum for the event types and the strongly typed handlers
13
-  emitEvent: ( event: string, ...args: unknown[] ) => void; // TODO: identify the enum for the event types
14 11
 }
15 12
 
16 13
 declare var _default: JitsiMediaDevices;
17
-export default _default;
14
+export default _default;

Завантаження…
Відмінити
Зберегти