Browse Source

hotfix. fix remove event listener

matrixbirds 4 years ago
parent
commit
4c3bd854bc
4 changed files with 28 additions and 3 deletions
  1. 4
    0
      lib/RtcEngine.native.d.ts
  2. 11
    1
      lib/RtcEngine.native.js
  3. 1
    1
      lib/RtcEngine.native.js.map
  4. 12
    1
      src/RtcEngine.native.ts

+ 4
- 0
lib/RtcEngine.native.d.ts View File

7
  * Other methods of the RtcEngine object serve for agora native sdk and set up error logging.
7
  * Other methods of the RtcEngine object serve for agora native sdk and set up error logging.
8
  */
8
  */
9
 declare class RtcEngine {
9
 declare class RtcEngine {
10
+    /**
11
+     * @ignore eventTypes
12
+     */
13
+    private static readonly _eventTypes;
10
     /**
14
     /**
11
      * @ignore AG_PREFIX
15
      * @ignore AG_PREFIX
12
      */
16
      */

+ 11
- 1
lib/RtcEngine.native.js View File

192
      * @return any
192
      * @return any
193
      */
193
      */
194
     static on(eventType, listener) {
194
     static on(eventType, listener) {
195
+        this._eventTypes.add(`${RtcEngine.AG_PREFIX}${eventType}`);
195
         // convert int32 to uint32
196
         // convert int32 to uint32
196
         if ([
197
         if ([
197
             'joinChannelSuccess',
198
             'joinChannelSuccess',
329
      * @return void
330
      * @return void
330
      */
331
      */
331
     static destroy() {
332
     static destroy() {
332
-        Agora.removeAllListeners();
333
+        if (this._eventTypes.size) {
334
+            for (let eventType of this._eventTypes) {
335
+                AgoraEventEmitter.removeAllListeners(eventType);
336
+            }
337
+            this._eventTypes.clear();
338
+        }
333
         return Agora.destroy();
339
         return Agora.destroy();
334
     }
340
     }
335
     /**
341
     /**
1460
         });
1466
         });
1461
     }
1467
     }
1462
 }
1468
 }
1469
+/**
1470
+ * @ignore eventTypes
1471
+ */
1472
+RtcEngine._eventTypes = new Set();
1463
 /**
1473
 /**
1464
  * @ignore AG_PREFIX
1474
  * @ignore AG_PREFIX
1465
  */
1475
  */

+ 1
- 1
lib/RtcEngine.native.js.map
File diff suppressed because it is too large
View File


+ 12
- 1
src/RtcEngine.native.ts View File

41
  */
41
  */
42
 class RtcEngine {
42
 class RtcEngine {
43
 
43
 
44
+    /**
45
+     * @ignore eventTypes
46
+     */
47
+    private static readonly _eventTypes: Set<string> = new Set<string>();
48
+
44
     /**
49
     /**
45
      * @ignore AG_PREFIX
50
      * @ignore AG_PREFIX
46
      */ 
51
      */ 
228
      * @return any
233
      * @return any
229
      */
234
      */
230
     public static on(eventType: string, listener: (...args: any[]) => any): any {
235
     public static on(eventType: string, listener: (...args: any[]) => any): any {
236
+        this._eventTypes.add(`${RtcEngine.AG_PREFIX}${eventType}`);
231
         // convert int32 to uint32
237
         // convert int32 to uint32
232
         if ([
238
         if ([
233
             'joinChannelSuccess',
239
             'joinChannelSuccess',
379
      * @return void
385
      * @return void
380
      */
386
      */
381
     public static destroy() {
387
     public static destroy() {
382
-        Agora.removeAllListeners();
388
+        if (this._eventTypes.size) {
389
+            for (let eventType of this._eventTypes) {
390
+                AgoraEventEmitter.removeAllListeners(eventType);
391
+            }
392
+            this._eventTypes.clear()
393
+        }
383
         return Agora.destroy();
394
         return Agora.destroy();
384
     }
395
     }
385
 
396