|
11 | 11 | from atproto_client.models.base import ParamsModelBase |
12 | 12 | from atproto_client.models.common import XrpcError |
13 | 13 | from atproto_core.exceptions import DAGCBORDecodingError |
14 | | -from websockets.client import connect as aconnect |
| 14 | +from websockets.asyncio.client import connect as aconnect |
15 | 15 | from websockets.exceptions import ( |
16 | 16 | ConnectionClosedError, |
17 | 17 | ConnectionClosedOK, |
|
46 | 46 |
|
47 | 47 |
|
48 | 48 | if t.TYPE_CHECKING: |
49 | | - from websockets.client import ClientConnection as SyncWebSocketClient |
50 | | - from websockets.legacy.client import Connect as AsyncConnect |
| 49 | + from websockets.asyncio.client import connect as AsyncConnect |
| 50 | + from websockets.sync.client import ClientConnection as SyncWebSocketClient |
51 | 51 |
|
52 | 52 |
|
53 | 53 | def _build_websocket_uri(method: str, base_uri: str, params: t.Optional[t.Dict[str, t.Any]] = None) -> str: |
@@ -124,9 +124,18 @@ def _websocket_uri(self) -> str: |
124 | 124 | return _build_websocket_uri(self._method, self._base_uri, self._params) |
125 | 125 |
|
126 | 126 | def _get_client(self) -> 'SyncWebSocketClient': |
127 | | - return connect(self._websocket_uri, max_size=_MAX_MESSAGE_SIZE_BYTES, close_timeout=0.1) |
| 127 | + # Disable automatic pings for sync client (added in websockets v15+) |
| 128 | + # to maintain behavior consistent with <v14 for now. |
| 129 | + return connect( |
| 130 | + self._websocket_uri, |
| 131 | + max_size=_MAX_MESSAGE_SIZE_BYTES, |
| 132 | + close_timeout=0.1, |
| 133 | + # see https://websockets.readthedocs.io/en/stable/topics/keepalive.html |
| 134 | + ping_interval=None, # Disable automatic pings |
| 135 | + ) |
128 | 136 |
|
129 | 137 | def _get_async_client(self) -> 'AsyncConnect': |
| 138 | + # Async client connect function accepts ping_interval directly (default is 20s) |
130 | 139 | return aconnect(self._websocket_uri, max_size=_MAX_MESSAGE_SIZE_BYTES, close_timeout=0.1) |
131 | 140 |
|
132 | 141 | def _get_reconnection_delay(self) -> int: |
|
0 commit comments