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.