Commit d6bb3f85 authored by JC Brand's avatar JC Brand

Small changes to connection status handler.

* Rename onConnStatusChanged to onConnectStatusChanged
* Provide human readable debug feedback on onConnectStatusChanged
parent f86ef934
...@@ -201,6 +201,19 @@ ...@@ -201,6 +201,19 @@
'online': 1 'online': 1
}; };
var PRETTY_CONNECTION_STATUS = {
0: 'ERROR',
1: 'CONNECTING',
2: 'CONNFAIL',
3: 'AUTHENTICATING',
4: 'AUTHFAIL',
5: 'CONNECTED',
6: 'DISCONNECTED',
7: 'DISCONNECTING',
8: 'ATTACHED',
9: 'REDIRECT'
};
// XEP-0085 Chat states // XEP-0085 Chat states
// http://xmpp.org/extensions/xep-0085.html // http://xmpp.org/extensions/xep-0085.html
var INACTIVE = 'inactive'; var INACTIVE = 'inactive';
...@@ -544,7 +557,7 @@ ...@@ -544,7 +557,7 @@
this.connection.jid, this.connection.jid,
this.connection.pass, this.connection.pass,
function (status, condition) { function (status, condition) {
converse.onConnStatusChanged(status, condition, true); converse.onConnectStatusChanged(status, condition, true);
}, },
this.connection.wait, this.connection.wait,
this.connection.hold, this.connection.hold,
...@@ -564,7 +577,8 @@ ...@@ -564,7 +577,8 @@
view.renderLoginPanel(); view.renderLoginPanel();
}; };
this.onConnStatusChanged = function (status, condition, reconnect) { this.onConnectStatusChanged = function (status, condition, reconnect) {
converse.log("Status changed to: "+PRETTY_CONNECTION_STATUS[status]);
if (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED) { if (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED) {
if ((typeof reconnect !== 'undefined') && (reconnect)) { if ((typeof reconnect !== 'undefined') && (reconnect)) {
converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached'); converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached');
...@@ -579,7 +593,7 @@ ...@@ -579,7 +593,7 @@
} else { } else {
converse.renderLoginPanel(); converse.renderLoginPanel();
} }
} else if (status === Strophe.Status.Error) { } else if (status === Strophe.Status.ERROR) {
converse.giveFeedback(__('Error'), 'error'); converse.giveFeedback(__('Error'), 'error');
} else if (status === Strophe.Status.CONNECTING) { } else if (status === Strophe.Status.CONNECTING) {
converse.giveFeedback(__('Connecting')); converse.giveFeedback(__('Connecting'));
...@@ -5249,7 +5263,7 @@ ...@@ -5249,7 +5263,7 @@
converse.connection.connect( converse.connection.connect(
that.fields.username+'@'+that.domain, that.fields.username+'@'+that.domain,
that.fields.password, that.fields.password,
converse.onConnStatusChanged converse.onConnectStatusChanged
); );
converse.chatboxviews.get('controlbox') converse.chatboxviews.get('controlbox')
.switchTab({target: that.$tabs.find('.current')}) .switchTab({target: that.$tabs.find('.current')})
...@@ -5562,7 +5576,7 @@ ...@@ -5562,7 +5576,7 @@
jid += '/converse.js-' + Math.floor(Math.random()*139749825).toString(); jid += '/converse.js-' + Math.floor(Math.random()*139749825).toString();
} }
} }
converse.connection.connect(jid, password, converse.onConnStatusChanged); converse.connection.connect(jid, password, converse.onConnectStatusChanged);
}, },
remove: function () { remove: function () {
...@@ -5661,7 +5675,7 @@ ...@@ -5661,7 +5675,7 @@
response.jid, response.jid,
response.sid, response.sid,
response.rid, response.rid,
this.onConnStatusChanged this.onConnectStatusChanged
); );
}.bind(this), }.bind(this),
error: function (response) { error: function (response) {
...@@ -5681,11 +5695,11 @@ ...@@ -5681,11 +5695,11 @@
} }
if (rid && sid && jid && Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(this.jid)) { 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.session.save({rid: rid}); // The RID needs to be increased with each request.
return this.connection.attach(jid, sid, rid, this.onConnStatusChanged); return this.connection.attach(jid, sid, rid, this.onConnectStatusChanged);
} }
} else { // Not keepalive } else { // Not keepalive
if (this.jid && this.sid && this.rid) { if (this.jid && this.sid && this.rid) {
return this.connection.attach(this.jid, this.sid, this.rid, this.onConnStatusChanged); return this.connection.attach(this.jid, this.sid, this.rid, this.onConnectStatusChanged);
} else { } else {
throw new Error("initConnection: If you use prebind and not keepalive, "+ throw new Error("initConnection: If you use prebind and not keepalive, "+
"then you MUST supply JID, RID and SID values"); "then you MUST supply JID, RID and SID values");
...@@ -5712,19 +5726,19 @@ ...@@ -5712,19 +5726,19 @@
var rid = tokens.rid, jid = tokens.jid, sid = tokens.sid; var rid = tokens.rid, jid = tokens.jid, sid = tokens.sid;
if (this.keepalive && rid && sid && jid) { if (this.keepalive && rid && sid && jid) {
this.session.save({rid: rid}); // The RID needs to be increased with each request. this.session.save({rid: rid}); // The RID needs to be increased with each request.
this.connection.attach(jid, sid, rid, this.onConnStatusChanged); this.connection.attach(jid, sid, rid, this.onConnectStatusChanged);
} else if (this.auto_login) { } else if (this.auto_login) {
if (!this.jid) { if (!this.jid) {
throw new Error("initConnection: If you use auto_login, you also need to provide a jid value"); throw new Error("initConnection: If you use auto_login, you also need to provide a jid value");
} }
if (this.authentication === ANONYMOUS) { if (this.authentication === ANONYMOUS) {
this.connection.connect(this.jid, null, this.onConnStatusChanged); this.connection.connect(this.jid, null, this.onConnectStatusChanged);
} else if (this.authentication === LOGIN) { } else if (this.authentication === LOGIN) {
if (!this.password) { if (!this.password) {
throw new Error("initConnection: If you use auto_login and "+ throw new Error("initConnection: If you use auto_login and "+
"authentication='login' then you also need to provide a password."); "authentication='login' then you also need to provide a password.");
} }
this.connection.connect(this.jid, this.password, this.onConnStatusChanged); this.connection.connect(this.jid, this.password, this.onConnectStatusChanged);
} }
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment