This commit is contained in:
yumoqing 2024-04-29 16:11:16 +08:00
parent 8e84ccecce
commit 1a6fbd2423

View File

@ -80,11 +80,18 @@ class XtermProcessor(BaseProcessor):
self.p_obj.close() self.p_obj.close()
async def ws_send(ws:web.WebSocketResponse, data): async def ws_send(ws:web.WebSocketResponse, data):
data = { if not isinstance(data, str):
data = json.dumps(data)
d = {
"type":1, "type":1,
"data":data "data":data
} }
return await ws.send_str(json.dumps(data)) d = json.dumps(d)
try:
return await ws.send_str(d)
except Exception as e:
print('ws.send_str() error:', e)
return False
class WsPool: class WsPool:
def __init__(self, ws, ws_path, app): def __init__(self, ws, ws_path, app):
@ -128,13 +135,9 @@ class WsPool:
async def sendto(self, data, id=None): async def sendto(self, data, id=None):
if id is None: if id is None:
return await ws_send(self.ws, data) return await ws_send(self.ws, data)
try: d = self.get_data()
d = self.get_data() ws = d.get(id)
ws = d.get(id) return await ws_send(ws, data)
return await ws_send(ws, data)
except Exception as e:
print('ws.sendto() error:', e)
return False
class WebsocketProcessor(PythonScriptProcessor): class WebsocketProcessor(PythonScriptProcessor):
@classmethod @classmethod