disconnect method

void disconnect()

Implementation

void disconnect() {
  if (socket == null) {
    Logs.debug("Socket already null, nothing to disconnect", tag: 'socket');
    return;
  }

  Logs.info("Disconnecting socket ID: ${socket!.id}", tag: 'socket');
  try {
    socket!.disconnect();
    socket!.dispose();
    socket = null;
    _isInitialized = false;
    _isConnecting = false;
    _eventListenerRegistered = false;
    _openInteractionCalled = false;
    _lastOpenInteractionTime = null;
    Logs.info("Socket disconnected and disposed successfully", tag: 'socket');
  } catch (e) {
    Logs.logError("Error during socket disconnect", tag: 'socket', error: e);
    socket = null;
    _isInitialized = false;
    _isConnecting = false;
    _eventListenerRegistered = false;
    _openInteractionCalled = false;
    _lastOpenInteractionTime = null;
  }
}