Commit fb773d5d authored by JC Brand's avatar JC Brand

smacks: Unregister smack stanza handlers on disconnect

parent ab0521eb
...@@ -187,6 +187,8 @@ async function sendEnableStanza () { ...@@ -187,6 +187,8 @@ async function sendEnableStanza () {
} }
} }
const smacks_handlers = [];
async function enableStreamManagement () { async function enableStreamManagement () {
if (!api.settings.get('enable_smacks')) { if (!api.settings.get('enable_smacks')) {
return; return;
...@@ -194,9 +196,13 @@ async function enableStreamManagement () { ...@@ -194,9 +196,13 @@ async function enableStreamManagement () {
if (!(await isStreamManagementSupported())) { if (!(await isStreamManagementSupported())) {
return; return;
} }
_converse.connection.addHandler(stanzaHandler); const conn = _converse.connection;
_converse.connection.addHandler(sendAck, Strophe.NS.SM, 'r'); while (smacks_handlers.length) {
_converse.connection.addHandler(handleAck, Strophe.NS.SM, 'a'); conn.deleteHandler(smacks_handlers.pop());
}
smacks_handlers.push(conn.addHandler(stanzaHandler));
smacks_handlers.push(conn.addHandler(sendAck, Strophe.NS.SM, 'r'));
smacks_handlers.push(conn.addHandler(handleAck, Strophe.NS.SM, 'a'));
if (_converse.session.get('smacks_stream_id')) { if (_converse.session.get('smacks_stream_id')) {
await sendResumeStanza(); await sendResumeStanza();
} else { } else {
...@@ -237,7 +243,6 @@ function onStanzaSent (stanza) { ...@@ -237,7 +243,6 @@ function onStanzaSent (stanza) {
converse.plugins.add('converse-smacks', { converse.plugins.add('converse-smacks', {
initialize () { initialize () {
// Configuration values for this plugin // Configuration values for this plugin
// ==================================== // ====================================
// Refer to docs/source/configuration.rst for explanations of these // Refer to docs/source/configuration.rst for explanations of these
......
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