client: client_id arg defaults to None

This commit is contained in:
Mose Müller 2025-02-20 17:27:55 +01:00
parent c5e1a08c54
commit 60287fef95

View File

@ -84,7 +84,7 @@ class Client:
url: str, url: str,
block_until_connected: bool = True, block_until_connected: bool = True,
sio_client_kwargs: dict[str, Any] = {}, sio_client_kwargs: dict[str, Any] = {},
client_id: str = "pydase_client", client_id: str | None = None,
): ):
# Parse the URL to separate base URL and path prefix # Parse the URL to separate base URL and path prefix
parsed_url = urllib.parse.urlparse(url) parsed_url = urllib.parse.urlparse(url)
@ -138,11 +138,14 @@ class Client:
async def _connect(self) -> None: async def _connect(self) -> None:
logger.debug("Connecting to server '%s' ...", self._url) logger.debug("Connecting to server '%s' ...", self._url)
await self._setup_events() await self._setup_events()
headers = {}
if self._client_id is not None:
headers["X-Client-Id"] = self._client_id
await self._sio.connect( await self._sio.connect(
url=self._base_url, url=self._base_url,
headers={ headers=headers,
"X-Client-Id": self._client_id,
},
socketio_path=f"{self._path_prefix}/ws/socket.io", socketio_path=f"{self._path_prefix}/ws/socket.io",
transports=["websocket"], transports=["websocket"],
retry=True, retry=True,