@ -93,7 +93,7 @@ def sync(
|
||||
client=client,
|
||||
)
|
||||
|
||||
return ws_connect(kwargs["url"].replace("http", "ws"), additional_headers=kwargs["headers"], close_timeout=None, compression=None, max_size=None) # type: ignore
|
||||
return ws_connect(kwargs["url"].replace("http", "ws"), additional_headers=kwargs["headers"]) # type: ignore
|
||||
|
||||
|
||||
|
||||
@ -179,20 +179,20 @@ class WebSocket:
|
||||
|
||||
"""
|
||||
for message in self.ws:
|
||||
yield {{response_type}}.from_dict(json.loads(message))
|
||||
yield {{response_type}}(**json.loads(message))
|
||||
|
||||
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.to_dict()))
|
||||
self.ws.send(json.dumps(data.model_dump()))
|
||||
|
||||
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.BSON.encode(data.to_dict()))
|
||||
self.ws.send(bson.encode(data.model_dump()))
|
||||
|
||||
def recv(self) -> {{response_type}}:
|
||||
"""Receive data from the websocket."""
|
||||
message = self.ws.recv()
|
||||
return {{response_type}}.from_dict(json.loads(message))
|
||||
return {{response_type}}(**json.loads(message))
|
||||
|
||||
def close(self):
|
||||
"""Close the websocket."""
|
||||
|
Reference in New Issue
Block a user