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]) {
  if (status_code == 100) {
    /* RFC 4320 4.1
     * 'A SIP element MUST NOT
     * send any provisional response with a
     * Status-Code other than 100 to a non-INVITE request.'
     */
    switch (state) {
      case TransactionState.TRYING:
        stateChanged(TransactionState.PROCEEDING);
        if (!transport!.send(response)) {
          onTransportError();
        }
        break;
      case TransactionState.PROCEEDING:
        last_response = response;
        if (!transport!.send(response)) {
          onTransportError();
          if (onFailure != null) {
            onFailure();
          }
        } else if (onSuccess != null) {
          onSuccess();
        }
        break;
      default:
        break;
    }
  } else if (status_code >= 200 && status_code <= 699) {
    switch (state) {
      case TransactionState.TRYING:
      case TransactionState.PROCEEDING:
        stateChanged(TransactionState.COMPLETED);
        last_response = response;
        J = setTimeout(() {
          timer_J();
        }, Timers.TIMER_J);
        if (!transport!.send(response)) {
          onTransportError();
          if (onFailure != null) {
            onFailure();
          }
        } else if (onSuccess != null) {
          onSuccess();
        }
        break;
      case TransactionState.COMPLETED:
        break;
      default:
        break;
    }
  }
}