aboutsummaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-19 19:39:01 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-19 19:39:01 +0100
commit1787205f04c9008a753618839bc8da72708f5cab (patch)
tree7501351f6436910bc210124af45d38a2a10bc0eb /pages
parent5f7ba73f128eddb5c3e4e11dd0025aa1c8d2f385 (diff)
working socket.io messages v2
Diffstat (limited to 'pages')
-rw-r--r--pages/game.tsx17
1 files changed, 10 insertions, 7 deletions
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<VoerGameProps> {
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<VoerGameProps> {
token: cookies.load("token"),
gameID: "fortnite"
})
- io.emit("new_move", {
+ this.io.emit("new_move", {
move: column,
token: cookies.load("token"),
gameID: "fortnite"