Skip to content

Commit

Permalink
Set timeout to connecting to server to 5 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
OmniTroid committed Nov 22, 2023
1 parent 0604090 commit b0f6ebd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions webAO/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ class Client extends EventEmitter {
this.serv.addEventListener("close", this.emit.bind(this, "close"));
this.serv.addEventListener("message", this.emit.bind(this, "message"));
this.serv.addEventListener("error", this.emit.bind(this, "error"));

// If the client is still not connected 5 seconds after attempting to join
// It's fair to assume that the server is not reachable
setTimeout(() => {
if (this.state === clientState.NotConnected) {
this.serv.close();
}
}, 5000);
} else {
this.joinServer();
}
Expand Down

0 comments on commit b0f6ebd

Please sign in to comment.