Unbuffered.
This commit is contained in:
parent
cc3b896d2c
commit
0a70e80668
@ -115,7 +115,7 @@ class RPCView(BaseView):
|
|||||||
raise Exception("Not allowed")
|
raise Exception("Not allowed")
|
||||||
args = data.get("args")
|
args = data.get("args")
|
||||||
if hasattr(super(),method_name) or not hasattr(self,method_name):
|
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)
|
method = getattr(self,method_name.replace(".","_"),None)
|
||||||
if not method:
|
if not method:
|
||||||
raise Exception("Method not found")
|
raise Exception("Method not found")
|
||||||
@ -125,9 +125,12 @@ class RPCView(BaseView):
|
|||||||
result = dict({"exception":str(ex),"traceback":traceback.format_exc()})
|
result = dict({"exception":str(ex),"traceback":traceback.format_exc()})
|
||||||
print(result,flush=True)
|
print(result,flush=True)
|
||||||
#dict(error=ex=str(ex),traceback=traceback.format_exc())
|
#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:
|
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):
|
async def call_ping(self,callId,*args):
|
||||||
return {"pong": args}
|
return {"pong": args}
|
||||||
@ -147,7 +150,13 @@ class RPCView(BaseView):
|
|||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
print(msg)
|
print(msg)
|
||||||
if msg.type == web.WSMsgType.TEXT:
|
if msg.type == web.WSMsgType.TEXT:
|
||||||
|
try:
|
||||||
await rpc(msg.json())
|
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:
|
elif msg.type == web.WSMsgType.ERROR:
|
||||||
print(f"WebSocket exception {ws.exception()}")
|
print(f"WebSocket exception {ws.exception()}")
|
||||||
await self.services.socket.delete(ws)
|
await self.services.socket.delete(ws)
|
||||||
|
Loading…
Reference in New Issue
Block a user