From b51f6edcc94fb6f5c141a79e599889f1c9e56ec7 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Tue, 4 Jan 2022 21:32:37 -0700 Subject: [PATCH] Connect to the websocket server when loading the site --- web-svelte/src/main.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web-svelte/src/main.ts b/web-svelte/src/main.ts index 9bba94a..3a9b516 100644 --- a/web-svelte/src/main.ts +++ b/web-svelte/src/main.ts @@ -1,12 +1,22 @@ -import App from './App.svelte' +import App from "./App.svelte"; import io from "socket.io-client"; +import type { IServerInfoResponse } from "common"; let url = "/"; if (import.meta.env.DEV) { url = "http://localhost:3001/"; }; -const socket = io(url); +export const socket = io(url); + +socket.once("res:server.info", (data: IServerInfoResponse) => { + console.table(data); +}); + +socket.on("connect", () => { + console.log("Connected to websocket server. Server info below:"); + socket.emit("req:server.info"); +}); const app = new App({ target: document.getElementById('app')