Skip to content

Commit 1a42fff

Browse files
committed
Patch WebsocketClient to work with any websockets version >= 10.0
1 parent 6b7acc8 commit 1a42fff

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [4.0.8] - 2025-06-20
9+
10+
- Patch WebsocketClient to work with any websockets version >= 10.0
11+
812
## [4.0.7] - 2025-06-19
913

1014
- Support requesting a temporary token (JWT) with region and client ref

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.7
1+
4.0.8

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
websockets>=14.0
1+
websockets>=10.0
22
httpx[http2]~=0.23
33
polling2~=0.5
44
toml~=0.10.2

speechmatics/client.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@
3939
UsageMode,
4040
)
4141

42+
try:
43+
# websockets >= 13.0
44+
from websockets.asyncio.client import ClientConnection
45+
from websockets.asyncio.client import connect
46+
47+
WS_HEADERS_KEY = "additional_headers"
48+
except ImportError:
49+
from websockets.legacy.client import WebSocketClientProtocol
50+
from websockets.legacy.client import connect # type: ignore
51+
52+
WS_HEADERS_KEY = "extra_headers"
53+
54+
4255
LOGGER = logging.getLogger(__name__)
4356

4457
# If the logging level is set to DEBUG then websockets logs very verbosely,
@@ -613,14 +626,18 @@ async def run(
613626
parsed_url._replace(path=url_path, query=updated_query)
614627
)
615628

629+
ws_kwargs = {
630+
WS_HEADERS_KEY: extra_headers,
631+
"ssl": self.connection_settings.ssl_context,
632+
"ping_timeout": self.connection_settings.ping_timeout_seconds,
633+
# Don't limit the max. size of incoming messages
634+
"max_size": None,
635+
}
636+
616637
try:
617-
async with websockets.connect( # pylint: disable=no-member
638+
async with connect(
618639
updated_url,
619-
ssl=self.connection_settings.ssl_context,
620-
ping_timeout=self.connection_settings.ping_timeout_seconds,
621-
# Don't limit the max. size of incoming messages
622-
max_size=None,
623-
additional_headers=extra_headers,
640+
**ws_kwargs,
624641
) as self.websocket:
625642
await self._communicate(stream, audio_settings)
626643
finally:

0 commit comments

Comments
 (0)