conversejs / converse.js

Web-based XMPP/Jabber chat client written in JavaScript
http://conversejs.org
Mozilla Public License 2.0
3.08k stars 771 forks source link

Automatically reconnecting after leaving a room? #2229

Open pkukkon opened 4 years ago

pkukkon commented 4 years ago

Describe the bug We're running a Converse 6.0.0 (headless) + Openfire 4.5.3 combo via http-prebind and a custom UI. Let's assume we join an empty (persistent) chat room via Converse API roughly like this...

converse.api.rooms.get(roomJID, {}, false).join(username);

...and can confirm from Openfire that the user has entered the room. When the chat windows is closed, we leave the room via...

converse.api.rooms.get(roomJID).leave();

...and can once more confirm from Openfire that the room is empty again. The problem is, as soon as the page with Converse is reloaded (or you just go to another browser tab and come back), this seems to trigger Converse to ping the room-name@domain/username (the isJoined method) which logs an error...

Apparently we're no longer connected to MUC

That is certainly correct since we left the room but it also leads Converse to instantly re-join it. Is this a bug or are we just missing something very obvious?

Expected behavior If a room is explicitly left via _converse.ChatRoom.leave, shouldn't local/sessionStorage be adjusted so that Converse no longer pings that room?

Environment (please complete the following information):

--- Want to back this issue? **[Post a bounty on it!](https://app.bountysource.com/issues/93146334-automatically-reconnecting-after-leaving-a-room?utm_campaign=plugin&utm_content=tracker%2F194169&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://app.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F194169&utm_medium=issues&utm_source=github).
licaon-kter commented 4 years ago

Can you test with HEAD? There were a lot of changes...

pkukkon commented 4 years ago

With HEAD (generated via npm run headless) we get an instant crash during initialization (Cannot read property 'plugins' of undefined) but still checking whether this is something in our end rather than Converse.

pkukkon commented 4 years ago

Actually, has building the headless version of Converse somehow changed since 6.0.0? In https://m.conversejs.org/docs/html/builds.html it mentions make dist/converse-headless.js but that is no longer valid for HEAD?

We've compiled the latest headless with make src/headless/dist/converse-headless.min.js but the resulting build seems wrong somehow since even our converse.initialize({ ... }); fails due to converse being undefined.

Edit: Seems like the latest headless wouldn't set window.converse at all?

jcbrand commented 4 years ago

window.converse is set here: https://github.com/conversejs/converse.js/blob/e82d6785c2cc24d347c2044560d428a33a1ac6f6/src/headless/converse-core.js#L1446

That's part of the headless build.

Could it be that it's a race condition whereby you're trying to call window.converse before the headless build has been loaded and parsed?

maqsood1ahmed commented 3 years ago

Hi @jcbrand please help me to do it properly. For now I updated this file src/headless/headless.js

import "./converse-status";      // XEP-0199 XMPP Ping
import "./converse-vcard";       // XEP-0054 VCard-temp
/* END: Removable components */

import { converse } from "./converse-core";
window.converse = converse;  //addition
export default converse;

I am using master repo. and building headless using make src/headless/dist/converse-headless.min.js and than calling inside my React component.