BloomRealtimeClient class
Client-side Realtime manager that connects to a Bloom WebSocket endpoint.
Provides resilient real-time features over WebSockets:
- Pub/Sub channel subscriptions returning a
Stream<Map<String, dynamic>> - Presence tracking with state snapshots, joins, and leaves
- Automatic exponential backoff reconnection with jitter and maximum delay cap
- Automatic re-subscription to channels and presence channels after reconnection
- Periodic heartbeat ping/pong keep-alives
Example
final client = BloomRealtimeClient(
uri: Uri.parse('ws://localhost:8080/ws/realtime'),
);
// Listen to connection state changes
client.onStateChanged.listen((state) {
print('Connection state: $state');
});
await client.connect();
// Subscribe to a channel
final chatStream = client.subscribe('chat:lobby');
chatStream.listen((data) => print('Chat message: $data'));
// Broadcast to channel
client.broadcast('chat:lobby', {'text': 'Hello!'});
- Available extensions
Constructors
- BloomRealtimeClient({required Uri uri, Duration initialReconnectDelay = const Duration(milliseconds: 500), Duration maxReconnectDelay = const Duration(seconds: 30), double backoffMultiplier = 1.5, bool autoReconnect = true, Duration pingInterval = const Duration(seconds: 30)})
-
Creates a BloomRealtimeClient targeting
uri.
Properties
- autoReconnect → bool
-
Whether to automatically reconnect when the connection drops.
final
- backoffMultiplier → double
-
Exponential backoff multiplier applied on each failed reconnection.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialReconnectDelay → Duration
-
Initial reconnection delay before the first retry attempt.
final
- isConnected → bool
-
Whether the client is currently connected to the server.
no setter
- maxReconnectDelay → Duration
-
Maximum ceiling on reconnection delays.
final
-
onStateChanged
→ Stream<
RealtimeConnectionState> -
Broadcast stream that emits whenever state changes.
no setter
- pingInterval → Duration
-
Interval at which ping keep-alive messages are sent.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → RealtimeConnectionState
-
Current connection state of the client.
no setter
- uri → Uri
-
Target WebSocket server endpoint URI.
final
Methods
-
broadcast(
String channelName, Map< String, dynamic> payload) → void -
Broadcasts a
payloadmap tochannelNamefrom the client. -
connect(
) → Future< void> - Connects to the WebSocket server at uri.
-
dispose(
) → void - Disconnects the socket, cancels timers, closes stream controllers, and releases resources.
-
invalidateQueriesOnBroadcast(
{required String channel, required List key, bool filter(Map< String, dynamic> payload)?}) → RealtimeQueryBridge -
Available on BloomRealtimeClient, provided by the BloomRealtimeClientQueryBridgeExtension extension
Binds a realtime channel directly to aBloomDataquerykeyfor automatic invalidation. -
joinPresence(
String channelName, Map< String, dynamic> userInfo) → Stream<List< Map< >String, dynamic> > -
Joins presence in
channelNamepublishinguserInfometadata. -
leavePresence(
String channelName) → void -
Leaves presence in
channelName. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
subscribe(
String channelName) → Stream< Map< String, dynamic> > -
Subscribes to
channelNameand returns a broadcast Stream of message payloads. -
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribe(
String channelName) → void -
Unsubscribes from
channelName, closing its local broadcast controller.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited