connectAckProcessor method Null safety

  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 (ackMsg.variableHeader.returnCode ==
            MqttConnectReturnCode.brokerUnavailable ||
        ackMsg.variableHeader.returnCode ==
            MqttConnectReturnCode.identifierRejected ||
        ackMsg.variableHeader.returnCode ==
            MqttConnectReturnCode.unacceptedProtocolVersion ||
        ackMsg.variableHeader.returnCode ==
            MqttConnectReturnCode.notAuthorized ||
        ackMsg.variableHeader.returnCode ==
            MqttConnectReturnCode.badUsernameOrPassword) {
      MqttLogger.log('MqttConnectionHandlerBase::_connectAckProcessor '
          'connection rejected');
      connectionStatus.returnCode = ackMsg.variableHeader.returnCode;
      _performConnectionDisconnect();
    } else {
      // Initialize the keepalive to start the ping based keepalive process.
      MqttLogger.log('MqttConnectionHandlerBase:_connectAckProcessor '
          '- state = connected');
      connectionStatus.state = MqttConnectionState.connected;
      connectionStatus.returnCode = MqttConnectReturnCode.connectionAccepted;
      // 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;
}