-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.py
30 lines (23 loc) · 1.07 KB
/
events.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
from flask import session
from flask_socketio import emit, join_room, leave_room
from .. import socketio
@socketio.on('joined', namespace='/chat')
def joined(message):
"""Sent by clients when they enter a room.
A status message is broadcast to all people in the room."""
room = session.get('room')
join_room(room)
emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=room)
@socketio.on('text', namespace='/chat')
def text(message):
"""Sent by a client when the user entered a new message.
The message is sent to all people in the room."""
room = session.get('room')
emit('message', {'msg': session.get('name') + ':' + message['msg']}, room=room, parentOnly= {message['msg'].startswith('!')})
@socketio.on('left', namespace='/chat')
def left(message):
"""Sent by clients when they leave a room.
A status message is broadcast to all people in the room."""
room = session.get('room')
leave_room(room)
emit('status', {'msg': session.get('name') + ' has left the room.'}, room=room)