Commit c1662c63 authored by JC Brand's avatar JC Brand

Properly disconnect upon "host-unknown" error.

parent 25e570c7
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
- Bugfix. Cancel button shown while registration form is being fetched wasn't working - Bugfix. Cancel button shown while registration form is being fetched wasn't working
properly. [jcbrand] properly. [jcbrand]
- Bugfix. Login form wasn't rendered after logging out (when `auto_reconnect` is `true`). [jcbrand] - Bugfix. Login form wasn't rendered after logging out (when `auto_reconnect` is `true`). [jcbrand]
- Properly disconnect upon "host-unknown" error. [jcbrand]
## 2.0.4 (2016-12-13) ## 2.0.4 (2016-12-13)
- #737: Bugfix. Translations weren't being applied. [jcbrand] - #737: Bugfix. Translations weren't being applied. [jcbrand]
......
...@@ -420,6 +420,7 @@ ...@@ -420,6 +420,7 @@
this.onDisconnected = function (condition) { this.onDisconnected = function (condition) {
if (_.includes([converse.LOGOUT, Strophe.Status.AUTHFAIL], converse.disconnection_cause) || if (_.includes([converse.LOGOUT, Strophe.Status.AUTHFAIL], converse.disconnection_cause) ||
converse.disconnection_reason === "host-unknown" ||
!converse.auto_reconnect) { !converse.auto_reconnect) {
return this.disconnect(); return this.disconnect();
} }
...@@ -435,9 +436,10 @@ ...@@ -435,9 +436,10 @@
return 'reconnecting'; return 'reconnecting';
}; };
this.setDisconnectionCause = function (connection_status) { this.setDisconnectionCause = function (cause, reason, override) {
if (typeof converse.disconnection_cause === "undefined") { if (_.isUndefined(converse.disconnection_cause) || override) {
converse.disconnection_cause = connection_status; converse.disconnection_cause = cause;
converse.disconnection_reason = reason;
} }
}; };
...@@ -447,6 +449,7 @@ ...@@ -447,6 +449,7 @@
// By default we always want to send out an initial presence stanza. // By default we always want to send out an initial presence stanza.
converse.send_initial_presence = true; converse.send_initial_presence = true;
delete converse.disconnection_cause; delete converse.disconnection_cause;
delete converse.disconnection_reason;
if (converse.connection.reconnecting) { if (converse.connection.reconnecting) {
converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached'); converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached');
converse.onConnected(true); converse.onConnected(true);
...@@ -460,7 +463,7 @@ ...@@ -460,7 +463,7 @@
converse.onConnected(); converse.onConnected();
} }
} else if (status === Strophe.Status.DISCONNECTED) { } else if (status === Strophe.Status.DISCONNECTED) {
converse.setDisconnectionCause(status); converse.setDisconnectionCause(status, condition);
converse.onDisconnected(condition); converse.onDisconnected(condition);
} else if (status === Strophe.Status.ERROR) { } else if (status === Strophe.Status.ERROR) {
converse.giveFeedback( converse.giveFeedback(
...@@ -474,11 +477,11 @@ ...@@ -474,11 +477,11 @@
} else if (status === Strophe.Status.AUTHFAIL) { } else if (status === Strophe.Status.AUTHFAIL) {
converse.giveFeedback(__('Authentication failed.'), 'error'); converse.giveFeedback(__('Authentication failed.'), 'error');
converse.connection.disconnect(__('Authentication Failed')); converse.connection.disconnect(__('Authentication Failed'));
converse.disconnection_cause = Strophe.Status.AUTHFAIL; converse.setDisconnectionCause(status, condition, true);
} else if (status === Strophe.Status.CONNFAIL) { } else if (status === Strophe.Status.CONNFAIL) {
converse.setDisconnectionCause(status); converse.setDisconnectionCause(status, condition);
} else if (status === Strophe.Status.DISCONNECTING) { } else if (status === Strophe.Status.DISCONNECTING) {
converse.setDisconnectionCause(status); converse.setDisconnectionCause(status, condition);
if (condition) { if (condition) {
converse.giveFeedback( converse.giveFeedback(
__("Disconnected"), 'warn', __("Disconnected"), 'warn',
...@@ -541,7 +544,7 @@ ...@@ -541,7 +544,7 @@
this.logOut = function () { this.logOut = function () {
converse.chatboxviews.closeAllChatBoxes(); converse.chatboxviews.closeAllChatBoxes();
converse.disconnection_cause = converse.LOGOUT; converse.setDisconnectionCause(converse.LOGOUT, undefined, true);
if (typeof converse.connection !== 'undefined') { if (typeof converse.connection !== 'undefined') {
converse.connection.disconnect(); converse.connection.disconnect();
} }
...@@ -1831,7 +1834,7 @@ ...@@ -1831,7 +1834,7 @@
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.");
} }
converse.disconnection_cause = Strophe.Status.AUTHFAIL; converse.setDisconnectionCause(Strophe.Status.AUTHFAIL, undefined, true);
converse.disconnect(); converse.disconnect();
return; return;
} }
......
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