Commit d341c6a1 authored by JC Brand's avatar JC Brand

Revert "Use getter to lazily create Strophe.Connection"

This reverts commit 7af73c34.

Doesn't look like the right approach for adding support for XEP-0156.
Work on that will continue in a branch in the meantime.
parent 7af73c34
...@@ -51479,7 +51479,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins ...@@ -51479,7 +51479,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
} }
}); });
_converse.api.waitUntil('chatBoxViewsInitialized').then(_converse.addControlBox).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); Promise.all([_converse.api.waitUntil('connectionInitialized'), _converse.api.waitUntil('chatBoxViewsInitialized')]).then(_converse.addControlBox).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
_converse.on('chatBoxesFetched', () => { _converse.on('chatBoxesFetched', () => {
const controlbox = _converse.chatboxes.get('controlbox') || _converse.addControlBox(); const controlbox = _converse.chatboxes.get('controlbox') || _converse.addControlBox();
...@@ -53126,8 +53126,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_1__["default"].plugins ...@@ -53126,8 +53126,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_1__["default"].plugins
} }
}); });
Promise.all([_converse.api.waitUntil('connectionInitialized'), _converse.api.waitUntil('chatBoxViewsInitialized')]).then(() => {
_converse.api.waitUntil('chatBoxViewsInitialized').then(() => {
_converse.minimized_chats = new _converse.MinimizedChats({ _converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes model: _converse.chatboxes
}); });
...@@ -59689,7 +59688,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins ...@@ -59689,7 +59688,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
_converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this)); _converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this));
_converse.on('rosterContactsFetched', () => { _converse.on('rosterContactsFetched', () => {
_converse.roster.each(c => this.addRosterContact(c, { _converse.roster.each(contact => this.addRosterContact(contact, {
'silent': true 'silent': true
})); }));
...@@ -62537,32 +62536,7 @@ const BOSH_WAIT = 59; ...@@ -62537,32 +62536,7 @@ const BOSH_WAIT = 59;
const _converse = { const _converse = {
'templates': {}, 'templates': {},
'promises': {}, 'promises': {}
get connection() {
/* Creates a new Strophe.Connection instance if we don't already have one.
*/
if (!this._connection) {
if (!this.bosh_service_url && !this.websocket_url) {
throw new Error("connection: you must supply a value for either the bosh_service_url or websocket_url or both.");
}
if (('WebSocket' in window || 'MozWebSocket' in window) && this.websocket_url) {
this._connection = new strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].Connection(this.websocket_url, this.connection_options);
} else if (this.bosh_service_url) {
this._connection = new strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].Connection(this.bosh_service_url, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.assignIn(this.connection_options, {
'keepalive': this.keepalive
}));
} else {
throw new Error("connection: this browser does not support websockets and bosh_service_url wasn't specified.");
}
_converse.emit('connectionInitialized');
}
return this._connection;
}
}; };
_converse.VERSION_NAME = "v4.0.5"; _converse.VERSION_NAME = "v4.0.5";
...@@ -62847,6 +62821,28 @@ function initClientConfig() { ...@@ -62847,6 +62821,28 @@ function initClientConfig() {
_converse.emit('clientConfigInitialized'); _converse.emit('clientConfigInitialized');
} }
_converse.initConnection = function () {
/* Creates a new Strophe.Connection instance if we don't already have one.
*/
if (!_converse.connection) {
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.");
}
if (('WebSocket' in window || 'MozWebSocket' in window) && _converse.websocket_url) {
_converse.connection = new strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].Connection(_converse.websocket_url, _converse.connection_options);
} else if (_converse.bosh_service_url) {
_converse.connection = new strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].Connection(_converse.bosh_service_url, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.assignIn(_converse.connection_options, {
'keepalive': _converse.keepalive
}));
} else {
throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified.");
}
}
_converse.emit('connectionInitialized');
};
function setUpXMLLogging() { function setUpXMLLogging() {
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].log = function (level, msg) { strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].log = function (level, msg) {
_converse.log(msg, level); _converse.log(msg, level);
...@@ -62866,6 +62862,9 @@ function setUpXMLLogging() { ...@@ -62866,6 +62862,9 @@ function setUpXMLLogging() {
function finishInitialization() { function finishInitialization() {
initPlugins(); initPlugins();
initClientConfig(); initClientConfig();
_converse.initConnection();
setUpXMLLogging(); setUpXMLLogging();
_converse.logIn(); _converse.logIn();
...@@ -62881,8 +62880,6 @@ function finishInitialization() { ...@@ -62881,8 +62880,6 @@ function finishInitialization() {
_converse.api.disco.own.features.add(strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].NS.IDLE); _converse.api.disco.own.features.add(strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].NS.IDLE);
}); });
} }
_converse.initialized = true;
} }
function cleanup() { function cleanup() {
...@@ -62903,9 +62900,7 @@ function cleanup() { ...@@ -62903,9 +62900,7 @@ function cleanup() {
delete _converse.controlboxtoggle; delete _converse.controlboxtoggle;
delete _converse.chatboxviews; delete _converse.chatboxviews;
if (_converse._connection) { _converse.connection.reset();
_converse._connection.reset();
}
_converse.stopListening(); _converse.stopListening();
...@@ -62923,7 +62918,7 @@ _converse.initialize = function (settings, callback) { ...@@ -62923,7 +62918,7 @@ _converse.initialize = function (settings, callback) {
_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.each(PROMISES, addPromise); _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.each(PROMISES, addPromise);
if (_converse.initialized) { if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_converse.connection)) {
cleanup(); cleanup();
} }
...@@ -63771,7 +63766,7 @@ _converse.initialize = function (settings, callback) { ...@@ -63771,7 +63766,7 @@ _converse.initialize = function (settings, callback) {
if (settings.connection) { if (settings.connection) {
this._connection = settings.connection; this.connection = settings.connection;
} }
if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_converse.connection) && _converse.connection.service === 'jasmine tests') { if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_converse.connection) && _converse.connection.service === 'jasmine tests') {
...@@ -12,24 +12,20 @@ ...@@ -12,24 +12,20 @@
describe("Authentication", function () { describe("Authentication", function () {
it("needs either a bosh_service_url a websocket_url or both", mock.initConverse(function (_converse) { it("needs either a bosh_service_url a websocket_url or both", mock.initConverse(function (_converse) {
const url = _converse.bosh_service_url; var url = _converse.bosh_service_url;
var connection = _converse.connection;
delete _converse.bosh_service_url; delete _converse.bosh_service_url;
delete _converse._connection; delete _converse.connection;
let err; expect(_converse.initConnection).toThrow(
try { new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both."));
_converse.connection; _converse.bosh_service_url = url;
} catch (e) { _converse.connection = connection;
err = e;
}
expect(_.get(err, 'message'))
.toBe("connection: you must supply a value for either the bosh_service_url or websocket_url or both.");
})); }));
describe("with prebind", function () { describe("with prebind", function () {
it("needs a jid when also using keepalive", mock.initConverse(function (_converse) { it("needs a jid when also using keepalive", mock.initConverse(function (_converse) {
const authentication = _converse.authentication; var authentication = _converse.authentication;
const jid = _converse.jid; var jid = _converse.jid;
delete _converse.jid; delete _converse.jid;
_converse.keepalive = true; _converse.keepalive = true;
_converse.authentication = "prebind"; _converse.authentication = "prebind";
...@@ -37,6 +33,9 @@ ...@@ -37,6 +33,9 @@
new Error( new Error(
"restoreBOSHSession: tried to restore a \"keepalive\" session "+ "restoreBOSHSession: tried to restore a \"keepalive\" session "+
"but we don't have the JID for the user!")); "but we don't have the JID for the user!"));
_converse.authentication= authentication;
_converse.jid = jid;
_converse.keepalive = false;
})); }));
it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (_converse) { it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (_converse) {
...@@ -209,20 +208,30 @@ ...@@ -209,20 +208,30 @@
it("has a method for retrieving the next RID", mock.initConverse(function (_converse) { it("has a method for retrieving the next RID", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
var old_connection = _converse.connection;
_converse.connection._proto.rid = '1234'; _converse.connection._proto.rid = '1234';
_converse.expose_rid_and_sid = false; _converse.expose_rid_and_sid = false;
expect(_converse.api.tokens.get('rid')).toBe(null); expect(_converse.api.tokens.get('rid')).toBe(null);
_converse.expose_rid_and_sid = true; _converse.expose_rid_and_sid = true;
expect(_converse.api.tokens.get('rid')).toBe('1234'); expect(_converse.api.tokens.get('rid')).toBe('1234');
_converse.connection = undefined;
expect(_converse.api.tokens.get('rid')).toBe(null);
// Restore the connection
_converse.connection = old_connection;
})); }));
it("has a method for retrieving the SID", mock.initConverse(function (_converse) { it("has a method for retrieving the SID", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
var old_connection = _converse.connection;
_converse.connection._proto.sid = '1234'; _converse.connection._proto.sid = '1234';
_converse.expose_rid_and_sid = false; _converse.expose_rid_and_sid = false;
expect(_converse.api.tokens.get('sid')).toBe(null); expect(_converse.api.tokens.get('sid')).toBe(null);
_converse.expose_rid_and_sid = true; _converse.expose_rid_and_sid = true;
expect(_converse.api.tokens.get('sid')).toBe('1234'); expect(_converse.api.tokens.get('sid')).toBe('1234');
_converse.connection = undefined;
expect(_converse.api.tokens.get('sid')).toBe(null);
// Restore the connection
_converse.connection = old_connection;
})); }));
}); });
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
it("contains a checkbox to indicate whether the computer is trusted or not", it("contains a checkbox to indicate whether the computer is trusted or not",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: false }, allow_registration: false },
function (done, _converse) { function (done, _converse) {
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
it("checkbox can be set to false by default", it("checkbox can be set to false by default",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
trusted: false, trusted: false,
allow_registration: false }, allow_registration: false },
......
...@@ -9,21 +9,23 @@ ...@@ -9,21 +9,23 @@
it("is not available unless allow_registration=true", it("is not available unless allow_registration=true",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: false }, allow_registration: false },
async function (done, _converse) { function (done, _converse) {
await test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox')); test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'))
test_utils.openControlBox(); .then(function () {
const cbview = _converse.chatboxviews.get('controlbox'); test_utils.openControlBox();
expect(cbview.el.querySelectorAll('a.register-account').length).toBe(0); var cbview = _converse.chatboxviews.get('controlbox');
done(); expect($(cbview.el.querySelector('a.register-account')).length).toBe(0);
done();
});
})); }));
it("can be opened by clicking on the registration tab", it("can be opened by clicking on the registration tab",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { function (done, _converse) {
...@@ -50,7 +52,7 @@ ...@@ -50,7 +52,7 @@
it("allows the user to choose an XMPP provider's domain", it("allows the user to choose an XMPP provider's domain",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { function (done, _converse) {
...@@ -90,7 +92,7 @@ ...@@ -90,7 +92,7 @@
it("will render a registration form as received from the XMPP provider", it("will render a registration form as received from the XMPP provider",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { function (done, _converse) {
...@@ -149,7 +151,7 @@ ...@@ -149,7 +151,7 @@
it("will set form_type to legacy and submit it as legacy", it("will set form_type to legacy and submit it as legacy",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { function (done, _converse) {
...@@ -210,7 +212,7 @@ ...@@ -210,7 +212,7 @@
it("will set form_type to xform and submit it as xform", it("will set form_type to xform and submit it as xform",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
function (done, _converse) { function (done, _converse) {
......
...@@ -598,9 +598,10 @@ converse.plugins.add('converse-controlbox', { ...@@ -598,9 +598,10 @@ converse.plugins.add('converse-controlbox', {
} }
}); });
_converse.api.waitUntil('chatBoxViewsInitialized') Promise.all([
.then(_converse.addControlBox) _converse.api.waitUntil('connectionInitialized'),
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); _converse.api.waitUntil('chatBoxViewsInitialized')
]).then(_converse.addControlBox).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
_converse.on('chatBoxesFetched', () => { _converse.on('chatBoxesFetched', () => {
const controlbox = _converse.chatboxes.get('controlbox') || _converse.addControlBox(); const controlbox = _converse.chatboxes.get('controlbox') || _converse.addControlBox();
......
...@@ -509,8 +509,10 @@ converse.plugins.add('converse-minimize', { ...@@ -509,8 +509,10 @@ converse.plugins.add('converse-minimize', {
} }
}); });
_converse.api.waitUntil('chatBoxViewsInitialized') Promise.all([
.then(() => { _converse.api.waitUntil('connectionInitialized'),
_converse.api.waitUntil('chatBoxViewsInitialized')
]).then(() => {
_converse.minimized_chats = new _converse.MinimizedChats({ _converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes model: _converse.chatboxes
}); });
......
...@@ -782,7 +782,7 @@ converse.plugins.add('converse-rosterview', { ...@@ -782,7 +782,7 @@ converse.plugins.add('converse-rosterview', {
_converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this)); _converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this));
_converse.on('rosterContactsFetched', () => { _converse.on('rosterContactsFetched', () => {
_converse.roster.each(c => this.addRosterContact(c, {'silent': true})); _converse.roster.each((contact) => this.addRosterContact(contact, {'silent': true}));
this.update(); this.update();
this.updateFilter(); this.updateFilter();
this.trigger('rosterContactsFetchedAndProcessed'); this.trigger('rosterContactsFetchedAndProcessed');
......
...@@ -69,29 +69,7 @@ const BOSH_WAIT = 59; ...@@ -69,29 +69,7 @@ const BOSH_WAIT = 59;
*/ */
const _converse = { const _converse = {
'templates': {}, 'templates': {},
'promises': {}, 'promises': {}
get connection () {
/* Creates a new Strophe.Connection instance if we don't already have one.
*/
if (!this._connection) {
if (!this.bosh_service_url && ! this.websocket_url) {
throw new Error("connection: you must supply a value for either the bosh_service_url or websocket_url or both.");
}
if (('WebSocket' in window || 'MozWebSocket' in window) && this.websocket_url) {
this._connection = new Strophe.Connection(this.websocket_url, this.connection_options);
} else if (this.bosh_service_url) {
this._connection = new Strophe.Connection(
this.bosh_service_url,
_.assignIn(this.connection_options, {'keepalive': this.keepalive})
);
} else {
throw new Error("connection: this browser does not support websockets and bosh_service_url wasn't specified.");
}
_converse.emit('connectionInitialized');
}
return this._connection;
}
} }
_converse.VERSION_NAME = "v4.0.5"; _converse.VERSION_NAME = "v4.0.5";
...@@ -395,6 +373,27 @@ function initClientConfig () { ...@@ -395,6 +373,27 @@ function initClientConfig () {
_converse.emit('clientConfigInitialized'); _converse.emit('clientConfigInitialized');
} }
_converse.initConnection = function () {
/* Creates a new Strophe.Connection instance if we don't already have one.
*/
if (!_converse.connection) {
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.");
}
if (('WebSocket' in window || 'MozWebSocket' in window) && _converse.websocket_url) {
_converse.connection = new Strophe.Connection(_converse.websocket_url, _converse.connection_options);
} else if (_converse.bosh_service_url) {
_converse.connection = new Strophe.Connection(
_converse.bosh_service_url,
_.assignIn(_converse.connection_options, {'keepalive': _converse.keepalive})
);
} else {
throw new Error("initConnection: this browser does not support websockets and bosh_service_url wasn't specified.");
}
}
_converse.emit('connectionInitialized');
}
function setUpXMLLogging () { function setUpXMLLogging () {
Strophe.log = function (level, msg) { Strophe.log = function (level, msg) {
...@@ -414,6 +413,7 @@ function setUpXMLLogging () { ...@@ -414,6 +413,7 @@ function setUpXMLLogging () {
function finishInitialization () { function finishInitialization () {
initPlugins(); initPlugins();
initClientConfig(); initClientConfig();
_converse.initConnection();
setUpXMLLogging(); setUpXMLLogging();
_converse.logIn(); _converse.logIn();
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
...@@ -425,7 +425,6 @@ function finishInitialization () { ...@@ -425,7 +425,6 @@ function finishInitialization () {
_converse.api.disco.own.features.add(Strophe.NS.IDLE); _converse.api.disco.own.features.add(Strophe.NS.IDLE);
}); });
} }
_converse.initialized = true;
} }
...@@ -442,9 +441,7 @@ function cleanup () { ...@@ -442,9 +441,7 @@ function cleanup () {
} }
delete _converse.controlboxtoggle; delete _converse.controlboxtoggle;
delete _converse.chatboxviews; delete _converse.chatboxviews;
if (_converse._connection) { _converse.connection.reset();
_converse._connection.reset();
}
_converse.stopListening(); _converse.stopListening();
_converse.tearDown(); _converse.tearDown();
delete _converse.config; delete _converse.config;
...@@ -457,7 +454,7 @@ _converse.initialize = function (settings, callback) { ...@@ -457,7 +454,7 @@ _converse.initialize = function (settings, callback) {
settings = !_.isUndefined(settings) ? settings : {}; settings = !_.isUndefined(settings) ? settings : {};
const init_promise = u.getResolveablePromise(); const init_promise = u.getResolveablePromise();
_.each(PROMISES, addPromise); _.each(PROMISES, addPromise);
if (_converse.initialized) { if (!_.isUndefined(_converse.connection)) {
cleanup(); cleanup();
} }
...@@ -1215,11 +1212,12 @@ _converse.initialize = function (settings, callback) { ...@@ -1215,11 +1212,12 @@ _converse.initialize = function (settings, callback) {
return _converse; return _converse;
}; };
// Initialization // Initialization
// -------------- // --------------
// This is the end of the initialize method. // This is the end of the initialize method.
if (settings.connection) { if (settings.connection) {
this._connection = settings.connection; this.connection = settings.connection;
} }
if (!_.isUndefined(_converse.connection) && if (!_.isUndefined(_converse.connection) &&
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
}; };
utils.openControlBox = function () { utils.openControlBox = function () {
const toggle = document.querySelector(".toggle-controlbox"); var toggle = document.querySelector(".toggle-controlbox");
if (!u.isVisible(document.querySelector("#controlbox"))) { if (!u.isVisible(document.querySelector("#controlbox"))) {
if (!u.isVisible(toggle)) { if (!u.isVisible(toggle)) {
u.removeClass('hidden', toggle); u.removeClass('hidden', toggle);
......
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