Connect to the websocket server when loading the site

This commit is contained in:
Oliver-Akins 2022-01-04 21:32:37 -07:00
parent a6b99c2afd
commit b51f6edcc9

View file

@ -1,12 +1,22 @@
import App from './App.svelte' import App from "./App.svelte";
import io from "socket.io-client"; import io from "socket.io-client";
import type { IServerInfoResponse } from "common";
let url = "/"; let url = "/";
if (import.meta.env.DEV) { if (import.meta.env.DEV) {
url = "http://localhost:3001/"; 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({ const app = new App({
target: document.getElementById('app') target: document.getElementById('app')