|
|
@@ -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;
|