browser-go-api/websockets/socket.py

56 lines
1.4 KiB
Python
Raw Normal View History

2019-10-07 23:28:11 +00:00
from app import socketio
from flask_socketio import send, emit, join_room, leave_room
import json
2019-10-07 23:28:11 +00:00
# ! Basic Connection
2019-10-07 23:28:11 +00:00
@socketio.on('connect')
def handle_connection():
print('''
wow, there was a socketio connection!
cool
''')
2019-10-09 07:20:36 +00:00
emit('message', {'data':'connection'}, broadcast=True)
2019-10-07 23:28:11 +00:00
@socketio.on('message')
def handle_message(message):
print(message)
2019-10-09 07:20:36 +00:00
emit('init namespace', {'namespace':'newroom'})
2019-10-08 23:56:28 +00:00
@socketio.on('connect', namespace='/newroom')
def handle_connection():
print('''
look cool a namespaced socketio connection!
2019-10-11 06:06:22 +00:00
''')
# ! Game Room Messages
2019-10-11 06:06:22 +00:00
def join_room_notice(room):
2019-10-12 05:23:38 +00:00
@socketio.on('connect', namespace=f'/{room}')
def room_socket_mount():
print(f'/{room} socket mounted')
2019-10-11 06:06:22 +00:00
@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):
2019-10-11 06:31:27 +00:00
socketio.emit('new game', game, broadcast=True, namespace=f'/{room}')
2019-10-11 06:06:22 +00:00
def new_room_notice(room):
socketio.emit('new room', room, broadcast=True)
def join_game_notice(game_id, user):
@socketio.on('join game')
def return_join_game_notice(data):
game = data['game']
join_room(game)
emit('join game', data, room=f'game')
2019-10-11 06:06:22 +00:00
# @socketio.on
# def room_socket(roomspace):
# pass