diff --git a/truthseeker/__init__.py b/truthseeker/__init__.py index 6e8411b..14cbd3a 100644 --- a/truthseeker/__init__.py +++ b/truthseeker/__init__.py @@ -1,8 +1,6 @@ import flask -import os - -from truthseeker.routes import routes_api, routes_ui from flask_socketio import SocketIO +import os class TruthSeekerApp(flask.Flask): @@ -34,7 +32,7 @@ class TruthSeekerApp(flask.Flask): APP = TruthSeekerApp() -from truthseeker.routes import routes_api, routes_ui +from truthseeker.routes import routes_api, routes_ui, routes_socketio APP.register_blueprint(routes_api.routes_api, url_prefix="/api/v1") APP.register_blueprint(routes_ui.routes_ui, url_prefix="/") diff --git a/truthseeker/routes/routes_socketio.py b/truthseeker/routes/routes_socketio.py new file mode 100644 index 0000000..d94816e --- /dev/null +++ b/truthseeker/routes/routes_socketio.py @@ -0,0 +1,19 @@ +from flask_socketio import join_room +import socketio + +from truthseeker import APP +from truthseeker.logic import game_logic + +@APP.socketio_app.on('connect') +def connect(auth): + if not (auth and "game_id" in auth): + raise socketio.exceptions.ConnectionRefusedError("Invalid connection data passed") + + game = game_logic.get_game(auth["game_id"]) + if not game: + raise socketio.exceptions.ConnectionRefusedError("No game with this ID") + + room = join_room("game."+auth["game_id"]) + join_room(room) + +