connectAckProcessor method

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

Processes the connect acknowledgement message.

Implementation

@protected
bool connectAckProcessor(MqttMessage msg) {
  MqttLogger.log(
      'SynchronousMqttServerConnectionHandler::_connectAckProcessor');
  try {
    final MqttConnectAckMessage ackMsg = msg;
    // 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(
          'SynchronousMqttServerConnectionHandler::_connectAckProcessor '
          'connection rejected');
      connectionStatus.returnCode = ackMsg.variableHeader.returnCode;
      _performConnectionDisconnect();
    } else {
      // Initialize the keepalive to start the ping based keepalive process.
      MqttLogger.log(
          'SynchronousMqttServerConnectionHandler::_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(
      'SynchronousMqttServerConnectionHandler:: cancelling connect timer');
  connectTimer.cancel();
  return true;
}