mirror of
https://github.com/kodxana/madiator-docker-runpod.git
synced 2024-12-04 23:40:13 +01:00
16 lines
464 B
Python
16 lines
464 B
Python
import json
|
|
|
|
active_websockets = set()
|
|
|
|
def send_websocket_message(message_type, data):
|
|
message = json.dumps({'type': message_type, 'data': data})
|
|
dead_sockets = set()
|
|
for ws in active_websockets:
|
|
try:
|
|
ws.send(message)
|
|
except Exception as e:
|
|
print(f"Error sending WebSocket message: {str(e)}")
|
|
dead_sockets.add(ws)
|
|
|
|
# Remove dead sockets
|
|
active_websockets.difference_update(dead_sockets)
|