subscribeTo method
Implementation
RealtimeSubscription subscribeTo(List<String> channels) {
StreamController<RealtimeMessage> controller = StreamController.broadcast();
_channels.addAll(channels);
Future.delayed(Duration.zero, () => _createSocket());
int id = DateTime.now().microsecondsSinceEpoch;
RealtimeSubscription subscription = RealtimeSubscription(
controller: controller,
channels: channels,
close: () async {
_subscriptions.remove(id);
controller.close();
_cleanup(channels);
if (_channels.isNotEmpty) {
await Future.delayed(Duration.zero, () => _createSocket());
} else {
await _closeConnection();
}
});
_subscriptions[id] = subscription;
return subscription;
}