disconnect method

Future<void> disconnect()

Implementation

Future<void> disconnect() async {
  if (_state is Disconnected) {
    return;
  }
  _shouldReconnect = false;
  _reconnectTimer?.cancel();
  _reconnectTimer = null;
  _keepAlive?.stop();
  _updateState(const Disconnected());
  await _channel?.sink.close();
  _channel = null;
  _negotiatedProtocol = NegotiatedWsProtocol.v2;
  if (_outboundQueue.isNotEmpty) {
    SdkLogger.w(
      'Dropping ${_outboundQueue.length} queued outbound message(s) on '
      'disconnect',
    );
    _outboundQueue.clear();
  }
}