create socketio routes
This commit is contained in:
parent
f1d371c5f2
commit
a5bba9d3a4
@ -1,8 +1,6 @@
|
|||||||
import flask
|
import flask
|
||||||
import os
|
|
||||||
|
|
||||||
from truthseeker.routes import routes_api, routes_ui
|
|
||||||
from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
|
import os
|
||||||
|
|
||||||
class TruthSeekerApp(flask.Flask):
|
class TruthSeekerApp(flask.Flask):
|
||||||
|
|
||||||
@ -34,7 +32,7 @@ class TruthSeekerApp(flask.Flask):
|
|||||||
|
|
||||||
APP = TruthSeekerApp()
|
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_api.routes_api, url_prefix="/api/v1")
|
||||||
APP.register_blueprint(routes_ui.routes_ui, url_prefix="/")
|
APP.register_blueprint(routes_ui.routes_ui, url_prefix="/")
|
||||||
|
19
truthseeker/routes/routes_socketio.py
Normal file
19
truthseeker/routes/routes_socketio.py
Normal 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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user