Bladeren bron

Attempts to increase the chances of unavailable presence reaching Prosody (on window unload, for example).

dev1
Lyubomir Marinov 9 jaren geleden
bovenliggende
commit
914ff83d30
2 gewijzigde bestanden met toevoegingen van 30 en 2 verwijderingen
  1. 14
    0
      modules/xmpp/ChatRoom.js
  2. 16
    2
      modules/xmpp/xmpp.js

+ 14
- 0
modules/xmpp/ChatRoom.js Bestand weergeven

@@ -153,7 +153,21 @@ ChatRoom.prototype.doLeave = function () {
153 153
     logger.log("do leave", this.myroomjid);
154 154
     var pres = $pres({to: this.myroomjid, type: 'unavailable' });
155 155
     this.presMap.length = 0;
156
+
157
+    // XXX Strophe is asynchronously sending by default. Unfortunately, that
158
+    // means that there may not be enough time to send the unavailable presence.
159
+    // Switching Strophe to synchronous sending is not much of an option because
160
+    // it may lead to a noticeable delay in navigating away from the current
161
+    // location. As a compromise, we will try to increase the chances of sending
162
+    // the unavailable presence within the short time span that we have upon
163
+    // unloading by invoking flush() on the connection. We flush() once before
164
+    // sending/queuing the unavailable presence in order to attemtp to have the
165
+    // unavailable presence at the top of the send queue. We flush() once more
166
+    // after sending/queuing the unavailable presence in order to attempt to
167
+    // have it sent as soon as possible.
168
+    this.connection.flush();
156 169
     this.connection.send(pres);
170
+    this.connection.flush();
157 171
 };
158 172
 
159 173
 

+ 16
- 2
modules/xmpp/xmpp.js Bestand weergeven

@@ -294,15 +294,29 @@ XMPP.prototype.getSessions = function () {
294 294
 };
295 295
 
296 296
 XMPP.prototype.disconnect = function () {
297
-    if (this.disconnectInProgress || !this.connection || !this.connection.connected)
298
-    {
297
+    if (this.disconnectInProgress
298
+            || !this.connection
299
+            || !this.connection.connected) {
299 300
         this.eventEmitter.emit(JitsiConnectionEvents.WRONG_STATE);
300 301
         return;
301 302
     }
302 303
 
303 304
     this.disconnectInProgress = true;
304 305
 
306
+    // XXX Strophe is asynchronously sending by default. Unfortunately, that
307
+    // means that there may not be enough time to send an unavailable presence
308
+    // or disconnect at all. Switching Strophe to synchronous sending is not
309
+    // much of an option because it may lead to a noticeable delay in navigating
310
+    // away from the current location. As a compromise, we will try to increase
311
+    // the chances of sending an unavailable presence and/or disconecting within
312
+    // the short time span that we have upon unloading by invoking flush() on
313
+    // the connection. We flush() once before disconnect() in order to attemtp
314
+    // to have its unavailable presence at the top of the send queue. We flush()
315
+    // once more after disconnect() in order to attempt to have its unavailable
316
+    // presence sent as soon as possible.
317
+    this.connection.flush();
305 318
     this.connection.disconnect();
319
+    this.connection.flush();
306 320
 };
307 321
 
308 322
 module.exports = XMPP;

Laden…
Annuleren
Opslaan