leave method
Leave this channel.
Implementation
Push leave({Duration? timeout}) {
_joinPush.cancelTimeout();
_rejoinTimer?.cancel();
final prevState = _state;
_state = PhoenixChannelState.leaving;
final currentLeavePush = _leavePush ??= Push(
this,
event: PhoenixChannelEvent.leave,
payload: () => {},
timeout: timeout ?? _timeout,
);
if (!socket.isConnected || prevState != PhoenixChannelState.joined) {
currentLeavePush.trigger(PushResponse(status: 'ok'));
} else {
void onClose(PushResponse reply) {
_onClose(reply);
close();
}
currentLeavePush
..onReply('ok', onClose)
..onReply('timeout', onClose)
..send();
}
return currentLeavePush;
}