Parcourir la source

fix: Removes listeners when e2eping is stopped.

dev1
Boris Grozev il y a 7 ans
Parent
révision
49757e5163
2 fichiers modifiés avec 43 ajouts et 26 suppressions
  1. 1
    16
      JitsiConference.js
  2. 42
    10
      modules/e2eping/e2eping.js

+ 1
- 16
JitsiConference.js Voir le fichier

@@ -257,7 +257,7 @@ JitsiConference.prototype._init = function(options = {}) {
257 257
     this.rttMonitor = new RttMonitor(config.rttMonitor || {});
258 258
 
259 259
     this.e2eping = new E2ePing(
260
-        this.eventEmitter,
260
+        this,
261 261
         config,
262 262
         (message, to) => {
263 263
             try {
@@ -267,21 +267,6 @@ JitsiConference.prototype._init = function(options = {}) {
267 267
                 logger.warn('Failed to send a ping request or response.');
268 268
             }
269 269
         });
270
-    this.on(
271
-        JitsiConferenceEvents.USER_JOINED,
272
-        (id, participant) => this.e2eping.participantJoined(participant));
273
-    this.on(
274
-        JitsiConferenceEvents.USER_LEFT,
275
-        (id, participant) => this.e2eping.participantLeft(participant));
276
-    this.on(
277
-        JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
278
-        (participant, payload) => {
279
-            this.e2eping.messageReceived(participant, payload);
280
-        });
281
-    this.on(
282
-        JitsiConferenceEvents.DATA_CHANNEL_OPENED,
283
-        this.e2eping.dataChannelOpened);
284
-
285 270
 
286 271
     if (!this.rtc) {
287 272
         this.rtc = new RTC(this, options);

+ 42
- 10
modules/e2eping/e2eping.js Voir le fichier

@@ -3,6 +3,7 @@ import { getLogger } from 'jitsi-meet-logger';
3 3
 import { createE2eRttEvent } from '../../service/statistics/AnalyticsEvents';
4 4
 import * as E2ePingEvents
5 5
     from '../../service/e2eping/E2ePingEvents';
6
+import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
6 7
 import Statistics from '../statistics/statistics';
7 8
 
8 9
 const logger = getLogger(__filename);
@@ -175,12 +176,13 @@ class ParticipantWrapper {
175 176
  */
176 177
 export default class E2ePing {
177 178
     /**
178
-     * @param {EventEmitter} eventEmitter - The object to use to emit events.
179
+     * @param {JitsiConference} conference - The conference.
179 180
      * @param {Function} sendMessage - The function to use to send a message.
180 181
      * @param {Object} options
181 182
      */
182
-    constructor(eventEmitter, options, sendMessage) {
183
-        this.eventEmitter = eventEmitter;
183
+    constructor(conference, options, sendMessage) {
184
+        this.conference = conference;
185
+        this.eventEmitter = conference.eventEmitter;
184 186
         this.sendMessage = sendMessage;
185 187
 
186 188
         // The interval at which pings will be sent (<= 0 disables sending).
@@ -213,6 +215,26 @@ export default class E2ePing {
213 215
             `Initializing e2e ping; pingInterval=${
214 216
                 this.pingIntervalMs}, analyticsInterval=${
215 217
                 this.analyticsIntervalMs}.`);
218
+
219
+        this.participantJoined = this.participantJoined.bind(this);
220
+        conference.on(
221
+            JitsiConferenceEvents.USER_JOINED,
222
+            this.participantJoined);
223
+
224
+        this.participantLeft = this.participantLeft.bind(this);
225
+        conference.on(
226
+            JitsiConferenceEvents.USER_LEFT,
227
+            this.participantLeft);
228
+
229
+        this.messageReceived = this.messageReceived.bind(this);
230
+        conference.on(
231
+            JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
232
+            this.messageReceived);
233
+
234
+        this.dataChannelOpened = this.dataChannelOpened.bind(this);
235
+        conference.on(
236
+            JitsiConferenceEvents.DATA_CHANNEL_OPENED,
237
+            this.dataChannelOpened);
216 238
     }
217 239
 
218 240
     /**
@@ -258,11 +280,10 @@ export default class E2ePing {
258 280
      * Handles a participant joining the conference. Starts to send ping
259 281
      * requests to the participant.
260 282
      *
283
+     * @param {String} id - The ID of the participant.
261 284
      * @param {JitsiParticipant} participant - The participant that joined.
262 285
      */
263
-    participantJoined(participant) {
264
-        const id = participant.getId();
265
-
286
+    participantJoined(id, participant) {
266 287
         if (this.pingIntervalMs <= 0) {
267 288
             return;
268 289
         }
@@ -280,11 +301,9 @@ export default class E2ePing {
280 301
     /**
281 302
      * Handles a participant leaving the conference. Stops sending requests.
282 303
      *
283
-     * @param {JitsiParticipant} participant - The participant that left.
304
+     * @param {String} id - The ID of the participant.
284 305
      */
285
-    participantLeft(participant) {
286
-        const id = participant.getId();
287
-
306
+    participantLeft(id) {
288 307
         if (this.pingIntervalMs <= 0) {
289 308
             return;
290 309
         }
@@ -337,6 +356,19 @@ export default class E2ePing {
337 356
     stop() {
338 357
         logger.info('Stopping e2eping');
339 358
 
359
+        this.conference.off(
360
+            JitsiConferenceEvents.USER_JOINED,
361
+            this.participantJoined);
362
+        this.conference.off(
363
+            JitsiConferenceEvents.USER_LEFT,
364
+            this.participantLeft);
365
+        this.conference.off(
366
+            JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
367
+            this.messageReceived);
368
+        this.conference.off(
369
+            JitsiConferenceEvents.DATA_CHANNEL_OPENED,
370
+            this.dataChannelOpened);
371
+
340 372
         for (const id in this.participants) {
341 373
             if (this.participants.hasOwnProperty(id)) {
342 374
                 this.participants[id].clearIntervals();

Chargement…
Annuler
Enregistrer