From 9db289df861d3ea5cdc8e48ea9c6e3bd0a8a2821 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sat, 16 May 2015 16:28:23 +0200 Subject: [PATCH] Bugfix. Automatic anonymous login didn't work if keepalive=false. --- converse.js | 72 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/converse.js b/converse.js index 7236e6ed3..7aebbe14a 100644 --- a/converse.js +++ b/converse.js @@ -5517,49 +5517,49 @@ this.setUpXMLLogging(); if (this.keepalive) { + if (!this.jid) { + throw new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user."); + } rid = this.session.get('rid'); sid = this.session.get('sid'); jid = this.session.get('jid'); - if (this.authentication === "prebind") { - if (!this.jid) { - throw new Error("initConnection: when using 'keepalive' with 'prebind, you must supply the JID of the current user."); - } - if (rid && sid && jid && Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(this.jid)) { - this.session.save({rid: rid}); // The RID needs to be increased with each request. - this.connection.attach(jid, sid, rid, this.onConnStatusChanged); - } else if (this.prebind_url) { - this.startNewBOSHSession(); + } + if (this.authentication === PREBIND) { + if (!this.keepalive) { + if (this.jid && this.sid && this.rid) { + this.connection.attach(this.jid, this.sid, this.rid, this.onConnStatusChanged); } else { - delete this.connection; - this.emit('noResumeableSession'); - } - } else { - // Non-prebind case. - if (rid && sid && jid) { - this.session.save({rid: rid}); // The RID needs to be increased with each request. - this.connection.attach(jid, sid, rid, this.onConnStatusChanged); - } else if (this.auto_login) { - if (!this.jid) { - throw new Error("initConnection: If you use auto_login, you also need to provide a jid value"); - } - if (this.authentication === ANONYMOUS) { - this.connection.connect(this.jid, null, this.onConnStatusChanged); - } else if (this.authentication === LOGIN) { - if (!this.password) { - throw new Error("initConnection: If you use auto_login and "+ - "authentication='login' then you also need to provide a password."); - } - this.connection.connect(this.jid, this.password, this.onConnStatusChanged); - } + throw new Error("initConnection: If you use prebind and not keepalive, "+ + "then you MUST supply JID, RID and SID values"); } } - } else if (this.authentication == "prebind") { - // prebind is used without keepalive - if (this.jid && this.sid && this.rid) { - this.connection.attach(this.jid, this.sid, this.rid, this.onConnStatusChanged); + if (rid && sid && jid && Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(this.jid)) { + this.session.save({rid: rid}); // The RID needs to be increased with each request. + this.connection.attach(jid, sid, rid, this.onConnStatusChanged); + } else if (this.prebind_url) { + this.startNewBOSHSession(); } else { - throw new Error("initConnection: If you use prebind and not keepalive, "+ - "then you MUST supply JID, RID and SID values"); + delete this.connection; + this.emit('noResumeableSession'); + } + } else { + // Non-prebind case. + if (this.keepalive && rid && sid && jid) { + this.session.save({rid: rid}); // The RID needs to be increased with each request. + this.connection.attach(jid, sid, rid, this.onConnStatusChanged); + } else if (this.auto_login) { + if (!this.jid) { + throw new Error("initConnection: If you use auto_login, you also need to provide a jid value"); + } + if (this.authentication === ANONYMOUS) { + this.connection.connect(this.jid, null, this.onConnStatusChanged); + } else if (this.authentication === LOGIN) { + if (!this.password) { + throw new Error("initConnection: If you use auto_login and "+ + "authentication='login' then you also need to provide a password."); + } + this.connection.connect(this.jid, this.password, this.onConnStatusChanged); + } } } }