aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom/reconnectButton.ts
blob: ae492fb2dea9c4520fc26352fa9a4e4a798fcdd1 (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
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) {
    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;