aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom/reconnectButton.ts
blob: eecb915f55a3cea5fb7e177bcb2f9f993d9c34e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Client, { client, clientState, setClient } from "../client";
import queryParser from "../utils/queryParser";
const { ip: serverIP, connect } = queryParser();

/**
 * Triggered when the reconnect button is pushed.
 */
export function ReconnectButton() {
  document.getElementById("client_errortext")!.textContent = "Reconnecting...";

  // 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;