create socketio routes

This commit is contained in:
Thomas Rubini 2023-01-03 16:01:33 +01:00
parent f1d371c5f2
commit a5bba9d3a4
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 21 additions and 4 deletions

View File

@ -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="/")

View File

@ -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)