mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
handle closing ws event
This commit is contained in:
parent
54cb5e1fed
commit
b16359c53e
@ -166,7 +166,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
|
|||||||
self.__stage3_ws_connected.set_passed()
|
self.__stage3_ws_connected.set_passed()
|
||||||
async for event in self.__kvmd_ws.communicate():
|
async for event in self.__kvmd_ws.communicate():
|
||||||
await self.__process_ws_event(event)
|
await self.__process_ws_event(event)
|
||||||
raise RfbError("KVMD closes the websocket (the server may have been stopped)")
|
raise RfbError("KVMD closed the websocket (the server may have been stopped)")
|
||||||
finally:
|
finally:
|
||||||
self.__kvmd_ws = None
|
self.__kvmd_ws = None
|
||||||
|
|
||||||
|
|||||||
@ -153,6 +153,8 @@ class KvmdClientWs:
|
|||||||
msg = receive_task.result()
|
msg = receive_task.result()
|
||||||
if msg.type == aiohttp.WSMsgType.TEXT:
|
if msg.type == aiohttp.WSMsgType.TEXT:
|
||||||
yield json.loads(msg.data)
|
yield json.loads(msg.data)
|
||||||
|
elif msg.type == aiohttp.WSMsgType.CLOSE:
|
||||||
|
await self.__ws.close()
|
||||||
elif msg.type == aiohttp.WSMsgType.CLOSED:
|
elif msg.type == aiohttp.WSMsgType.CLOSED:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -167,6 +169,10 @@ class KvmdClientWs:
|
|||||||
receive_task.cancel()
|
receive_task.cancel()
|
||||||
if writer_task:
|
if writer_task:
|
||||||
writer_task.cancel()
|
writer_task.cancel()
|
||||||
|
try:
|
||||||
|
await self.__ws.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
self.__communicated = False
|
self.__communicated = False
|
||||||
|
|
||||||
async def send_key_event(self, key: str, state: bool) -> None:
|
async def send_key_event(self, key: str, state: bool) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user