Sfoglia il codice sorgente

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

Fires CONFERENCE_LEFT event once we receive our presence unavailable.
dev1
Paweł Domas 9 anni fa
parent
commit
84293afeaa

+ 4
- 3
JitsiConference.js Vedi File

147
     }
147
     }
148
 
148
 
149
     this.room = null;
149
     this.room = null;
150
-
151
-    this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
152
 }
150
 }
153
 /**
151
 /**
154
  * Leaves the conference.
152
  * Leaves the conference.
721
         this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
719
         this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
722
     }.bind(this));
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
 JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
728
 JitsiConference.prototype.onUserRoleChanged = function (jid, role) {

+ 2
- 0
JitsiConferenceEventManager.js Vedi File

240
         conference.onMemberJoined.bind(conference));
240
         conference.onMemberJoined.bind(conference));
241
     chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
241
     chatRoom.addListener(XMPPEvents.MUC_MEMBER_LEFT,
242
         conference.onMemberLeft.bind(conference));
242
         conference.onMemberLeft.bind(conference));
243
+    this.chatRoomForwarder.forward(XMPPEvents.MUC_LEFT,
244
+        JitsiConferenceEvents.CONFERENCE_LEFT);
243
 
245
 
244
     chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
246
     chatRoom.addListener(XMPPEvents.DISPLAY_NAME_CHANGED,
245
         conference.onDisplayNameChanged.bind(conference));
247
         conference.onDisplayNameChanged.bind(conference));

+ 34
- 15
modules/xmpp/ChatRoom.js Vedi File

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
 ChatRoom.prototype.doLeave = function () {
180
 ChatRoom.prototype.doLeave = function () {
178
     logger.log("do leave", this.myroomjid);
181
     logger.log("do leave", this.myroomjid);
179
     var pres = $pres({to: this.myroomjid, type: 'unavailable' });
182
     var pres = $pres({to: this.myroomjid, type: 'unavailable' });
490
             reason = reasonSelect.text();
493
             reason = reasonSelect.text();
491
         }
494
         }
492
 
495
 
493
-        this.leave();
496
+        this._dispose();
494
 
497
 
495
         this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
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
         return true;
500
         return true;
498
     }
501
     }
499
 
502
 
500
     // Status code 110 indicates that this notification is "self-presence".
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
         delete this.members[from];
512
         delete this.members[from];
503
         this.onParticipantLeft(from, false);
513
         this.onParticipantLeft(from, false);
504
     }
514
     }
505
     // If the status code is 110 this means we're leaving and we would like
515
     // If the status code is 110 this means we're leaving and we would like
506
     // to remove everyone else from our view, so we trigger the event.
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
         for (var i in this.members) {
518
         for (var i in this.members) {
509
             var member = this.members[i];
519
             var member = this.members[i];
510
             delete this.members[i];
520
             delete this.members[i];
511
             this.onParticipantLeft(i, member.isFocus);
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
 
961
 
947
 /**
962
 /**
948
  * Leaves the room. Closes the jingle session.
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
     if (this.session) {
974
     if (this.session) {
953
         this.session.close();
975
         this.session.close();
954
     }
976
     }
955
     this.eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE);
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
 module.exports = ChatRoom;
980
 module.exports = ChatRoom;

+ 2
- 0
service/xmpp/XMPPEvents.js Vedi File

81
     MUC_MEMBER_JOINED: "xmpp.muc_member_joined",
81
     MUC_MEMBER_JOINED: "xmpp.muc_member_joined",
82
     // Designates an event indicating that a participant left the XMPP MUC.
82
     // Designates an event indicating that a participant left the XMPP MUC.
83
     MUC_MEMBER_LEFT: "xmpp.muc_member_left",
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
     // Designates an event indicating that the MUC role of a participant has
86
     // Designates an event indicating that the MUC role of a participant has
85
     // changed.
87
     // changed.
86
     MUC_ROLE_CHANGED: "xmpp.muc_role_changed",
88
     MUC_ROLE_CHANGED: "xmpp.muc_role_changed",

Loading…
Annulla
Salva