pybragerone.api.ws¶
WebSocket (Socket.IO) client for BragerOne realtime events.
Classes
|
Protocol for an event dispatcher used by the realtime manager. |
|
Thin Socket.IO wrapper for BragerOne realtime channel. |
- class pybragerone.api.ws.EventDispatcher(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for an event dispatcher used by the realtime manager.
- class pybragerone.api.ws.RealtimeManager(token: str, *, origin: str = 'https://one.brager.pl', referer: str = 'https://one.brager.pl/', io_base: str = 'https://io.brager.pl', socket_path: str = '/socket.io', namespace: str = '/ws', token_provider: Callable[[], Awaitable[str]] | None = None, connect_timeout_s: float = 20.0)[source]¶
Bases:
objectThin Socket.IO wrapper for BragerOne realtime channel.
The manager keeps a single AsyncClient connection, exposes the Engine.IO SID and the namespace SID, and forwards selected events to a user-provided callback (
EventHandler). It does not interpret payloads; that is the gateway’s responsibility.Notes
Authentication is provided only via HTTP headers (Bearer token).
We always connect to the :data:`~.constants.WS_NAMESPACE` namespace.
We listen to:
snapshotand the various*:parameters:changeevents.Subscriptions are emitted in a few payload variants (
modules/devids) and optionally includegroup_id.
- Parameters:
- add_on_connected(cb: Callable[[], Awaitable[None] | None])[source]¶
Register a callback to be called when the connection is established.
- add_on_disconnected(cb: Callable[[], Awaitable[None] | None])[source]¶
Register a callback to be called when the Socket.IO session drops.
- async connect()[source]¶
Open a Socket.IO connection with appropriate headers and wait for join.
- Return type:
- async force_reconnect()[source]¶
Tear down a still-“connected” Socket.IO session and reconnect.
Used when ParamUpdates go silent while the client still reports up (zombie Engine.IO that skipped disconnect callbacks). The SPA recovers via built-in Socket.IO reconnect then
connect→ModulesService.connect+ REST/modules/parameters; our supervisor only acts whenconnectedlooks down, so this forces that same path (on_connected→ gateway resubscribe + prime).Waits for the namespace join (same as
connect()) so callers can safelysid()/modules.connectimmediately afterwards.- Return type:
- async hard_reset()[source]¶
Abandon the Socket.IO client and open a brand-new transport session.
Stronger than
force_reconnect(): stops the supervisor, replaces theAsyncClient(handlers re-bound), then runs a fullconnect(). Used when disconnect/reconnect on the same client fails to restore liveParamUpdatetraffic.- Return type:
- on_event(handler: EventDispatcher)[source]¶
Register a single event dispatcher (gateway attaches here).
- Return type:
- Parameters:
handler (EventDispatcher)