Skip to content

Commit 3eb18e3

Browse files
authored
fix(realtime): enable auto_reconnect option from supabase client (#938)
1 parent c1513a9 commit 3eb18e3

File tree

6 files changed

+460
-418
lines changed

6 files changed

+460
-418
lines changed

poetry.lock

Lines changed: 436 additions & 405 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ gotrue = ">=1.3,<3.0"
2222
httpx = ">=0.24,<0.28"
2323
storage3 = ">=0.5.3,<0.9.0"
2424
supafunc = ">=0.3.1,<0.7.0"
25+
typing-extensions = "^4.12.2"
2526

2627
[tool.poetry.dev-dependencies]
2728
pre-commit = "^3.8.0"

supabase/_async/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ async def remove_all_channels(self) -> None:
218218

219219
@staticmethod
220220
def _init_realtime_client(
221-
realtime_url: str, supabase_key: str, options: Optional[Dict[str, Any]]
221+
realtime_url: str, supabase_key: str, options: Optional[Dict[str, Any]] = None
222222
) -> AsyncRealtimeClient:
223+
if options is None:
224+
options = {}
223225
"""Private method for creating an instance of the realtime-py client."""
224-
return AsyncRealtimeClient(
225-
realtime_url, token=supabase_key, params=options or {}
226-
)
226+
return AsyncRealtimeClient(realtime_url, token=supabase_key, **options)
227227

228228
@staticmethod
229229
def _init_storage_client(

supabase/_sync/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ def remove_all_channels(self) -> None:
217217

218218
@staticmethod
219219
def _init_realtime_client(
220-
realtime_url: str, supabase_key: str, options: Optional[Dict[str, Any]]
220+
realtime_url: str, supabase_key: str, options: Optional[Dict[str, Any]] = None
221221
) -> SyncRealtimeClient:
222+
if options is None:
223+
options = {}
222224
"""Private method for creating an instance of the realtime-py client."""
223-
return SyncRealtimeClient(
224-
realtime_url, token=supabase_key, params=options or {}
225-
)
225+
return SyncRealtimeClient(realtime_url, token=supabase_key, **options)
226226

227227
@staticmethod
228228
def _init_storage_client(

supabase/lib/client_options.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass, field
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Dict, Optional, Union
33

44
from gotrue import (
55
AsyncMemoryStorage,
@@ -12,6 +12,8 @@
1212
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
1313
from supafunc.utils import DEFAULT_FUNCTION_CLIENT_TIMEOUT
1414

15+
from supabase.types import RealtimeClientOptions
16+
1517
from ..version import __version__
1618

1719
DEFAULT_HEADERS = {"X-Client-Info": f"supabase-py/{__version__}"}
@@ -37,7 +39,7 @@ class ClientOptions:
3739
storage: SyncSupportedStorage = field(default_factory=SyncMemoryStorage)
3840
"""A storage provider. Used to store the logged in session."""
3941

40-
realtime: Optional[Dict[str, Any]] = None
42+
realtime: Optional[RealtimeClientOptions] = None
4143
"""Options passed to the realtime-py instance"""
4244

4345
postgrest_client_timeout: Union[int, float, Timeout] = (
@@ -63,7 +65,7 @@ def replace(
6365
auto_refresh_token: Optional[bool] = None,
6466
persist_session: Optional[bool] = None,
6567
storage: Optional[SyncSupportedStorage] = None,
66-
realtime: Optional[Dict[str, Any]] = None,
68+
realtime: Optional[RealtimeClientOptions] = None,
6769
postgrest_client_timeout: Union[
6870
int, float, Timeout
6971
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
@@ -104,7 +106,7 @@ def replace(
104106
auto_refresh_token: Optional[bool] = None,
105107
persist_session: Optional[bool] = None,
106108
storage: Optional[SyncSupportedStorage] = None,
107-
realtime: Optional[Dict[str, Any]] = None,
109+
realtime: Optional[RealtimeClientOptions] = None,
108110
postgrest_client_timeout: Union[
109111
int, float, Timeout
110112
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
@@ -142,7 +144,7 @@ def replace(
142144
auto_refresh_token: Optional[bool] = None,
143145
persist_session: Optional[bool] = None,
144146
storage: Optional[SyncSupportedStorage] = None,
145-
realtime: Optional[Dict[str, Any]] = None,
147+
realtime: Optional[RealtimeClientOptions] = None,
146148
postgrest_client_timeout: Union[
147149
int, float, Timeout
148150
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,

supabase/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing_extensions import NotRequired, TypedDict
2+
3+
4+
class RealtimeClientOptions(TypedDict, total=False):
5+
auto_reconnect: NotRequired[bool]
6+
hb_interval: NotRequired[int]
7+
max_retries: NotRequired[int]
8+
initial_backoff: NotRequired[float]

0 commit comments

Comments
 (0)