From 2276afb13721f204a1e7d21f6c3981bdef6f9637 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 3 May 2026 22:12:52 +0800 Subject: [PATCH] Allow configuring websocket connect options --- dingtalk_stream/stream.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dingtalk_stream/stream.py b/dingtalk_stream/stream.py index 91dc243..1069df1 100644 --- a/dingtalk_stream/stream.py +++ b/dingtalk_stream/stream.py @@ -28,7 +28,7 @@ class DingTalkStreamClient(object): OPEN_CONNECTION_API = DINGTALK_OPENAPI_ENDPOINT + '/v1.0/gateway/connections/open' TAG_DISCONNECT = 'disconnect' - def __init__(self, credential: Credential, logger: logging.Logger = None): + def __init__(self, credential: Credential, logger: logging.Logger = None, websocket_connect_options=None): self.credential: Credential = credential self.event_handler: EventHandler = EventHandler() self.callback_handler_map = {} @@ -38,6 +38,7 @@ def __init__(self, credential: Credential, logger: logging.Logger = None): self._pre_started = False self._is_event_required = False self._access_token = {} + self.websocket_connect_options = websocket_connect_options or {} def register_all_event_handler(self, handler: EventHandler): handler.dingtalk_client = self @@ -71,7 +72,7 @@ async def start(self): self.logger.info('endpoint is %s', connection) uri = f'{connection["endpoint"]}?ticket={quote_plus(connection["ticket"])}' - async with websockets.connect(uri) as websocket: + async with websockets.connect(uri, **self.websocket_connect_options) as websocket: self.websocket = websocket asyncio.create_task(self.keepalive(websocket)) async for raw_message in websocket: