init room socket

This commit is contained in:
Sorrel Bri 2019-10-10 23:06:22 -07:00
parent e4d7c1ad46
commit 085ae0f682
2 changed files with 27 additions and 2 deletions

View file

@ -4,6 +4,7 @@ from models.GameRoom import GameRoom, rooms_schema, room_schema
from models.Game import Game, games_schema from models.Game import Game, games_schema
from database import db from database import db
from ..decorators import jwt_required from ..decorators import jwt_required
from websockets.socket import new_room_notice, join_room_notice
api_rooms = Blueprint('api_rooms', __name__, url_prefix='/api/rooms') api_rooms = Blueprint('api_rooms', __name__, url_prefix='/api/rooms')
@ -12,6 +13,7 @@ def get_room(room_id):
print(room_id) print(room_id)
games = Game.query.filter_by(game_room=room_id).all() games = Game.query.filter_by(game_room=room_id).all()
response = games_schema.dumps(games) response = games_schema.dumps(games)
join_room_notice(room_id)
return jsonify(response) return jsonify(response)
@api_rooms.route('/', methods=['GET']) @api_rooms.route('/', methods=['GET'])
@ -40,8 +42,8 @@ def post_room():
response = { response = {
'status': 'success', 'status': 'success',
'message': 'Succesfully registered.', 'message': 'Succesfully registered.',
'gameRoom': room.id
} }
new_room_notice(room_schema.dumps(room))
return jsonify(response), 201 return jsonify(response), 201
except Exception as e: except Exception as e:
print(e) print(e)

View file

@ -23,3 +23,26 @@ def handle_connection():
look cool a namespaced socketio connection! look cool a namespaced socketio connection!
''') ''')
def join_room_notice(room):
@socketio.on('connect', namespace=f'/{room}')
def handle_connection():
print(f'joined room at {room}')
emit('join room', {'roomspace': f'{room}'})
@socketio.on('join room', namespace=f'/{room}')
def connect_room(message):
print(f'connected with ${message}')
emit('connected', {'roomspace': f'/{room}'})
def new_game_notice(room, game):
@socketio.on('connect', namespace=f'/{room}')
def emit_game(game):
pass
def new_room_notice(room):
socketio.emit('new room', room, broadcast=True)
# @socketio.on
# def room_socket(roomspace):
# pass