connect method

  1. @override
Future<MqttConnectionStatus?> connect([
  1. String? username,
  2. String? password
])
override

Performs a connect to the message broker with an optional username and password for the purposes of authentication. If a username and password are supplied these will override any previously set in a supplied connection message so if you supply your own connection message and use the authenticateAs method to set these parameters do not set them again here.

Implementation

@override
Future<MqttConnectionStatus?> connect(
    [String? username, String? password]) async {
  instantiationCorrect = true;
  clientEventBus = events.EventBus();
  clientEventBus
      ?.on<DisconnectOnNoPingResponse>()
      .listen(disconnectOnNoPingResponse);
  connectionHandler = MqttSynchronousBrowserConnectionHandler(
    clientEventBus,
    maxConnectionAttempts: maxConnectionAttempts,
  );
  return await super.connect(username, password);
}