diff options
Diffstat (limited to 'webAO/dom')
| -rw-r--r-- | webAO/dom/disconnectButton.ts | 12 | ||||
| -rw-r--r-- | webAO/dom/reconnectButton.ts | 24 | ||||
| -rw-r--r-- | webAO/dom/window.ts | 3 |
3 files changed, 32 insertions, 7 deletions
diff --git a/webAO/dom/disconnectButton.ts b/webAO/dom/disconnectButton.ts new file mode 100644 index 0000000..35daf16 --- /dev/null +++ b/webAO/dom/disconnectButton.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; + +/** + * Triggered when the disconnect button in settings is pushed. + * Forces a disconnection for testing purposes. + */ +export function DisconnectButton() { + if (client.serv && client.serv.readyState === WebSocket.OPEN) { + client.serv.close(); + } +} +window.DisconnectButton = DisconnectButton; 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; diff --git a/webAO/dom/window.ts b/webAO/dom/window.ts index ee1b121..ba19982 100644 --- a/webAO/dom/window.ts +++ b/webAO/dom/window.ts @@ -29,7 +29,8 @@ declare global { pickEmotion: (emo: number) => void; pickChar: (ccharacter: any) => void; chartable_filter: (_event: any) => void; - ReconnectButton: (_event: any) => void; + ReconnectButton: () => void; + DisconnectButton: () => void; opusCheck: (channel: HTMLAudioElement) => OnErrorEventHandlerNonNull; imgError: (image: any) => void; charError: (image: any) => void; |
