Skip to content

Commit

Permalink
Merge pull request online-go#2387 from GreenAsJade/go_slooow
Browse files Browse the repository at this point in the history
Go slooow
  • Loading branch information
anoek authored Oct 7, 2023
2 parents 35ecee6 + 6f0933b commit f2d963e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/NetworkStatus/NetworkStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};

Expand Down
9 changes: 9 additions & 0 deletions src/lib/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f2d963e

Please sign in to comment.