Explorar el Código

feat: Removes eventEmitter from Moderator.

It creates its own emitter now extending Listenable.
release-8443
damencho hace 2 años
padre
commit
8a1631fd46
Se han modificado 3 ficheros con 44 adiciones y 9 borrados
  1. 21
    3
      modules/util/EventEmitterForwarder.js
  2. 18
    1
      modules/xmpp/ChatRoom.js
  3. 5
    5
      modules/xmpp/moderator.js

+ 21
- 3
modules/util/EventEmitterForwarder.js Ver fichero

@@ -12,6 +12,7 @@ function EventEmitterForwarder(src, dest) {
12 12
     }
13 13
     this.src = src;
14 14
     this.dest = dest;
15
+    this.listeners = new Map();
15 16
 }
16 17
 
17 18
 /**
@@ -30,9 +31,26 @@ EventEmitterForwarder.prototype.forward = function(...args) {
30 31
     args[0] = this.dest;
31 32
 
32 33
     // Using bind.apply to pass the arguments as Array-like object ("arguments")
33
-    this.src.addListener(
34
-        srcEvent,
35
-        Function.prototype.bind.apply(this.dest.emit, args));
34
+    const newListener = Function.prototype.bind.apply(this.dest.emit, args);
35
+
36
+    this.src.addListener(srcEvent, newListener);
37
+    this.listeners.set(srcEvent, newListener);
38
+};
39
+
40
+/**
41
+ * Clears the listeners for the supplied events.
42
+ *
43
+ * @param args all the events which listeners to be cleaned.
44
+ */
45
+EventEmitterForwarder.prototype.removeListeners = function(...args) {
46
+    args.forEach(a => {
47
+        const l = this.listeners.get(a);
48
+
49
+        if (l) {
50
+            this.src.removeListener(a, l);
51
+            this.listeners.delete(a);
52
+        }
53
+    });
36 54
 };
37 55
 
38 56
 module.exports = EventEmitterForwarder;

+ 18
- 1
modules/xmpp/ChatRoom.js Ver fichero

@@ -7,8 +7,10 @@ import { $iq, $msg, $pres, Strophe } from 'strophe.js';
7 7
 import * as JitsiTranscriptionStatus from '../../JitsiTranscriptionStatus';
8 8
 import { MediaType } from '../../service/RTC/MediaType';
9 9
 import { VideoType } from '../../service/RTC/VideoType';
10
+import AuthenticationEvents from '../../service/authentication/AuthenticationEvents';
10 11
 import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
11 12
 import Settings from '../settings/Settings';
13
+import EventEmitterForwarder from '../util/EventEmitterForwarder';
12 14
 import GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
13 15
 import Listenable from '../util/Listenable';
14 16
 
@@ -168,7 +170,15 @@ export default class ChatRoom extends Listenable {
168 170
         this.focusMucJid = null;
169 171
         this.noBridgeAvailable = false;
170 172
         this.options = options || {};
171
-        this.moderator = new Moderator(this.xmpp, this.eventEmitter, xmpp.options);
173
+        this.moderator = new Moderator(this.xmpp, xmpp.options);
174
+
175
+        this.eventsForwarder = new EventEmitterForwarder(this.moderator, this.eventEmitter);
176
+        this.eventsForwarder.forward(AuthenticationEvents.IDENTITY_UPDATED, AuthenticationEvents.IDENTITY_UPDATED);
177
+        this.eventsForwarder.forward(XMPPEvents.REDIRECTED, XMPPEvents.REDIRECTED);
178
+        this.eventsForwarder.forward(XMPPEvents.AUTHENTICATION_REQUIRED, XMPPEvents.AUTHENTICATION_REQUIRED);
179
+        this.eventsForwarder.forward(XMPPEvents.FOCUS_DISCONNECTED, XMPPEvents.FOCUS_DISCONNECTED);
180
+        this.eventsForwarder.forward(XMPPEvents.RESERVATION_ERROR, XMPPEvents.RESERVATION_ERROR);
181
+
172 182
         if (typeof this.options.enableLobby === 'undefined' || this.options.enableLobby) {
173 183
             this.lobby = new Lobby(this);
174 184
         }
@@ -1823,6 +1833,13 @@ export default class ChatRoom extends Listenable {
1823 1833
         this._removeConnListeners.forEach(remove => remove());
1824 1834
         this._removeConnListeners = [];
1825 1835
 
1836
+        this.eventsForwarder.removeListeners(
1837
+            AuthenticationEvents.IDENTITY_UPDATED,
1838
+            XMPPEvents.REDIRECTED,
1839
+            XMPPEvents.AUTHENTICATION_REQUIRED,
1840
+            XMPPEvents.FOCUS_DISCONNECTED,
1841
+            XMPPEvents.RESERVATION_ERROR);
1842
+
1826 1843
         this.joined = false;
1827 1844
         this.inProgressEmitted = false;
1828 1845
     }

+ 5
- 5
modules/xmpp/moderator.js Ver fichero

@@ -5,6 +5,7 @@ import { $iq, Strophe } from 'strophe.js';
5 5
 
6 6
 import FeatureFlags from '../flags/FeatureFlags';
7 7
 import Settings from '../settings/Settings';
8
+import Listenable from '../util/Listenable';
8 9
 
9 10
 const AuthenticationEvents
10 11
     = require('../../service/authentication/AuthenticationEvents');
@@ -41,14 +42,15 @@ function createExpBackoffTimer(step) {
41 42
 /**
42 43
  * The moderator/focus responsible for direct communication with jicofo
43 44
  */
44
-export default class Moderator {
45
+export default class Moderator extends Listenable {
45 46
     /**
46 47
      * Constructs moderator.
47 48
      * @param xmpp The xmpp.
48
-     * @param emitter The emitter.
49 49
      * @param options The options.
50 50
      */
51
-    constructor(xmpp, emitter, options) {
51
+    constructor(xmpp, options) {
52
+        super();
53
+
52 54
         this.getNextTimeout = createExpBackoffTimer(1000);
53 55
         this.getNextErrorTimeout = createExpBackoffTimer(1000);
54 56
         this.options = options;
@@ -60,8 +62,6 @@ export default class Moderator {
60 62
         // availability.
61 63
         this.sipGatewayEnabled = false;
62 64
 
63
-        this.eventEmitter = emitter;
64
-
65 65
         this.connection = xmpp.connection;
66 66
 
67 67
         // The JID to which conference-iq requests are sent over XMPP.

Loading…
Cancelar
Guardar