doAutoReconnect method

void doAutoReconnect({
  1. bool force = false,
})

Auto reconnect method, used to invoke a manual auto reconnect sequence. If autoReconnect is not set this method does nothing. If the client is not disconnected this method will have no effect unless the force parameter is set to true, otherwise auto reconnect will try indefinitely to reconnect to the broker.

Implementation

void doAutoReconnect({bool force = false}) {
  if (!autoReconnect) {
    MqttLogger.log(
        'MqttClient::doAutoReconnect - auto reconnect is not set, exiting');
    return;
  }

  if (connectionStatus!.state != MqttConnectionState.connected || force) {
    // Fire a manual auto reconnect request.
    final wasConnected =
        connectionStatus!.state == MqttConnectionState.connected;
    clientEventBus!
        .fire(AutoReconnect(userRequested: true, wasConnected: wasConnected));
  }
}