subscribeTo method

RealtimeSubscription subscribeTo(
  1. List<String> channels
)
inherited

Implementation

RealtimeSubscription subscribeTo(List<String> channels) {
  StreamController<RealtimeMessage> controller = StreamController.broadcast();
  for (var channel in channels) {
    if (!_channels.containsKey(channel)) {
      _channels[channel] = [];
    }
    _channels[channel]!.add(controller);
  }
  Future.delayed(Duration.zero, () => _createSocket());
  RealtimeSubscription subscription = RealtimeSubscription(
      stream: controller.stream,
      close: () async {
        controller.close();
        for (var channel in channels) {
          _channels[channel]!.remove(controller);
          if (_channels[channel]!.isEmpty) {
            _channels.remove(channel);
          }
        }
        if (_channels.isNotEmpty) {
          await Future.delayed(Duration.zero, () => _createSocket());
        } else {
          await _closeConnection();
        }
      });
  return subscription;
}