From 49d5f8e6929a28186b81006c02288268d1a0f291 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 11 Sep 2013 22:02:54 -0700 Subject: [PATCH] Handle session resumption --- clientapp/helpers/xmppEventHandlers.js | 4 ++++ clientapp/libraries/stanza.io.js | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js index a8274f8..a7cdb07 100644 --- a/clientapp/helpers/xmppEventHandlers.js +++ b/clientapp/helpers/xmppEventHandlers.js @@ -86,6 +86,10 @@ module.exports = function (client, app) { window.location = '/login'; }); + client.on('stream:management:resumed', function () { + me.connected = true; + }); + client.on('session:started', function (jid) { me.jid = jid; diff --git a/clientapp/libraries/stanza.io.js b/clientapp/libraries/stanza.io.js index e069c51..d164f54 100644 --- a/clientapp/libraries/stanza.io.js +++ b/clientapp/libraries/stanza.io.js @@ -76,6 +76,8 @@ function Client(opts) { this._idPrefix = uuid.v4(); this._idCount = 0; + this.timeoutMonitor = null; + this.negotiatedFeatures = {}; this.featureOrder = [ 'sasl', @@ -407,8 +409,10 @@ Client.prototype.connect = function (opts) { _.extend(self.config, opts || {}); // Default iq timeout of 15 seconds - self.timeoutMonitor = new paddle.Paddle(self.config.timeout || 15); - self.timeoutMonitor.start(); + if (!self.timeoutMonitor) { + self.timeoutMonitor = new paddle.Paddle(self.config.timeout || 15); + self.timeoutMonitor.start(); + } if (self.config.wsURL) { return self.conn.connect(self.config); @@ -426,6 +430,7 @@ Client.prototype.connect = function (opts) { Client.prototype.disconnect = function () { this.timeoutMonitor.stop(); + this.timeoutMonitor = null; if (this.sessionStarted) { this.emit('session:end'); this.releaseGroup('session');