Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2023-11-29 00:39:14 -08:00
parent bc3d698539
commit faaeb3a472
74 changed files with 496 additions and 1985 deletions

View File

@ -157,15 +157,15 @@ class WebSocket:
def send(self, data: WebSocketRequest):
"""Send data to the websocket."""
self.ws.send(json.dumps(data.model_dump()))
self.ws.send(json.dumps(data.model_dump(mode="json")))
def send_binary(self, data: WebSocketRequest):
"""Send data as bson to the websocket."""
self.ws.send(bson.encode(data.model_dump()))
self.ws.send(bson.encode(data.model_dump(mode="json"))) # type: ignore
def recv(self) -> WebSocketResponse:
"""Receive data from the websocket."""
message = self.ws.recv()
message = self.ws.recv(timeout=60)
return WebSocketResponse(**json.loads(message))
def close(self):