From ca222415b73d0f037f48f5b0605c8ec7999267f3 Mon Sep 17 00:00:00 2001 From: m0cs Date: Fri, 22 Jan 2016 20:06:32 -0300 Subject: [PATCH 1/2] A cleaner reconnect timeout. --- converse.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/converse.js b/converse.js index bd2a2678e..dcaa0cfb4 100755 --- a/converse.js +++ b/converse.js @@ -434,6 +434,7 @@ */ this.send_initial_presence = true; this.msg_counter = 0; + this.reconnectTimeout = undefined; // Module-level functions // ---------------------- @@ -605,7 +606,8 @@ this.reconnect = function (condition) { converse.log('Attempting to reconnect in 5 seconds'); converse.giveFeedback(__('Attempting to reconnect in 5 seconds'), 'error'); - setTimeout(function () { + clearTimeout(converse.reconnectTimeout); + converse.reconnectTimeout = setTimeout(function () { if (converse.authentication !== "prebind") { this.connection.connect( this.connection.jid, @@ -638,6 +640,10 @@ // By default we always want to send out an initial presence stanza. converse.send_initial_presence = true; delete converse.disconnection_cause; + if (!!converse.reconnectTimeout) { + clearTimeout(converse.reconnectTimeout); + delete converse.reconnectTimeout; + } if ((typeof reconnect !== 'undefined') && (reconnect)) { converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached'); converse.onReconnected(); From b645d8fb30ef182451b3093a3e98a66e83b8a2fb Mon Sep 17 00:00:00 2001 From: m0cs Date: Mon, 25 Jan 2016 10:05:45 -0300 Subject: [PATCH 2/2] Added changelog entry. --- docs/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 7af593b48..0336e0501 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -16,6 +16,7 @@ See [include_offline_state](https://conversejs.org/docs/html/configuration.html#include_offline_state) for details. [jcbrand] - A chatroom invite might come from someone not in your roster list. [ben] - #487 Empty the resources array when the resource is null [rlanvin] +- #559 Optimize auto_reconnect function. [m0cs] ## 0.10.0 (2015-11-05)