88from typing import TYPE_CHECKING , Any , Dict , Optional , cast
99
1010from typing_extensions import Final , Self
11- from websockets import client as websocket_client
11+ from websockets .asyncio import client as websocket_client
12+ from websockets .protocol import State
1213
1314from xrpl .asyncio .clients .client import Client
1415from xrpl .asyncio .clients .exceptions import XRPLWebsocketException
@@ -65,7 +66,7 @@ def __init__(self: Self, url: str) -> None:
6566 url: The URL of the rippled node to submit requests to.
6667 """
6768 self ._open_requests : _REQUESTS_TYPE = {}
68- self ._websocket : Optional [websocket_client .WebSocketClientProtocol ] = None
69+ self ._websocket : Optional [websocket_client .ClientConnection ] = None
6970 self ._handler_task : Optional [_HANDLER_TYPE ] = None
7071 # unfortunately, we cannot create the Queue here because it needs to be
7172 # tied to a currently-running event loop. the sync websocket client
@@ -85,7 +86,7 @@ def is_open(self: Self) -> bool:
8586 self ._handler_task is not None
8687 and self ._messages is not None
8788 and self ._websocket is not None
88- and self ._websocket .open
89+ and self ._websocket .state == State . OPEN
8990 )
9091
9192 async def _do_open (self : Self ) -> None :
@@ -119,7 +120,7 @@ async def _do_close(self: Self) -> None:
119120 self ._messages = None
120121
121122 # close the connection
122- await cast (websocket_client .WebSocketClientProtocol , self ._websocket ).close ()
123+ await cast (websocket_client .ClientConnection , self ._websocket ).close ()
123124
124125 async def _handler (self : Self ) -> None :
125126 """
@@ -131,9 +132,7 @@ async def _handler(self: Self) -> None:
131132
132133 As long as a given client remains open, this handler will be running as a Task.
133134 """
134- async for response in cast (
135- websocket_client .WebSocketClientProtocol , self ._websocket
136- ):
135+ async for response in cast (websocket_client .ClientConnection , self ._websocket ):
137136 response_dict = json .loads (response )
138137
139138 # if this response corresponds to request, fulfill the Future
@@ -175,7 +174,7 @@ async def _do_send_no_future(self: Self, request: Request) -> None:
175174 Arguments:
176175 request: The request to send.
177176 """
178- await cast (websocket_client .WebSocketClientProtocol , self ._websocket ).send (
177+ await cast (websocket_client .ClientConnection , self ._websocket ).send (
179178 json .dumps (
180179 request_to_websocket (request ),
181180 ),
0 commit comments