aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/game/socket.py16
-rw-r--r--pages/game.tsx17
2 files changed, 18 insertions, 15 deletions
diff --git a/api/game/socket.py b/api/game/socket.py
index fdeac73..55bff0f 100644
--- a/api/game/socket.py
+++ b/api/game/socket.py
@@ -1,12 +1,10 @@
from flask import Blueprint, request, make_response
-from flask_socketio import SocketIO, emit, disconnect, emit
+from flask_socketio import SocketIO, emit, Namespace
from game.voerbak_connector import bord
from db import cursor
import time
import json
-namespace = "/game/socket"
-
class game:
def __init__(self, game_id):
self.game_id = game_id
@@ -21,12 +19,14 @@ class game:
def run(app):
io = SocketIO(app, cors_allowed_origins="*")
- @io.on("new_move", namespace)
- def new_move(data):
- print(data)
+ namespace = "/game/socket/"
+ @io.on("connect", namespace)
+ def connect():
+ print("new connection", namespace)
- @io.on("resign", namespace)
- def resign(data):
+ @io.on("new_move")
+ def connect(data):
+ print("new_move")
print(data)
io.run(app, host="127.0.0.1", port=5000, debug=True)
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"