internalDisconnect method Null safety

  1. @protected
void internalDisconnect()

Internal disconnect This is always passed to the connection handler to allow the client to close itself down correctly on disconnect.

Implementation

@protected
void internalDisconnect() {
  // if we don't have a connection Handler we are already disconnected.
  if (connectionHandler == null) {
    MqttLogger.log(
        'MqttClient::internalDisconnect - not invoking disconnect, no connection handler');
    return;
  }
  if (autoReconnect && connectionHandler.initialConnectionComplete) {
    if (!connectionHandler.autoReconnectInProgress) {
      // Fire an automatic auto reconnect request
      clientEventBus!.fire(AutoReconnect(userRequested: false));
    } else {
      MqttLogger.log(
          'MqttClient::internalDisconnect - not invoking auto connect, already in progress');
    }
  } else {
    // Unsolicited disconnect only if we are connected initially
    if (connectionHandler.initialConnectionComplete) {
      _disconnect(unsolicited: true);
    }
  }
}