BloomRealtimeBinding class

Reactive signal-backed adapter wrapping a BloomRealtimeChannelClient.

Converts realtime streams into observable signals:

  • connectionState: Tracks socket connection status.
  • channel: Caches and updates a signal for the latest message on a channel.
  • presence: Caches and updates a signal for the list of online presences in a channel.

Ownership & Cleanup

BloomRealtimeBinding listens to streams provided by client. When the binding is no longer needed (for example, when a controller or view unmounts), call dispose to cancel internal stream subscriptions. Note that disposing the binding does NOT dispose the underlying client, allowing the client socket connection to be shared across multiple bindings or views.

Backend Behavior

  • Browser (mount): Subscribed Live descriptors update reactively as incoming socket frames arrive.
  • SSR (renderToHtml): Safe to instantiate with a mock or disconnected client. Initial signals yield null messages and empty presence lists.

Example

final binding = BloomRealtimeBinding(client: realtimeClient);

// Observe messages on a chat channel
final chatSignal = binding.channel('chat:lobby');

// Observe active users
final usersSignal = binding.presence('chat:lobby', userInfo: {'name': 'Bob'});

BloomNode buildChatRoom() {
  return Div(
    children: [
      Live(() => P(text: 'Online: ${usersSignal.value.length} users')),
      Live(() => P(text: 'Latest: ${chatSignal.value?['text'] ?? 'No messages'}')),
    ],
  );
}

Constructors

BloomRealtimeBinding({required BloomRealtimeChannelClient client})
Creates a BloomRealtimeBinding wrapping client and begins observing connection state changes.

Properties

client BloomRealtimeChannelClient
The underlying channel client providing transport streams.
final
connectionState ReadonlySignal<RealtimeConnectionState>
Reactive signal reflecting the current RealtimeConnectionState.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

channel(String channelName) ReadonlySignal<Map<String, dynamic>?>
Returns a ReadonlySignal reflecting the latest message payload on channelName.
dispose() Future<void>
Cancels all active channel and presence stream subscriptions registered by this binding.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
presence(String channelName, {Map<String, dynamic> userInfo = const {}}) ReadonlySignal<List<Map<String, dynamic>>>
Returns a ReadonlySignal tracking the active presence list on channelName.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited