diff --git a/src/components/NetworkStatus/NetworkStatus.tsx b/src/components/NetworkStatus/NetworkStatus.tsx index 17068547e4..1c31c6fdcb 100644 --- a/src/components/NetworkStatus/NetworkStatus.tsx +++ b/src/components/NetworkStatus/NetworkStatus.tsx @@ -41,9 +41,10 @@ export function NetworkStatus(): JSX.Element { }; const timeout = () => { setState("timeout"); + console.log("Network status timeout: ", socket.options.timeout_delay); }; const disconnected = (code: number) => { - // Note that when the socket comes up again, a fresh `latency` will clear this + // When the socket comes up again, a fresh `latency` will clear this setState(code === 1001 ? "went-away" : "disconnected"); }; diff --git a/src/lib/sockets.ts b/src/lib/sockets.ts index 0c4a8d62a3..825c367d7d 100644 --- a/src/lib/sockets.ts +++ b/src/lib/sockets.ts @@ -29,6 +29,9 @@ socket.options.timeout_delay = 8000; const MIN_PING_INTERVAL = 3000; // blitz players would really like to know ASAP... const MIN_TIMEOUT_DELAY = 1000; +const MAX_PING_INTERVAL = 15000; +const MAX_TIMEOUT_DELAY = 14000; + export let ai_host; if ( window.location.hostname.indexOf("dev.beta") >= 0 && @@ -109,6 +112,12 @@ socket.on("latency", (latency, drift) => { */ }); +// If we timed out, maybe their internet just went slow... +socket.on("timeout", () => { + socket.options.ping_interval = Math.min(socket.options.ping_interval * 2, MAX_PING_INTERVAL); + socket.options.timeout_delay = Math.min(socket.options.timeout_delay * 2, MAX_TIMEOUT_DELAY); +}); + /* Returns the time in ms since the last time a connection was established to * the server. * (Zero if we've never connected)