connectAckProcessor method

  1. @protected
bool connectAckProcessor(
  1. MqttMessage msg
)

Processes the connect acknowledgement message.

Implementation

@protected
bool connectAckProcessor(MqttMessage msg) {
  MqttLogger.log('MqttConnectionHandlerBase::_connectAckProcessor');
  try {
    final ackMsg = msg as MqttConnectAckMessage;
    // Drop the connection if our connect request has been rejected.
    if (MqttReasonCodeUtilities.isError(
        mqttConnectReasonCode.asInt(ackMsg.variableHeader!.reasonCode)!)) {
      MqttLogger.log('MqttConnectionHandlerBase::_connectAckProcessor '
          'connection rejected, reason code is ${mqttConnectReasonCode.asString(ackMsg.variableHeader!.reasonCode)}');
      connectionStatus.reasonCode = ackMsg.variableHeader!.reasonCode;
      connectionStatus.reasonString = ackMsg.variableHeader!.reasonString;
      _performConnectionDisconnect();
    } else {
      // Initialize the keepalive to start the ping based keepalive process.
      MqttLogger.log('MqttConnectionHandlerBase::_connectAckProcessor '
          '- state = connected');
      connectionStatus.state = MqttConnectionState.connected;
      connectionStatus.reasonCode = ackMsg.variableHeader!.reasonCode;
      connectionStatus.reasonString = ackMsg.variableHeader!.reasonString;
      connectionStatus.connectAckMessage = msg;
      // Call the connected callback if we have one
      if (onConnected != null) {
        onConnected!();
      }
    }
  } on Exception {
    _performConnectionDisconnect();
  }
  // Cancel the connect timer;
  MqttLogger.log('MqttConnectionHandlerBase:: cancelling connect timer');
  connectTimer.cancel();
  return true;
}