This commit is contained in:
yumoqing 2025-07-15 23:12:00 +08:00
parent db284d1bb6
commit 3d0a465d4c

View File

@ -19,6 +19,7 @@ class XtermProcessor(PythonScriptProcessor):
async def ws_2_process(self, ws): async def ws_2_process(self, ws):
async for msg in ws: async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT: if msg.type == aiohttp.WSMsgType.TEXT:
debug(f'recv from ws:{msg}')
resize_pattern = '_#_resize_#_' resize_pattern = '_#_resize_#_'
heartbeat_pattern = '_#_heartbeat_#_' heartbeat_pattern = '_#_heartbeat_#_'
if msg.data.startswith(resize_pattern): if msg.data.startswith(resize_pattern):
@ -26,7 +27,7 @@ class XtermProcessor(PythonScriptProcessor):
await self.p_obj.set_terminal_size(row, col) await self.p_obj.set_terminal_size(row, col)
continue continue
if msg.data == heartbeat_pattern: if msg.data == heartbeat_pattern:
await ws_send(ws, heartbeat_pattern) await self.ws_sendstr(ws, heartbeat_pattern)
continue continue
self.p_obj.stdin.write(msg.data) self.p_obj.stdin.write(msg.data)
elif msg.type == aiohttp.WSMsgType.ERROR: elif msg.type == aiohttp.WSMsgType.ERROR:
@ -37,6 +38,7 @@ class XtermProcessor(PythonScriptProcessor):
while self.running: while self.running:
x = await self.p_obj.stdout.read(1024) x = await self.p_obj.stdout.read(1024)
await self.ws_sendstr(ws, x) await self.ws_sendstr(ws, x)
await asyncio.sleep(0)
async def datahandle(self,request): async def datahandle(self,request):
await self.path_call(request) await self.path_call(request)
@ -81,6 +83,8 @@ class XtermProcessor(PythonScriptProcessor):
"type":1, "type":1,
"data":s "data":s
} }
debug(f'{data=}')
await ws.send_str(json.dumps(data, indent=4, ensure_ascii=False)) await ws.send_str(json.dumps(data, indent=4, ensure_ascii=False))
debug(f'{data=} sended')