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

@ -183,15 +183,15 @@ class WebSocket:
def send(self, data:{% for arg in args %}{%if arg.name == "body" %}{{arg.type}}{% endif %}{% endfor %}):
"""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:{% for arg in args %}{%if arg.name == "body" %}{{arg.type}}{% endif %}{% endfor %}):
"""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) -> {{response_type}}:
"""Receive data from the websocket."""
message = self.ws.recv()
message = self.ws.recv(timeout=60)
return {{response_type}}(**json.loads(message))
def close(self):