receiveResponse method

  1. @override
void receiveResponse(
  1. int? status_code,
  2. IncomingMessage response, [
  3. void onSuccess()?,
  4. void onFailure()?,
])
override

Implementation

@override
void receiveResponse(int? status_code, IncomingMessage response,
    [void Function()? onSuccess, void Function()? onFailure]) {
  int status_code = response.status_code;

  if (status_code >= 100 && status_code <= 199) {
    switch (state) {
      case TransactionState.CALLING:
        stateChanged(TransactionState.PROCEEDING);
        _eventHandlers.emit(
            EventOnReceiveResponse(response: response as IncomingResponse?));
        break;
      case TransactionState.PROCEEDING:
        _eventHandlers.emit(
            EventOnReceiveResponse(response: response as IncomingResponse?));
        break;
      default:
        break;
    }
  } else if (status_code >= 200 && status_code <= 299) {
    switch (state) {
      case TransactionState.CALLING:
      case TransactionState.PROCEEDING:
        stateChanged(TransactionState.ACCEPTED);
        M = setTimeout(() {
          timer_M();
        }, Timers.TIMER_M);
        _eventHandlers.emit(
            EventOnReceiveResponse(response: response as IncomingResponse?));
        break;
      case TransactionState.ACCEPTED:
        _eventHandlers.emit(
            EventOnReceiveResponse(response: response as IncomingResponse?));
        break;
      default:
        break;
    }
  } else if (status_code >= 300 && status_code <= 699) {
    switch (state) {
      case TransactionState.CALLING:
      case TransactionState.PROCEEDING:
        stateChanged(TransactionState.COMPLETED);
        sendACK(response);
        _eventHandlers.emit(
            EventOnReceiveResponse(response: response as IncomingResponse?));
        break;
      case TransactionState.COMPLETED:
        sendACK(response);
        break;
      default:
        break;
    }
  }
}