UI: Improve UX of Remote API setting page (#1870)

Co-authored-by: David Walker <d0sboots@gmail.com>
This commit is contained in:
catloversg
2025-01-13 01:58:24 +07:00
committed by GitHub
parent fdb325bf66
commit 0e8dca85e1
3 changed files with 102 additions and 60 deletions
+12 -5
View File
@@ -3,6 +3,10 @@ import { RFARequestHandler } from "./MessageHandlers";
import { SnackbarEvents } from "../ui/React/Snackbar";
import { ToastVariant } from "@enums";
function showErrorMessage(address: string, detail: string) {
SnackbarEvents.emit(`Error with websocket ${address}, details: ${detail}`, ToastVariant.ERROR, 5000);
}
export class Remote {
connection?: WebSocket;
static protocol = "ws";
@@ -20,11 +24,14 @@ export class Remote {
public startConnection(): void {
const address = Remote.protocol + "://" + this.ipaddr + ":" + this.port;
this.connection = new WebSocket(address);
this.connection.addEventListener("error", (e: Event) =>
SnackbarEvents.emit(`Error with websocket ${address}, details: ${JSON.stringify(e)}`, ToastVariant.ERROR, 5000),
);
try {
this.connection = new WebSocket(address);
} catch (error) {
console.error(error);
showErrorMessage(address, String(error));
return;
}
this.connection.addEventListener("error", (e: Event) => showErrorMessage(address, JSON.stringify(e)));
this.connection.addEventListener("message", handleMessageEvent);
this.connection.addEventListener("open", () =>
SnackbarEvents.emit(