Skip to content

Commit

Permalink
fix(realtime): enable auto_reconnect option from supabase client (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks authored Sep 29, 2024
1 parent c1513a9 commit 3eb18e3
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 418 deletions.
841 changes: 436 additions & 405 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gotrue = ">=1.3,<3.0"
httpx = ">=0.24,<0.28"
storage3 = ">=0.5.3,<0.9.0"
supafunc = ">=0.3.1,<0.7.0"
typing-extensions = "^4.12.2"

[tool.poetry.dev-dependencies]
pre-commit = "^3.8.0"
Expand Down
8 changes: 4 additions & 4 deletions supabase/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ async def remove_all_channels(self) -> None:

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

@staticmethod
def _init_storage_client(
Expand Down
8 changes: 4 additions & 4 deletions supabase/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ def remove_all_channels(self) -> None:

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

@staticmethod
def _init_storage_client(
Expand Down
12 changes: 7 additions & 5 deletions supabase/lib/client_options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import Any, Dict, Optional, Union
from typing import Dict, Optional, Union

from gotrue import (
AsyncMemoryStorage,
Expand All @@ -12,6 +12,8 @@
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
from supafunc.utils import DEFAULT_FUNCTION_CLIENT_TIMEOUT

from supabase.types import RealtimeClientOptions

from ..version import __version__

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

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

postgrest_client_timeout: Union[int, float, Timeout] = (
Expand All @@ -63,7 +65,7 @@ def replace(
auto_refresh_token: Optional[bool] = None,
persist_session: Optional[bool] = None,
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[Dict[str, Any]] = None,
realtime: Optional[RealtimeClientOptions] = None,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
Expand Down Expand Up @@ -104,7 +106,7 @@ def replace(
auto_refresh_token: Optional[bool] = None,
persist_session: Optional[bool] = None,
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[Dict[str, Any]] = None,
realtime: Optional[RealtimeClientOptions] = None,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
Expand Down Expand Up @@ -142,7 +144,7 @@ def replace(
auto_refresh_token: Optional[bool] = None,
persist_session: Optional[bool] = None,
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[Dict[str, Any]] = None,
realtime: Optional[RealtimeClientOptions] = None,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
Expand Down
8 changes: 8 additions & 0 deletions supabase/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing_extensions import NotRequired, TypedDict


class RealtimeClientOptions(TypedDict, total=False):
auto_reconnect: NotRequired[bool]
hb_interval: NotRequired[int]
max_retries: NotRequired[int]
initial_backoff: NotRequired[float]

0 comments on commit 3eb18e3

Please sign in to comment.