Pārlūkot izejas kodu

fix(JitsiConference.leave): Promise and logic

dev1
hristoterezov 9 gadus atpakaļ
vecāks
revīzija
9075fcfc43

+ 20
- 34
JitsiConference.js Parādīt failu

140
     return this.room && this.room.joined;
140
     return this.room && this.room.joined;
141
 };
141
 };
142
 
142
 
143
-/**
144
- * Leaves the conference and calls onMemberLeft for every participant.
145
- */
146
-JitsiConference.prototype._leaveRoomAndRemoveParticipants = function () {
147
-    // remove all participants
148
-    this.getParticipants().forEach(function (participant) {
149
-        this.onMemberLeft(participant.getJid());
150
-    }.bind(this));
151
-
152
-    // leave the conference
153
-    if (this.room) {
154
-        this.room.leave();
155
-    }
156
-
157
-    this.room = null;
158
-};
159
-
160
 /**
143
 /**
161
  * Leaves the conference.
144
  * Leaves the conference.
162
  * @returns {Promise}
145
  * @returns {Promise}
163
  */
146
  */
164
 JitsiConference.prototype.leave = function () {
147
 JitsiConference.prototype.leave = function () {
165
-    var conference = this;
166
-
167
     if (this.participantConnectionStatus) {
148
     if (this.participantConnectionStatus) {
168
         this.participantConnectionStatus.dispose();
149
         this.participantConnectionStatus.dispose();
169
         this.participantConnectionStatus = null;
150
         this.participantConnectionStatus = null;
170
     }
151
     }
171
 
152
 
172
-    this.statistics.stopCallStats();
153
+    this.getLocalTracks().forEach(track => this.onTrackRemoved(track));
154
+
173
     this.rtc.closeAllDataChannels();
155
     this.rtc.closeAllDataChannels();
156
+    if(this.statistics)
157
+        this.statistics.dispose();
174
 
158
 
175
-    return Promise.all(
176
-        conference.getLocalTracks().map(function (track) {
177
-            return conference.removeTrack(track);
178
-        })
179
-    ).then(this._leaveRoomAndRemoveParticipants.bind(this))
180
-    .catch(function (error) {
181
-        logger.error(error);
182
-        GlobalOnErrorHandler.callUnhandledRejectionHandler(
183
-            {promise: this, reason: error});
184
-        // We are proceeding with leaving the conference because room.leave may
185
-        // succeed.
186
-        this._leaveRoomAndRemoveParticipants();
187
-        return Promise.resolve();
188
-    }.bind(this));
159
+    // leave the conference
160
+    if (this.room) {
161
+        let room = this.room;
162
+        this.room = null;
163
+        return room.leave().catch(() => {
164
+            // remove all participants because currently the conference won't
165
+            // be usable anyway. This is done on success automatically by the
166
+            // ChatRoom instance.
167
+            this.getParticipants().forEach(
168
+                participant => this.onMemberLeft(participant.getJid()));
169
+        });
170
+    }
171
+
172
+    // If this.room == null we are calling second time leave().
173
+    return Promise.reject(
174
+        new Error("The conference is has been already left"));
189
 };
175
 };
190
 
176
 
191
 /**
177
 /**

+ 0
- 5
JitsiConferenceEventManager.js Parādīt failu

406
     });
406
     });
407
 
407
 
408
     if(conference.statistics) {
408
     if(conference.statistics) {
409
-        chatRoom.addListener(XMPPEvents.DISPOSE_CONFERENCE,
410
-            function () {
411
-                conference.statistics.dispose();
412
-            });
413
-
414
         chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
409
         chatRoom.addListener(XMPPEvents.CONNECTION_ICE_FAILED,
415
             function (pc) {
410
             function (pc) {
416
                 conference.statistics.sendIceConnectionFailedEvent(pc);
411
                 conference.statistics.sendIceConnectionFailedEvent(pc);

+ 1
- 0
modules/statistics/statistics.js Parādīt failu

216
 };
216
 };
217
 
217
 
218
 Statistics.prototype.dispose = function () {
218
 Statistics.prototype.dispose = function () {
219
+    this.stopCallStats();
219
     this.stopRemoteStats();
220
     this.stopRemoteStats();
220
     if(this.eventEmitter)
221
     if(this.eventEmitter)
221
         this.eventEmitter.removeAllListeners();
222
         this.eventEmitter.removeAllListeners();

+ 20
- 2
modules/xmpp/ChatRoom.js Parādīt failu

958
 
958
 
959
 /**
959
 /**
960
  * Leaves the room. Closes the jingle session.
960
  * Leaves the room. Closes the jingle session.
961
+ * @returns {Promise} which is resolved if XMPPEvents.MUC_LEFT is received less
962
+ * than 5s after sending presence unavailable. Otherwise the promise is
963
+ * rejected.
961
  */
964
  */
962
 ChatRoom.prototype.leave = function () {
965
 ChatRoom.prototype.leave = function () {
963
     this._dispose();
966
     this._dispose();
964
-    this.doLeave();
967
+    return new Promise((resolve, reject) => {
968
+        let timeout = setTimeout(() => onMucLeft(true), 5000);
969
+        let eventEmitter = this.eventEmitter;
970
+        function onMucLeft(doReject = false) {
971
+            eventEmitter.removeListener(XMPPEvents.MUC_LEFT, onMucLeft);
972
+            clearTimeout(timeout);
973
+            if(doReject) {
974
+                // the timeout expired
975
+                reject(new Error("The timeout for the confirmation about " +
976
+                    "leaving the room expired."));
977
+            } else {
978
+                resolve();
979
+            }
980
+        }
981
+        eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
982
+        this.doLeave();
983
+    });
965
 };
984
 };
966
 
985
 
967
 /**
986
 /**
971
     if (this.session) {
990
     if (this.session) {
972
         this.session.close();
991
         this.session.close();
973
     }
992
     }
974
-    this.eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE);
975
 };
993
 };
976
 
994
 
977
 module.exports = ChatRoom;
995
 module.exports = ChatRoom;

+ 0
- 1
service/xmpp/XMPPEvents.js Parādīt failu

43
     // Designates an event indicating that the display name of a participant
43
     // Designates an event indicating that the display name of a participant
44
     // has changed.
44
     // has changed.
45
     DISPLAY_NAME_CHANGED: "xmpp.display_name_changed",
45
     DISPLAY_NAME_CHANGED: "xmpp.display_name_changed",
46
-    DISPOSE_CONFERENCE: "xmpp.dispose_conference",
47
     ETHERPAD: "xmpp.etherpad",
46
     ETHERPAD: "xmpp.etherpad",
48
     FOCUS_DISCONNECTED: 'xmpp.focus_disconnected',
47
     FOCUS_DISCONNECTED: 'xmpp.focus_disconnected',
49
     FOCUS_LEFT: "xmpp.focus_left",
48
     FOCUS_LEFT: "xmpp.focus_left",

Notiek ielāde…
Atcelt
Saglabāt