diff --git a/lib/client.js b/lib/client.js index 8b0eaaf..565bb8c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -69,6 +69,7 @@ export default class Client extends EventTarget { this.disconnect(); this.autoReconnect = autoReconnect; + console.log("Connecting to " + this.params.url); this.setStatus(Client.Status.CONNECTING); try { @@ -98,11 +99,20 @@ export default class Client extends EventTarget { this.isupport = new Map(); if (this.autoReconnect) { - console.info("Reconnecting to server in " + RECONNECT_DELAY_SEC + " seconds"); - clearTimeout(this.reconnectTimeoutID); - this.reconnectTimeoutID = setTimeout(() => { - this.reconnect(); - }, RECONNECT_DELAY_SEC * 1000); + if (!navigator.onLine) { + console.info("Waiting for network to go back online"); + const handleOnline = () => { + window.removeEventListener("online", handleOnline); + this.reconnect(); + }; + window.addEventListener("online", handleOnline); + } else { + console.info("Reconnecting to server in " + RECONNECT_DELAY_SEC + " seconds"); + clearTimeout(this.reconnectTimeoutID); + this.reconnectTimeoutID = setTimeout(() => { + this.reconnect(); + }, RECONNECT_DELAY_SEC * 1000); + } } });