getConnectMessage method

MqttConnectMessage getConnectMessage(
  1. String? username,
  2. String? password
)

Gets a pre-configured connect message if one has not been supplied by the user. Returns an MqttConnectMessage that can be used to connect to a message broker if the user has not set one.

Implementation

MqttConnectMessage getConnectMessage(String? username, String? password) =>
    connectionMessage ??= MqttConnectMessage()
        .withClientIdentifier(clientIdentifier)
        // Explicitly set the will flag
        .withWillQos(MqttQos.atMostOnce)
        .keepAliveFor(MqttConstants.defaultKeepAlive)
        .authenticateAs(username, password)
        .startClean();