disconnectWithCallBck method

void disconnectWithCallBck(
  1. OnCloseCallback? closeCallback
)

Closes the socket connection, effectively logging the user out.

Implementation

void disconnectWithCallBck(OnCloseCallback? closeCallback) {
  _invalidateGatewayResponseTimer();
  _resetGatewayCounters();
  _logger.i('disconnect()');
  if (_closed) {
    _logger.i('WebSocket is already closed');
    closeCallback?.call(0, 'Client send disconnect');
    return;
  }
  // Don't wait for the WebSocket 'close' event, do it now.
  _closed = true;
  _connected = false;
  _registered = false;
  try {
    txSocket.close();
    Future.delayed(const Duration(milliseconds: 100), () {
      closeCallback?.call(0, 'Client send disconnect');
    });
  } catch (error) {
    _logger.e('close() | error closing the WebSocket: $error');
  }
}