diff options
author | Maxim Devaev <[email protected]> | 2022-07-19 16:42:46 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-07-19 16:42:46 +0300 |
commit | adf4be9bf7c3b04fde04a6f3e516e48c5ea1a1e6 (patch) | |
tree | d36c60db2a833436937243240cbd6331e987a42a /kvmd/htserver.py | |
parent | b16359c53e5dd62839a9af0fa14bdb9c5f350c75 (diff) |
common event parsing
Diffstat (limited to 'kvmd/htserver.py')
-rw-r--r-- | kvmd/htserver.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/kvmd/htserver.py b/kvmd/htserver.py index 94d2c3ee..3a523b00 100644 --- a/kvmd/htserver.py +++ b/kvmd/htserver.py @@ -208,6 +208,13 @@ async def stream_json_exception(response: StreamResponse, err: Exception) -> Non }, False) +async def send_ws_event(wsr: WebSocketResponse, event_type: str, event: Optional[Dict]) -> None: + await wsr.send_str(json.dumps({ + "event_type": event_type, + "event": event, + })) + + def parse_ws_event(msg: str) -> Tuple[str, Dict]: data = json.loads(msg) if not isinstance(data, dict): @@ -246,10 +253,7 @@ class WsSession: return f"WsSession(id={id(self)}, {self.kwargs})" async def send_event(self, event_type: str, event: Optional[Dict]) -> None: - await self.wsr.send_str(json.dumps({ - "event_type": event_type, - "event": event, - })) + await send_ws_event(self.wsr, event_type, event) class HttpServer: |