From d356f718eb862fee7e73caf67b384cc2b7b4f5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20D=C4=99bski?= Date: Thu, 25 Jul 2024 16:17:38 +0200 Subject: [PATCH] CR fixup: Added response_timeout parameter in open_connection methods. --- changelog.md | 3 +-- livechat/agent/rtm/api/v33.py | 10 +++++----- livechat/agent/rtm/api/v34.py | 10 +++++----- livechat/agent/rtm/api/v35.py | 10 +++++----- livechat/agent/rtm/api/v36.py | 10 +++++----- livechat/customer/rtm/api/v33.py | 10 +++++----- livechat/customer/rtm/api/v34.py | 10 +++++----- livechat/customer/rtm/api/v35.py | 10 +++++----- livechat/customer/rtm/api/v36.py | 10 +++++----- livechat/utils/ws_client.py | 12 ++++++------ 10 files changed, 47 insertions(+), 48 deletions(-) diff --git a/changelog.md b/changelog.md index 7c284bf..612743c 100644 --- a/changelog.md +++ b/changelog.md @@ -5,11 +5,10 @@ All notable changes to this project will be documented in this file. ### Added - New `get_company_details` method in configuration-api v3.6. +- Added `response_timeout` parameter in `open_connection` methods. ### Changed - Updated outdated packages. -- Exposed `response_timeout` parameter in `open_connection` methods. -- Changed default value of `ping_timeout` to 30 seconds. ## [0.3.9] - 2024-04-22 diff --git a/livechat/agent/rtm/api/v33.py b/livechat/agent/rtm/api/v33.py index 0b019d6..495c01d 100644 --- a/livechat/agent/rtm/api/v33.py +++ b/livechat/agent/rtm/api/v33.py @@ -16,17 +16,17 @@ def __init__(self, url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/agent/rtm/api/v34.py b/livechat/agent/rtm/api/v34.py index a00f4d7..db368b9 100644 --- a/livechat/agent/rtm/api/v34.py +++ b/livechat/agent/rtm/api/v34.py @@ -16,17 +16,17 @@ def __init__(self, url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/agent/rtm/api/v35.py b/livechat/agent/rtm/api/v35.py index e9d4447..518bd98 100644 --- a/livechat/agent/rtm/api/v35.py +++ b/livechat/agent/rtm/api/v35.py @@ -16,17 +16,17 @@ def __init__(self, url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/agent/rtm/api/v36.py b/livechat/agent/rtm/api/v36.py index 46f04b6..e33ed09 100644 --- a/livechat/agent/rtm/api/v36.py +++ b/livechat/agent/rtm/api/v36.py @@ -16,17 +16,17 @@ def __init__(self, url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/customer/rtm/api/v33.py b/livechat/customer/rtm/api/v33.py index 9dbb53b..e53fe8f 100644 --- a/livechat/customer/rtm/api/v33.py +++ b/livechat/customer/rtm/api/v33.py @@ -24,17 +24,17 @@ def __init__(self, license_id: str, base_url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/customer/rtm/api/v34.py b/livechat/customer/rtm/api/v34.py index 79ca5c0..9809de3 100644 --- a/livechat/customer/rtm/api/v34.py +++ b/livechat/customer/rtm/api/v34.py @@ -24,17 +24,17 @@ def __init__(self, organization_id: str, base_url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/customer/rtm/api/v35.py b/livechat/customer/rtm/api/v35.py index baf9909..0ccb279 100644 --- a/livechat/customer/rtm/api/v35.py +++ b/livechat/customer/rtm/api/v35.py @@ -24,17 +24,17 @@ def __init__(self, organization_id: str, base_url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/customer/rtm/api/v36.py b/livechat/customer/rtm/api/v36.py index 7e13f4c..5c9e89c 100644 --- a/livechat/customer/rtm/api/v36.py +++ b/livechat/customer/rtm/api/v36.py @@ -24,17 +24,17 @@ def __init__(self, organization_id: str, base_url: str): def open_connection(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> None: + response_timeout: Union[float, int] = 3) -> None: ''' Opens WebSocket connection. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, diff --git a/livechat/utils/ws_client.py b/livechat/utils/ws_client.py index c41795f..cbf875d 100644 --- a/livechat/utils/ws_client.py +++ b/livechat/utils/ws_client.py @@ -7,7 +7,7 @@ import ssl import threading from time import sleep -from typing import List, NoReturn +from typing import List, NoReturn, Union from loguru import logger from websocket import WebSocketApp, WebSocketConnectionClosedException @@ -31,16 +31,16 @@ def __init__(self, *args, **kwargs): def open(self, origin: dict = None, - ping_timeout: float = 30, - ping_interval: float = 5, - ws_conn_timeout: float = 10, + ping_timeout: Union[float, int] = 3, + ping_interval: Union[float, int] = 5, + ws_conn_timeout: Union[float, int] = 10, keep_alive: bool = True, - response_timeout: float = 3) -> NoReturn: + response_timeout: Union[float, int] = 3) -> NoReturn: ''' Opens websocket connection and keep running forever. Args: origin (dict): Specifies origin while creating websocket connection. ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 30 seconds. + by default sets to 3 seconds. ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). If set to 0, no ping is sent periodically, by default sets to 5 seconds. ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection,