Просмотр исходного кода

Merge pull request #264 from jitsi/handle-conference-left

Fires CONFERENCE_LEFT event once we receive our presence unavailable.
dev1
Paweł Domas 9 лет назад
Родитель
Сommit
84293afeaa
4 измененных файлов: 42 добавлений и 18 удалений
  1. 4
    3
      JitsiConference.js
  2. 2
    0
      JitsiConferenceEventManager.js
  3. 34
    15
      modules/xmpp/ChatRoom.js
  4. 2
    0
      service/xmpp/XMPPEvents.js

+ 4
- 3
JitsiConference.js Просмотреть файл

@@ -147,8 +147,6 @@ JitsiConference.prototype._leaveRoomAndRemoveParticipants = function () {
147 147
     }
148 148
 
149 149
     this.room = null;
150
-
151
-    this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
152 150
 }
153 151
 /**
154 152
  * Leaves the conference.
@@ -721,7 +719,10 @@ JitsiConference.prototype.onMemberLeft = function (jid) {
721 719
         this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
722 720
     }.bind(this));
723 721
 
724
-    this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
722
+    // there can be no participant in case the member that left is focus
723
+    if (participant)
724
+        this.eventEmitter.emit(
725
+            JitsiConferenceEvents.USER_LEFT, id, participant);
725 726
 };
726 727
 
727 728
 JitsiConference.prototype.onUserRoleChanged = function (jid, role) {

+ 2
- 0
JitsiConferenceEventManager.js Просмотреть файл

@@ -240,6 +240,8 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
240 240
         conference.onMemberJoined.bind(conference));
241 241
     chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
242 242
         conference.onMemberLeft.bind(conference));
243
+    this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
244
+        JitsiConferenceEvents.CONFERENCE_LEFT);
243 245
 
244 246
     chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
245 247
         conference.onDisplayNameChanged.bind(conference));

+ 34
- 15
modules/xmpp/ChatRoom.js Просмотреть файл

@@ -173,7 +173,10 @@ ChatRoom.prototype.sendPresence = function (fromJoin) {
173 173
     }
174 174
 };
175 175
 
176
-
176
+/**
177
+ * Sends the presence unavailable, signaling the server
178
+ * we want to leave the room.
179
+ */
177 180
 ChatRoom.prototype.doLeave = function () {
178 181
     logger.log("do leave", this.myroomjid);
179 182
     var pres = $pres({to: this.myroomjid, type: 'unavailable' });
@@ -490,32 +493,44 @@ ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
490 493
             reason = reasonSelect.text();
491 494
         }
492 495
 
493
-        this.leave();
496
+        this._dispose();
494 497
 
495 498
         this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
496
-        delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
499
+        this.connection.emuc.doLeave(this.roomjid);
497 500
         return true;
498 501
     }
499 502
 
500 503
     // Status code 110 indicates that this notification is "self-presence".
501
-    if (!$(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="110"]').length) {
504
+    var isSelfPresence = $(pres).find(
505
+            '>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="110"]'
506
+        ).length !== 0;
507
+    var isKick = $(pres).find(
508
+            '>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]'
509
+        ).length !== 0;
510
+
511
+    if (!isSelfPresence) {
502 512
         delete this.members[from];
503 513
         this.onParticipantLeft(from, false);
504 514
     }
505 515
     // If the status code is 110 this means we're leaving and we would like
506 516
     // to remove everyone else from our view, so we trigger the event.
507
-    else if (Object.keys(this.members).length > 1) {
517
+    else if (Object.keys(this.members).length > 0) {
508 518
         for (var i in this.members) {
509 519
             var member = this.members[i];
510 520
             delete this.members[i];
511 521
             this.onParticipantLeft(i, member.isFocus);
512 522
         }
523
+        this.connection.emuc.doLeave(this.roomjid);
524
+
525
+        // we fire muc_left only if this is not a kick,
526
+        // kick has both statuses 110 and 307.
527
+        if (!isKick)
528
+            this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
513 529
     }
514
-    if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
515
-        if (this.myroomjid === from) {
516
-            this.leave(true);
517
-            this.eventEmitter.emit(XMPPEvents.KICKED);
518
-        }
530
+
531
+    if (isKick && this.myroomjid === from) {
532
+        this._dispose();
533
+        this.eventEmitter.emit(XMPPEvents.KICKED);
519 534
     }
520 535
 };
521 536
 
@@ -946,16 +961,20 @@ ChatRoom.prototype.onMute = function (iq) {
946 961
 
947 962
 /**
948 963
  * Leaves the room. Closes the jingle session.
949
- * @parama voidSendingPresence avoids sending the presence when leaving
950 964
  */
951
-ChatRoom.prototype.leave = function (avoidSendingPresence) {
965
+ChatRoom.prototype.leave = function () {
966
+    this._dispose();
967
+    this.doLeave();
968
+};
969
+
970
+/**
971
+ * Disposes the conference, closes the jingle session.
972
+ */
973
+ChatRoom.prototype._dispose = function () {
952 974
     if (this.session) {
953 975
         this.session.close();
954 976
     }
955 977
     this.eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE);
956
-    if(!avoidSendingPresence)
957
-        this.doLeave();
958
-    this.connection.emuc.doLeave(this.roomjid);
959 978
 };
960 979
 
961 980
 module.exports = ChatRoom;

+ 2
- 0
service/xmpp/XMPPEvents.js Просмотреть файл

@@ -81,6 +81,8 @@ var XMPPEvents = {
81 81
     MUC_MEMBER_JOINED: "xmpp.muc_member_joined",
82 82
     // Designates an event indicating that a participant left the XMPP MUC.
83 83
     MUC_MEMBER_LEFT: "xmpp.muc_member_left",
84
+    // Designates an event indicating that local participant left the muc
85
+    MUC_LEFT: "xmpp.muc_left",
84 86
     // Designates an event indicating that the MUC role of a participant has
85 87
     // changed.
86 88
     MUC_ROLE_CHANGED: "xmpp.muc_role_changed",

Загрузка…
Отмена
Сохранить