subscribe method

Subscription subscribe({
  1. Set<String>? channels,
  2. Set<String>? channelGroups,
  3. bool withPresence = false,
  4. Keyset? keyset,
  5. String? using,
  6. Timetoken? timetoken,
})
inherited

Subscribes to channels and channelGroups.

Returned subscription is automatically resumed. Example:

var subscription = pubnub.subscribe(channels: {'my_test_channel'});
subscription.messages.listen((envelope) {
  // handle envelope
});

Implementation

Subscription subscribe(
    {Set<String>? channels,
    Set<String>? channelGroups,
    bool withPresence = false,
    Keyset? keyset,
    String? using,
    Timetoken? timetoken}) {
  keyset ??= keysets[using];

  var manager = _getOrCreateManager(keyset);

  var subscription = manager.createSubscription(
      channels: channels,
      channelGroups: channelGroups,
      withPresence: withPresence,
      timetoken: timetoken);

  subscription.resume();

  return subscription;
}