Manages subscription tracking for WebSocket connections.
Pure functional module - state ownership stays with Client GenServer. Tracks subscribed channels and provides restoration on reconnect.
Telemetry Events
The following telemetry events are emitted:
[:zen_websocket, :subscription_manager, :add]- Emitted when a channel is added.- Measurements:
%{count: 1} - Metadata:
%{channel: channel}
- Measurements:
[:zen_websocket, :subscription_manager, :remove]- Emitted when a channel is removed.- Measurements:
%{count: 1} - Metadata:
%{channel: channel}
- Measurements:
[:zen_websocket, :subscription_manager, :restore]- Emitted when subscriptions are restored.- Measurements:
%{channel_count: integer()} - Metadata:
%{channels: [String.t()]}
- Measurements:
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
handle_message | 2 | Handle incoming subscription confirmation messages. | msg: value, state: value |
build_restore_message | 1 | Build a restore message for reconnection. | state: value |
list | 1 | List all currently tracked subscriptions. | state: value |
remove | 2 | Remove a channel from the tracked subscription set. | state: value, channel: value |
add | 2 | Add a channel to the tracked subscription set. | state: value, channel: value |
Summary
Functions
Adds a channel to the tracked subscription set.
Builds a restore message for reconnection.
Handles incoming subscription confirmation messages.
Lists all currently tracked subscriptions.
Removes a channel from the tracked subscription set.
Types
Functions
Adds a channel to the tracked subscription set.
Called when a subscription confirmation is received.
Builds a restore message for reconnection.
Returns nil if:
- No subscriptions to restore
restore_subscriptionsconfig is false
Returns JSON-encoded subscribe message otherwise.
Handles incoming subscription confirmation messages.
Extracts the channel from the message and adds it to tracked subscriptions.
Lists all currently tracked subscriptions.
Removes a channel from the tracked subscription set.
Called when unsubscribing from a channel.