Commit 9635f53d authored by JC Brand's avatar JC Brand

converse-smacks: 2 bugfixes.

- Don't ever resume SMACKS stream when using BOSH
- Clear SMACKS session data when using BOSH
parent d3692755
...@@ -318,7 +318,7 @@ function addPromise (promise) { ...@@ -318,7 +318,7 @@ function addPromise (promise) {
_converse.promises[promise] = u.getResolveablePromise(); _converse.promises[promise] = u.getResolveablePromise();
} }
function isTestEnv () { _converse.isTestEnv = function () {
return _.get(_converse.connection, 'service') === 'jasmine tests'; return _.get(_converse.connection, 'service') === 'jasmine tests';
} }
...@@ -455,7 +455,7 @@ function clearSession () { ...@@ -455,7 +455,7 @@ function clearSession () {
delete _converse.session; delete _converse.session;
} }
// TODO: Refactor so that we don't clear // TODO: Refactor so that we don't clear
if (!_converse.config.get('trusted') || isTestEnv()) { if (!_converse.config.get('trusted') || _converse.isTestEnv()) {
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
} }
...@@ -1224,7 +1224,7 @@ _converse.initialize = async function (settings, callback) { ...@@ -1224,7 +1224,7 @@ _converse.initialize = async function (settings, callback) {
} }
} else if (reconnecting) { } else if (reconnecting) {
this.autoLogin(); this.autoLogin();
} else if (!isTestEnv() && window.PasswordCredential) { } else if (!_converse.isTestEnv() && window.PasswordCredential) {
const creds = await navigator.credentials.get({'password': true}); const creds = await navigator.credentials.get({'password': true});
if (creds && creds.type == 'password' && u.isValidJID(creds.id)) { if (creds && creds.type == 'password' && u.isValidJID(creds.id)) {
await setUserJID(creds.id); await setUserJID(creds.id);
...@@ -1280,7 +1280,7 @@ _converse.initialize = async function (settings, callback) { ...@@ -1280,7 +1280,7 @@ _converse.initialize = async function (settings, callback) {
this.connection = settings.connection; this.connection = settings.connection;
} }
if (isTestEnv()) { if (_converse.isTestEnv()) {
await finishInitialization(); await finishInitialization();
return _converse; return _converse;
} else if (!_.isUndefined(i18n)) { } else if (!_.isUndefined(i18n)) {
......
...@@ -175,7 +175,8 @@ converse.plugins.add('converse-smacks', { ...@@ -175,7 +175,8 @@ converse.plugins.add('converse-smacks', {
_converse.connection._addSysHandler(_.flow(saveSessionData, promise.resolve), Strophe.NS.SM, 'enabled'); _converse.connection._addSysHandler(_.flow(saveSessionData, promise.resolve), Strophe.NS.SM, 'enabled');
_converse.connection._addSysHandler(_.flow(onFailedStanza, promise.resolve), Strophe.NS.SM, 'failed'); _converse.connection._addSysHandler(_.flow(onFailedStanza, promise.resolve), Strophe.NS.SM, 'failed');
const stanza = u.toStanza(`<enable xmlns="${Strophe.NS.SM}" resume="true"/>`); const resume = (_converse.api.connection.isType('websocket') || _converse.isTestEnv());
const stanza = u.toStanza(`<enable xmlns="${Strophe.NS.SM}" resume="${resume}"/>`);
_converse.api.send(stanza); _converse.api.send(stanza);
_converse.connection.flush(); _converse.connection.flush();
await promise; await promise;
...@@ -193,14 +194,8 @@ converse.plugins.add('converse-smacks', { ...@@ -193,14 +194,8 @@ converse.plugins.add('converse-smacks', {
_converse.connection.addHandler(sendAck, Strophe.NS.SM, 'r'); _converse.connection.addHandler(sendAck, Strophe.NS.SM, 'r');
_converse.connection.addHandler(handleAck, Strophe.NS.SM, 'a'); _converse.connection.addHandler(handleAck, Strophe.NS.SM, 'a');
if (_converse.api.connection.isType('bosh') && if ((_converse.api.connection.isType('websocket') || _converse.isTestEnv()) &&
_converse.connfeedback.get('connection_status') === Strophe.Status.ATTACHED) { _converse.session.get('smacks_stream_id')) {
// No need to continue further when we have an existing BOSH session,
// since our existing session still exists server-side.
return;
}
if (_converse.session.get('smacks_stream_id')) {
await sendResumeStanza(); await sendResumeStanza();
} else { } else {
clearSessionData(); clearSessionData();
......
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