Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(realtime): enable auto_reconnect option from supabase client #938

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.8.0"
supafunc = ">=0.3.1,<0.6.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]
Loading