Commit f0a45456 authored by JC Brand's avatar JC Brand

converse-core: Properly disconnect if reconnection attempt fails.

parent 2a81d2e6
...@@ -399,25 +399,28 @@ ...@@ -399,25 +399,28 @@
converse.logIn(null, true); converse.logIn(null, true);
}, 1000); }, 1000);
this.disconnect = function () {
delete converse.connection.reconnecting;
converse._tearDown();
converse.chatboxviews.closeAllChatBoxes();
converse.emit('disconnected');
converse.log('DISCONNECTED');
return 'disconnected';
};
this.onDisconnected = function (condition) { this.onDisconnected = function (condition) {
if (converse.disconnection_cause !== converse.LOGOUT && converse.auto_reconnect) { if (converse.disconnection_cause !== converse.LOGOUT && converse.auto_reconnect) {
if (converse.disconnection_cause === Strophe.Status.CONNFAIL) { if (converse.disconnection_cause === Strophe.Status.CONNFAIL) {
converse.reconnect(condition); converse.reconnect(condition);
converse.log('RECONNECTING'); converse.log('RECONNECTING');
} else if (converse.disconnection_cause === Strophe.Status.DISCONNECTING || } else if (converse.disconnection_cause === Strophe.Status.DISCONNECTED) {
converse.disconnection_cause === Strophe.Status.DISCONNECTED) {
window.setTimeout(_.partial(converse.reconnect, condition), 3000); window.setTimeout(_.partial(converse.reconnect, condition), 3000);
converse.log('RECONNECTING IN 3 SECONDS'); converse.log('RECONNECTING IN 3 SECONDS');
} }
converse.emit('reconnecting'); converse.emit('reconnecting');
return 'reconnecting'; return 'reconnecting';
} }
delete converse.connection.reconnecting; return this.disconnect();
converse._tearDown();
converse.chatboxviews.closeAllChatBoxes();
converse.emit('disconnected');
converse.log('DISCONNECTED');
return 'disconnected';
}; };
this.setDisconnectionCause = function (connection_status) { this.setDisconnectionCause = function (connection_status) {
...@@ -447,12 +450,6 @@ ...@@ -447,12 +450,6 @@
} else if (status === Strophe.Status.DISCONNECTED) { } else if (status === Strophe.Status.DISCONNECTED) {
converse.setDisconnectionCause(status); converse.setDisconnectionCause(status);
converse.onDisconnected(condition); converse.onDisconnected(condition);
if (status === Strophe.Status.DISCONNECTING && condition) {
converse.giveFeedback(
__("Disconnected"), 'warn',
__("The connection to the chat server has dropped")
);
}
} else if (status === Strophe.Status.ERROR) { } else if (status === Strophe.Status.ERROR) {
converse.giveFeedback( converse.giveFeedback(
__('Connection error'), 'error', __('Connection error'), 'error',
...@@ -470,6 +467,12 @@ ...@@ -470,6 +467,12 @@
converse.setDisconnectionCause(status); converse.setDisconnectionCause(status);
} else if (status === Strophe.Status.DISCONNECTING) { } else if (status === Strophe.Status.DISCONNECTING) {
converse.setDisconnectionCause(status); converse.setDisconnectionCause(status);
if (condition) {
converse.giveFeedback(
__("Disconnected"), 'warn',
__("The connection to the chat server has dropped")
);
}
} }
}; };
...@@ -1817,7 +1820,7 @@ ...@@ -1817,7 +1820,7 @@
"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.disconnection_cause = Strophe.Status.AUTHFAIL;
converse.onDisconnected(); converse.disconnect();
converse.giveFeedback(''); // Wipe the feedback converse.giveFeedback(''); // Wipe the feedback
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