Commit b6b08518 authored by JC Brand's avatar JC Brand

Attempt to restore BOSH session or auto_login before...

triggering connectionInitialized.

That way, when listening for `connectionInitialized`, we'll know when it
fires whether we've attached to a BOSH connection or not.
parent 1ba320ef
...@@ -12,16 +12,19 @@ ...@@ -12,16 +12,19 @@
describe("Authentication", function () { describe("Authentication", function () {
it("needs either a bosh_service_url a websocket_url or both", mock.initConverse((done, _converse) => { it("needs either a bosh_service_url a websocket_url or both", mock.initConverse(async (done, _converse) => {
const url = _converse.bosh_service_url; const url = _converse.bosh_service_url;
const connection = _converse.connection; const connection = _converse.connection;
delete _converse.bosh_service_url; delete _converse.bosh_service_url;
delete _converse.connection; delete _converse.connection;
expect(_converse.initConnection).toThrow( try {
new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.")); await _converse.initConnection();
_converse.bosh_service_url = url; } catch (e) {
_converse.connection = connection; _converse.bosh_service_url = url;
done(); _converse.connection = connection;
expect(e.message).toBe("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.");
done();
}
})); }));
}); });
......
...@@ -521,9 +521,11 @@ function clearSession () { ...@@ -521,9 +521,11 @@ function clearSession () {
} }
_converse.initConnection = function () { /**
/* Creates a new Strophe.Connection instance if we don't already have one. * Creates a new Strophe.Connection instance and if applicable, attempt to
*/ * restore the BOSH session or if `auto_login` is true, attempt to log in.
*/
_converse.initConnection = async function () {
if (!_converse.connection) { if (!_converse.connection) {
if (!_converse.bosh_service_url && ! _converse.websocket_url) { if (!_converse.bosh_service_url && ! _converse.websocket_url) {
throw new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both."); throw new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both.");
...@@ -546,6 +548,11 @@ _converse.initConnection = function () { ...@@ -546,6 +548,11 @@ _converse.initConnection = function () {
throw new Error("initConnection: this browser does not support "+ throw new Error("initConnection: this browser does not support "+
"websockets and bosh_service_url wasn't specified."); "websockets and bosh_service_url wasn't specified.");
} }
if (_converse.auto_login) {
_converse.api.user.login();
} else if (_converse.api.connection.isType('bosh')) {
await _converse.restoreBOSHSession();
}
} }
setUpXMLLogging(); setUpXMLLogging();
/** /**
...@@ -644,15 +651,10 @@ function setUpXMLLogging () { ...@@ -644,15 +651,10 @@ function setUpXMLLogging () {
} }
function finishInitialization () { async function finishInitialization () {
initClientConfig(); initClientConfig();
initPlugins(); initPlugins();
_converse.initConnection(); await _converse.initConnection();
if (_converse.auto_login) {
_converse.api.user.login();
} else if (_converse.api.connection.isType('bosh')) {
_converse.restoreBOSHSession();
}
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
if (!Backbone.history.started) { if (!Backbone.history.started) {
Backbone.history.start(); Backbone.history.start();
......
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