Skip to content

Commit cff1d4a

Browse files
Merge branch 'Orchius83-multi_user_requirements_update'
2 parents f94935c + 5cb58e9 commit cff1d4a

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

cheshire_cat_api/cat_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ def url(self):
4646
return f"{secure}{self.settings.base_url}{port}"
4747

4848
def _connect(self):
49+
connection_url = f"ws{self.url}/{self.settings.ws.path}"
50+
if self.settings.ws.user_id is not None:
51+
connection_url += f"/{self.settings.ws.user_id}"
4952
""""Connect to the WebSocket in a separate thread"""
5053
self._ws = WebSocketApp(
51-
f"ws{self.url}/{self.settings.ws.path}",
54+
connection_url,
5255
on_message=self.on_ws_message,
5356
on_error=self.on_ws_error,
5457
on_close=self.on_ws_close,
@@ -71,6 +74,7 @@ def run(self):
7174
header_name='access_token',
7275
header_value=self.settings.auth_key
7376
))
77+
time.sleep(2)
7478
self.is_started = True
7579

7680
def on_ws_open(self, ws):

cheshire_cat_api/utils.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,44 @@ class WebSocketSettings:
2424
Class containing the WebSocket configuration options and variables used by ccat-api package
2525
"""
2626

27-
def __init__(self):
27+
def __init__(self, path='ws', retries=3, delay=5000, on_failed=None, user_id=None):
2828
# Websocket path to use to communicate with the CCat
29-
self.path = 'ws'
29+
self.path = path
3030
# The maximum number of retries before calling on_failed
31-
self.retries = 3
31+
self.retries = retries
3232
# The delay for reconnect, in milliseconds
33-
self.delay = 5000
33+
self.delay = delay
3434
# The function to call after failing to reconnect
35-
self.on_failed = None
35+
self.on_failed = on_failed
36+
# User to connect with
37+
self.user_id = user_id
3638

3739

3840
class Settings:
3941
"""
4042
Class containing all the configuration options and variables used by ccat-api package
4143
"""
4244

43-
def __init__(self):
45+
def __init__(self,
46+
base_url='localhost',
47+
auth_key='',
48+
port=1865,
49+
secure=False,
50+
timeout=10000,
51+
instant=True,
52+
ws=WebSocketSettings(),
53+
):
4454
# The URL to which connect to the Cat
45-
self.base_url = 'localhost'
55+
self.base_url = base_url
4656
# The key to authenticate the Cat endpoints
47-
self.auth_key = ''
57+
self.auth_key = auth_key
4858
# The port to which connect to the Cat
49-
self.port = 1865
59+
self.port = port
5060
# Choose to either use the secure protocol or not
51-
self.secure = False
61+
self.secure = secure
5262
# Timeout for the endpoints, in milliseconds
53-
self.timeout = 10000
63+
self.timeout = timeout
5464
# Choose to either instantly initialize websocket and api client or not
55-
self.instant = True
65+
self.instant = instant
5666
# WebSocket Settings
57-
self.ws = WebSocketSettings()
67+
self.ws = ws

0 commit comments

Comments
 (0)