Unbuffered.

This commit is contained in:
retoor 2025-01-31 12:49:47 +01:00
parent cc3b896d2c
commit 0a70e80668

View File

@ -115,7 +115,7 @@ class RPCView(BaseView):
raise Exception("Not allowed")
args = data.get("args")
if hasattr(super(),method_name) or not hasattr(self,method_name):
return await self.ws.send_json({"callId":call_id,"data":"Not allowed"})
return await self._send_json({"callId":call_id,"data":"Not allowed"})
method = getattr(self,method_name.replace(".","_"),None)
if not method:
raise Exception("Method not found")
@ -125,9 +125,12 @@ class RPCView(BaseView):
result = dict({"exception":str(ex),"traceback":traceback.format_exc()})
print(result,flush=True)
#dict(error=ex=str(ex),traceback=traceback.format_exc())
await self.ws.send_json({"callId":call_id,"success":True,"data":result})
await self._send_json({"callId":call_id,"success":True,"data":result})
except Exception as ex:
await self.ws.send_json({"callId":call_id,"success":False,"data":str(ex)})
await self._send_json({"callId":call_id,"success":False,"data":str(ex)})
async def _send_json(self,obj):
await self.ws.send_text(json.dumps(obj,default=str))
async def call_ping(self,callId,*args):
return {"pong": args}
@ -147,7 +150,13 @@ class RPCView(BaseView):
async for msg in ws:
print(msg)
if msg.type == web.WSMsgType.TEXT:
try:
await rpc(msg.json())
except Exception as ex:
print(ex,flush=True)
print(traceback.format_exc(),flush=True)
await self.services.socket.delete(ws)
break
elif msg.type == web.WSMsgType.ERROR:
print(f"WebSocket exception {ws.exception()}")
await self.services.socket.delete(ws)