xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.19k stars 372 forks source link

status goes offline immediately after connecting status #835

Closed 4RGUS closed 4 years ago

4RGUS commented 4 years ago

I am using the library on react-native to create a chat demo application

Platform: "react-native": "0.61.5", "@xmpp/client": "0.11.1" macOS

My code:

const xmpp = client({
  service: "wss://*****:5443/ws",
  domain: "*****",
  username: "username",
  password: "password",
});

When I start the server with : xmpp.start().catch(console.error);

I track the status and it says: connecting

Then I get a console log error: offline

when I listen using:

xmpp.on("offline", () => {
      console.log("offline");
    });

after this I get warnings :

YellowBox.js:71 Possible Unhandled Promise Rejection (id: 0):
Error: Connection is closing
Error: Connection is closing
    at http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:188389:20
    at tryCallTwo (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3253:7)
    at doResolve (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3417:15)
    at new Promise (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3276:5)
    at Client.write (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:188387:16)
    at Client.send$ (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:188359:55)
    at tryCatch (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:29245:19)
    at Generator.invoke [as _invoke] (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:29421:24)
    at Generator.prototype.<computed> [as next] (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:29288:23)
    at tryCatch (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:29245:19)

I checked the same configuration with WebSocket and it worked fine

4RGUS commented 4 years ago

Nevermind. It was my mistake I was using the following piece of code:

xmpp.on("stanza", async (stanza) => {
      if (stanza.is("message")) {
        await xmpp.send(xml("presence", { type: "unavailable" }));
        await xmpp.stop();
      }
    });

the xmpp.stop() made the connection to go offline.