diff options
-rw-r--r-- | api/game/socket.py | 26 | ||||
-rw-r--r-- | api/main.py | 6 |
2 files changed, 24 insertions, 8 deletions
diff --git a/api/game/socket.py b/api/game/socket.py index 7931ada..c4e5ac7 100644 --- a/api/game/socket.py +++ b/api/game/socket.py @@ -1,12 +1,30 @@ from flask import Blueprint, request, make_response -from flask_socketio import SocketIO, emit, disconnect, Namespace -from main import socketio +from flask_socketio import SocketIO, emit, disconnect, Namespace, emit import time import json class GameSocketNamespace(Namespace): def connect(self): - print("connection") + print("new connection") + emit("gert", {"gert": "banaan"}) -socketio.on_namespace(GameSocketNamespace("/game/socket")) + def on_connect(self): + print("new connection") + emit("gert", {"gert": "banaan"}) + + def on_disconnect(self): + print("disconnect") + + def new_move(self, data): + print("new_move") + print(data) + + def resign(self, data): + print("resign") + print(data) + +def run(app): + socketio = SocketIO(app) + socketio.on_namespace(GameSocketNamespace("/game/socket")) + socketio.run(app, host="127.0.0.1", port=5000, debug=True) diff --git a/api/main.py b/api/main.py index afa9871..5588138 100644 --- a/api/main.py +++ b/api/main.py @@ -2,7 +2,6 @@ from flask import Flask from flask_socketio import SocketIO app = Flask(__name__) -socketio = SocketIO(app) from status import status from user.info import info @@ -10,7 +9,7 @@ from auth.signup import signup from auth.login import login from auth.login_token import token from game.new import new_game -import game.socket +from game.socket import run app.register_blueprint(status, url_prefix='/') app.register_blueprint(info, url_prefix='/user') @@ -19,5 +18,4 @@ app.register_blueprint(login, url_prefix='/auth') app.register_blueprint(token, url_prefix='/auth') app.register_blueprint(new_game, url_prefix='/game') -if __name__ == "__main__": - socketio.run(app, host="127.0.0.1", port=5000, debug=True) +if __name__ == "__main__": run(app) |