init_incoming method

void init_incoming(
  1. IncomingRequest request
)

Implementation

void init_incoming(IncomingRequest request) {
  String reg_tone = r'^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*';
  String reg_duration = r'^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*';

  _direction = 'incoming';
  _request = request;

  request.reply(200);

  if (request.body != null) {
    List<String> body = request.body!.split('\n');

    if (body.length >= 1) {
      if ((body[0]).contains(RegExp(reg_tone))) {
        _tone = body[0].replaceAll(reg_tone, '\$2');
      }
    }
    if (body.length >= 2) {
      if ((body[1]).contains(RegExp(reg_duration))) {
        _duration =
            Utils.parseInt(body[1].replaceAll(reg_duration, '\$2'), 10);
      }
    }
  }

  _duration ??= C.DEFAULT_DURATION;

  if (_tone == null) {
    logger.debug('invalid INFO DTMF received, discarded');
  } else {
    _session.newDTMF('remote', this, request);
  }
}