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,6 +7,10 @@ import { Option, Callback, AgoraUserInfo, AudioMixingOption, PlayEffectOption, A
7 7
  * Other methods of the RtcEngine object serve for agora native sdk and set up error logging.
8 8
  */
9 9
 declare class RtcEngine {
10
+    /**
11
+     * @ignore eventTypes
12
+     */
13
+    private static readonly _eventTypes;
10 14
     /**
11 15
      * @ignore AG_PREFIX
12 16
      */

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

@@ -192,6 +192,7 @@ class RtcEngine {
192 192
      * @return any
193 193
      */
194 194
     static on(eventType, listener) {
195
+        this._eventTypes.add(`${RtcEngine.AG_PREFIX}${eventType}`);
195 196
         // convert int32 to uint32
196 197
         if ([
197 198
             'joinChannelSuccess',
@@ -329,7 +330,12 @@ class RtcEngine {
329 330
      * @return void
330 331
      */
331 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 339
         return Agora.destroy();
334 340
     }
335 341
     /**
@@ -1460,6 +1466,10 @@ class RtcEngine {
1460 1466
         });
1461 1467
     }
1462 1468
 }
1469
+/**
1470
+ * @ignore eventTypes
1471
+ */
1472
+RtcEngine._eventTypes = new Set();
1463 1473
 /**
1464 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,6 +41,11 @@ const AgoraEventEmitter = new NativeEventEmitter(Agora);
41 41
  */
42 42
 class RtcEngine {
43 43
 
44
+    /**
45
+     * @ignore eventTypes
46
+     */
47
+    private static readonly _eventTypes: Set<string> = new Set<string>();
48
+
44 49
     /**
45 50
      * @ignore AG_PREFIX
46 51
      */ 
@@ -228,6 +233,7 @@ class RtcEngine {
228 233
      * @return any
229 234
      */
230 235
     public static on(eventType: string, listener: (...args: any[]) => any): any {
236
+        this._eventTypes.add(`${RtcEngine.AG_PREFIX}${eventType}`);
231 237
         // convert int32 to uint32
232 238
         if ([
233 239
             'joinChannelSuccess',
@@ -379,7 +385,12 @@ class RtcEngine {
379 385
      * @return void
380 386
      */
381 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 394
         return Agora.destroy();
384 395
     }
385 396