master
yumoqing 2024-04-29 16:11:16 +08:00
parent 8e84ccecce
commit 1a6fbd2423
1 changed files with 12 additions and 9 deletions

View File

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