subscription method

Subscription subscription(
  1. String channel
)

Create or get a subscription for a channel.

Implementation

Subscription subscription(String channel) {
  final existing = _subscriptions[channel];
  if (existing != null) {
    // If subscription was deleted, remove it and create a new one
    if (existing.isDeleted) {
      _subscriptions.remove(channel);
    } else {
      return existing;
    }
  }

  final subscription = Subscription(SubscriptionOptions(
    channel: channel,
    httpClient: _httpClient,
    hooks: _hooks,
    getEventSourceStatus: () => _status,
    onDeleted: (ch) {
      // Auto-remove from internal map when subscription is deleted
      _subscriptions.remove(ch);
    },
  ));

  _subscriptions[channel] = subscription;
  return subscription;
}