forked from coder-with-a-bushido/simple-signaling-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
34 lines (25 loc) · 928 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask, request
from flask_socketio import SocketIO, emit, join_room
app = Flask(__name__)
app.secret_key = 'random secret key!'
socketio = SocketIO(app, cors_allowed_origins="*")
@socketio.on('join')
def join(message):
username = message['username']
room = message['room']
join_room(room)
print('RoomEvent: {} has joined the room {}\n'.format(username, room))
emit('ready', {username: username}, to=room, skip_sid=request.sid)
@socketio.on('data')
def transfer_data(message):
username = message['username']
room = message['room']
data = message['data']
print('DataEvent: {} has sent the data:\n {}\n'.format(username, data))
emit('data', data, to=room, skip_sid=request.sid)
@socketio.on_error_default
def default_error_handler(e):
print("Error: {}".format(e))
socketio.stop()
if __name__ == '__main__':
socketio.run(app, host="0.0.0.0", port=5004)