From 1787205f04c9008a753618839bc8da72708f5cab Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 19 Feb 2021 19:39:01 +0100 Subject: working socket.io messages v2 --- pages/game.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'pages') diff --git a/pages/game.tsx b/pages/game.tsx index 8728674..f49e248 100644 --- a/pages/game.tsx +++ b/pages/game.tsx @@ -1,11 +1,9 @@ import { CSSProperties, Component } from 'react'; -import { io as socket } from 'socket.io-client'; +import { io as socket, Socket } from 'socket.io-client'; import axios from 'axios'; import { userInfo } from '../api/api'; import * as cookies from 'react-cookies'; -var io = socket("http://localhost:2080/api/game/socket/"); - import { NavBar } from '../components/navbar'; import { CenteredPage } from '../components/page'; import { VoerBord } from '../components/voerBord'; @@ -51,15 +49,20 @@ class VoerGame extends Component { constructor(props: VoerGameProps) { super(props); - io.on("connect", () => { + if (typeof document === "undefined") return; + this.io = socket(window.location.origin, { resource: 'api/game/socket/socket.io' }); + + this.io.on("connect", () => { console.log("connect") - io.emit("resign", {"cool": "data"}); + this.io.emit("resign", {"cool": "data"}); }) - io.on("disconnect", () => { + this.io.on("disconnect", () => { console.log("disconnect") }) } + io: Socket; + width = 7; height = 6; @@ -88,7 +91,7 @@ class VoerGame extends Component { token: cookies.load("token"), gameID: "fortnite" }) - io.emit("new_move", { + this.io.emit("new_move", { move: column, token: cookies.load("token"), gameID: "fortnite" -- cgit v1.2.3