autoReconnect method

  1. @protected
void autoReconnect (
  1. AutoReconnect reconnectEvent
)
@protected

Auto reconnect

Implementation

@protected
void autoReconnect(AutoReconnect reconnectEvent) async {
  // If already in progress exit
  if (autoReconnectInProgress) {
    return;
  }

  // If the auto reconnect callback is set call it
  if (onAutoReconnect != null) {
    onAutoReconnect();
  }
  // Disconnect and call internal connect indefinitely
  connection.disconnect(auto: true);
  connectionStatus = MqttClientConnectionStatus();
  autoReconnectInProgress = true;
  connection.onDisconnected = null;
  while (connectionStatus.state != MqttConnectionState.connected) {
    MqttLogger.log(
        'MqttConnectionHandlerBase::autoReconnect - attempting reconnection');
    await internalConnect(server, port, connectionMessage);
  }
  autoReconnectInProgress = false;
  MqttLogger.log(
      'MqttConnectionHandler::autoReconnect - auto reconnect complete');
}