subscribe method

  1. @override
Stream<Map<String, dynamic>> subscribe(
  1. String channelName
)
override

Subscribes to channelName and returns a broadcast stream of message payloads.

If already connected, immediately sends a subscribe frame over the wire. Repeated calls with the same channelName share the same underlying stream controller without sending duplicate wire subscriptions.

Implementation

@override
Stream<Map<String, dynamic>> subscribe(String channelName) {
  final isNew = _desiredSubscriptions.add(channelName);

  final stream = _channelStreams.putIfAbsent(channelName, () {
    final controller = StreamController<Map<String, dynamic>>.broadcast();
    _channelControllers[channelName] = controller;
    return controller.stream;
  });

  if (isConnected && isNew) {
    send(RealtimeMessage.subscribe(channelName));
  }

  return stream;
}