Procházet zdrojové kódy

Merge pull request #182 from jitsi/kick-fix-2

Cleaning resources after leaving (kick)
dev1
hristoterezov před 9 roky
rodič
revize
d2f767de37
3 změnil soubory, kde provedl 39 přidání a 25 odebrání
  1. 29
    22
      JitsiConference.js
  2. 5
    0
      JitsiConferenceEventManager.js
  3. 5
    3
      modules/xmpp/ChatRoom.js

+ 29
- 22
JitsiConference.js Zobrazit soubor

@@ -83,8 +83,6 @@ JitsiConference.prototype._init = function (options) {
83 83
     this.room = this.xmpp.createRoom(this.options.name, this.options.config,
84 84
         this.settings, (this.retries < 4 ? 3 : null));
85 85
 
86
-    this.eventManager.setupChatRoomListeners();
87
-
88 86
     //restore previous presence options
89 87
     if(options.roomState) {
90 88
         this.room.loadState(options.roomState);
@@ -96,7 +94,6 @@ JitsiConference.prototype._init = function (options) {
96 94
         this.eventManager.setupRTCListeners();
97 95
     }
98 96
 
99
-
100 97
     if(!this.statistics) {
101 98
         this.statistics = new Statistics(this.xmpp, {
102 99
             callStatsID: this.options.config.callStatsID,
@@ -106,6 +103,9 @@ JitsiConference.prototype._init = function (options) {
106 103
             roomName: this.options.name
107 104
         });
108 105
     }
106
+
107
+    this.eventManager.setupChatRoomListeners();
108
+
109 109
     // Always add listeners because on reload we are executing leave and the
110 110
     // listeners are removed from statistics module.
111 111
     this.eventManager.setupStatisticsListeners();
@@ -490,6 +490,30 @@ JitsiConference.prototype._fireMuteChangeEvent = function (track) {
490 490
     this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
491 491
 };
492 492
 
493
+/**
494
+ * Clear JitsiLocalTrack properties and listeners.
495
+ * @param track the JitsiLocalTrack object.
496
+ */
497
+JitsiConference.prototype.onTrackRemoved = function (track) {
498
+    track._setSSRC(null);
499
+    track._setConference(null);
500
+    this.rtc.removeLocalTrack(track);
501
+    track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
502
+        track.muteHandler);
503
+    track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
504
+        track.audioLevelHandler);
505
+    this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
506
+        track.ssrcHandler);
507
+
508
+    // send event for stopping screen sharing
509
+    // FIXME: we assume we have only one screen sharing track
510
+    // if we change this we need to fix this check
511
+    if (track.isVideoTrack() && track.videoType === "desktop")
512
+        this.statistics.sendScreenSharingEvent(false);
513
+
514
+    this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
515
+}
516
+
493 517
 /**
494 518
  * Removes JitsiLocalTrack object to the conference.
495 519
  * @param track the JitsiLocalTrack object.
@@ -503,30 +527,13 @@ JitsiConference.prototype.removeTrack = function (track) {
503 527
 
504 528
     if(!this.room){
505 529
         if(this.rtc) {
506
-            this.rtc.removeLocalTrack(track);
507
-            this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
530
+            this.onTrackRemoved(track);
508 531
         }
509 532
         return Promise.resolve();
510 533
     }
511 534
     return new Promise(function (resolve, reject) {
512 535
         this.room.removeStream(track.getOriginalStream(), function(){
513
-            track._setSSRC(null);
514
-            track._setConference(null);
515
-            this.rtc.removeLocalTrack(track);
516
-            track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
517
-                track.muteHandler);
518
-            track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
519
-                track.audioLevelHandler);
520
-            this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
521
-                track.ssrcHandler);
522
-
523
-            // send event for stopping screen sharing
524
-            // FIXME: we assume we have only one screen sharing track
525
-            // if we change this we need to fix this check
526
-            if (track.isVideoTrack() && track.videoType === "desktop")
527
-                this.statistics.sendScreenSharingEvent(false);
528
-
529
-            this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
536
+            this.onTrackRemoved(track);
530 537
             resolve();
531 538
         }.bind(this), function (error) {
532 539
             reject(error);

+ 5
- 0
JitsiConferenceEventManager.js Zobrazit soubor

@@ -193,6 +193,11 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
193 193
 
194 194
     this.chatRoomForwarder.forward(XMPPEvents.KICKED,
195 195
         JitsiConferenceEvents.KICKED);
196
+    chatRoom.addListener(XMPPEvents.KICKED,
197
+        function () {
198
+            conference.room = null;
199
+            conference.leave.bind(conference);
200
+        });
196 201
 
197 202
     chatRoom.addListener(XMPPEvents.MUC_MEMBER_JOINED,
198 203
         conference.onMemberJoined.bind(conference));

+ 5
- 3
modules/xmpp/ChatRoom.js Zobrazit soubor

@@ -495,7 +495,7 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
495 495
     }
496 496
     if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
497 497
         if (this.myroomjid === from) {
498
-            this.leave();
498
+            this.leave(true);
499 499
             this.eventEmitter.emit(XMPPEvents.KICKED);
500 500
         }
501 501
     }
@@ -948,13 +948,15 @@ ChatRoom.prototype.onMute = function (iq) {
948 948
 
949 949
 /**
950 950
  * Leaves the room. Closes the jingle session.
951
+ * @parama voidSendingPresence avoids sending the presence when leaving
951 952
  */
952
-ChatRoom.prototype.leave = function () {
953
+ChatRoom.prototype.leave = function (avoidSendingPresence) {
953 954
     if (this.session) {
954 955
         this.session.close();
955 956
     }
956 957
     this.eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE);
957
-    this.doLeave();
958
+    if(!avoidSendingPresence)
959
+        this.doLeave();
958 960
     this.connection.emuc.doLeave(this.roomjid);
959 961
 };
960 962
 

Načítá se…
Zrušit
Uložit