unsubscribe method

Push unsubscribe({
  1. Duration? timeout,
})

Leaves the channel

Unsubscribes from server events, and instructs channel to terminate on server. Triggers onClose() hooks.

To receive leave acknowledgements, use the a receive hook to bind to the server ack,

channel.unsubscribe().receive("ok", (_){print("left!");} );

Implementation

Push unsubscribe({Duration? timeout}) {
  void onClose() {
    socket.log('channel', 'leave $topic');
    trigger(
      ChannelEvents.close.eventName(),
      payload: {'type': 'leave'},
      ref: joinRef(),
    );
  }

  _state = ChannelStates.leaving;
  final leavePush = Push(this, ChannelEvents.leave, {}, timeout ?? _timeout);
  leavePush
      .receive('ok', (_) => onClose())
      .receive('timeout', (_) => onClose());
  leavePush.send();
  if (!canPush()) {
    leavePush.trigger('ok', {});
  }

  return leavePush;
}