Connect to the websocket server when loading the site
This commit is contained in:
parent
a6b99c2afd
commit
b51f6edcc9
1 changed files with 12 additions and 2 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue