diff options
| author | stonedDiscord <Tukz@gmx.de> | 2026-04-06 16:22:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-06 16:22:55 +0200 |
| commit | 815f56add06b92a48b964cb1343f70c86ea36435 (patch) | |
| tree | 99ef56a333dbb419ccadfcaac2cbbc94a8d3df1d /webAO/dom/reconnectButton.ts | |
| parent | 8c8a4a478a233764b7ca31bd39ebfdd2954a2a46 (diff) | |
| parent | 6f407b54c3251b90463bc508852b031d72b0c673 (diff) | |
Merge pull request #298 from AttorneyOnline/reconnect
Add reconnect UI
Diffstat (limited to 'webAO/dom/reconnectButton.ts')
| -rw-r--r-- | webAO/dom/reconnectButton.ts | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/webAO/dom/reconnectButton.ts b/webAO/dom/reconnectButton.ts index 079e7fc..eecb915 100644 --- a/webAO/dom/reconnectButton.ts +++ b/webAO/dom/reconnectButton.ts @@ -1,16 +1,28 @@ -import Client, { client, setClient } from "../client"; +import Client, { client, clientState, setClient } from "../client"; import queryParser from "../utils/queryParser"; -const { ip: serverIP } = queryParser(); +const { ip: serverIP, connect } = queryParser(); /** * Triggered when the reconnect button is pushed. */ export function ReconnectButton() { - client.cleanup(); - setClient(new Client(serverIP)); + document.getElementById("client_errortext")!.textContent = "Reconnecting..."; - if (client) { - document.getElementById("client_error")!.style.display = "none"; + // Build the connection string the same way the initial connection does + let connectionString = connect; + if (!connectionString && serverIP) { + // if connectionString is not set, try IP + // and just guess ws, though it could be wss + connectionString = `ws://${serverIP}`; } + + const hdid = client.hdid; + client.state = clientState.Reconnecting; + client.cleanup(); + + const newClient = new Client(connectionString); + setClient(newClient); + newClient.hdid = hdid; + newClient.connect(); } window.ReconnectButton = ReconnectButton; |
