-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_instance.py
More file actions
37 lines (29 loc) · 1002 Bytes
/
Copy pathsocket_instance.py
File metadata and controls
37 lines (29 loc) · 1002 Bytes
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
35
36
37
from flask_socketio import SocketIO, join_room, emit
socketio = SocketIO(cors_allowed_origins="*", async_mode='eventlet')
@socketio.on('connect')
def handle_connect():
socketio.emit('Hello',"hello")
print('✅ Client connected')
@socketio.on('join')
def on_join(data):
empId = data.get('empId')
panelId = data.get('panelId')
if empId:
join_room(empId)
print(f'🚪 User {empId} joined their room')
emit('user_connected', {
'message': f'User {empId} connected.',
'empId': empId
}, room=empId)
if panelId:
room_name = f"panel_{panelId}"
join_room(room_name)
print(f'👥 User {empId} also joined panel room {room_name}')
emit('user_connected_panel', {
'message': f'User {empId} joined panel room.',
'empId': empId,
'panel': panelId
}, room=room_name)
@socketio.on('disconnect')
def handle_disconnect():
print('❌ Client disconnected')