|
@@ -290,7 +290,13 @@ XMPP.prototype.getSessions = function () {
|
290
|
290
|
return this.connection.jingle.sessions;
|
291
|
291
|
};
|
292
|
292
|
|
293
|
|
-XMPP.prototype.disconnect = function () {
|
|
293
|
+/**
|
|
294
|
+ * Disconnects this from the XMPP server (if this is connected).
|
|
295
|
+ *
|
|
296
|
+ * @param ev optionally, the event which triggered the necessity to disconnect
|
|
297
|
+ * from the XMPP server (e.g. beforeunload, unload)
|
|
298
|
+ */
|
|
299
|
+XMPP.prototype.disconnect = function (ev) {
|
294
|
300
|
if (this.disconnectInProgress
|
295
|
301
|
|| !this.connection
|
296
|
302
|
|| !this.connection.connected) {
|
|
@@ -312,8 +318,25 @@ XMPP.prototype.disconnect = function () {
|
312
|
318
|
// once more after disconnect() in order to attempt to have its unavailable
|
313
|
319
|
// presence sent as soon as possible.
|
314
|
320
|
this.connection.flush();
|
|
321
|
+
|
|
322
|
+ if (ev !== null && typeof ev !== 'undefined') {
|
|
323
|
+ var evType = ev.type;
|
|
324
|
+
|
|
325
|
+ if (evType == 'beforeunload' || evType == 'unload') {
|
|
326
|
+ // XXX Whatever we said above, synchronous sending is the best
|
|
327
|
+ // (known) way to properly disconnect from the XMPP server.
|
|
328
|
+ // Consequently, it may be fine to have the source code and comment
|
|
329
|
+ // it in or out depending on whether we want to run with it for some
|
|
330
|
+ // time.
|
|
331
|
+ this.connection.options.sync = true;
|
|
332
|
+ }
|
|
333
|
+ }
|
|
334
|
+
|
315
|
335
|
this.connection.disconnect();
|
316
|
|
- this.connection.flush();
|
|
336
|
+
|
|
337
|
+ if (this.connection.options.sync !== true) {
|
|
338
|
+ this.connection.flush();
|
|
339
|
+ }
|
317
|
340
|
};
|
318
|
341
|
|
319
|
342
|
module.exports = XMPP;
|