fix(plugin): a try catch for webscoket send

This commit is contained in:
BennyKok 2023-12-18 13:23:35 +08:00
parent 5b2cb407c7
commit 0dec0015a5

View File

@ -132,13 +132,18 @@ async def websocket_handler(request):
return ws return ws
async def send(event, data, sid=None): async def send(event, data, sid=None):
try:
if sid: if sid:
ws = sockets.get(sid) ws = sockets.get(sid)
if ws: if ws and not ws.closed: # Check if the WebSocket connection is open and not closing
await ws.send_json({ 'event': event, 'data': data }) await ws.send_json({ 'event': event, 'data': data })
else: else:
for ws in sockets.values(): for ws in sockets.values():
if not ws.closed: # Check if the WebSocket connection is open and not closing
await ws.send_json({ 'event': event, 'data': data }) await ws.send_json({ 'event': event, 'data': data })
except Exception as e:
print(f"Exception: {e}")
traceback.print_exc()
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)