Question

I want to do a background check, which will be every minute to check the Internet connection. If it interrupted then I show a message and try to reconnect. How do I do this?

Was it helpful?

Solution

Sounds like you want to implement XMPP Ping (XEP-0199).

There is a Strophe plugin for this: https://github.com/strophe/strophejs-plugins/tree/master/ping

You ping the server, and then provide a callback for a successful response and a callback for when an error occurs or when the timeout was reached.

```

connection.ping.ping(
    "serviceJID@server.org",
    success_callback,
    error_callback,
    timeout
);

```

In the error_callback you can determine if timeout was reached and then reconnect to your XMPP server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top