Dialog constructor

Dialog(
  1. RTCSession owner,
  2. dynamic message,
  3. String type, [
  4. int? state,
])

Implementation

Dialog(RTCSession owner, dynamic message, String type, [int? state]) {
  state = state ?? DialogStatus.STATUS_CONFIRMED;
  _owner = owner;
  _ua = owner.ua;

  if (!message.hasHeader('contact')) {
    throw Exceptions.TypeError(
        'unable to create a Dialog without Contact header field');
  }

  if (message is IncomingResponse) {
    state = (message.status_code < 200)
        ? DialogStatus.STATUS_EARLY
        : DialogStatus.STATUS_CONFIRMED;
  }

  dynamic contact = message.parseHeader('contact');

  // RFC 3261 12.1.1.
  if (type == 'UAS') {
    _id = Id.fromMap(<String, dynamic>{
      'call_id': message.call_id,
      'local_tag': message.to_tag,
      'remote_tag': message.from_tag,
    });

    _state = state;
    _remote_seqnum = message.cseq;
    _local_uri = message.parseHeader('to').uri;
    _remote_uri = message.parseHeader('from').uri;
    _remote_target = contact.uri;
    _route_set = message.getHeaders('record-route');
    _ack_seqnum = _remote_seqnum;
  }
  // RFC 3261 12.1.2.
  else if (type == 'UAC') {
    _id = Id.fromMap(<String, dynamic>{
      'call_id': message.call_id,
      'local_tag': message.from_tag,
      'remote_tag': message.to_tag,
    });
    _state = state;
    local_seqnum = message.cseq;
    _local_uri = message.parseHeader('from').uri;
    _remote_uri = message.parseHeader('to').uri;
    _remote_target = contact.uri;
    _route_set = message.getHeaders('record-route').reversed.toList();
    _ack_seqnum = null;
  }

  _ua!.newDialog(this);
  logger.debug(
      '$type dialog created with status ${_state == DialogStatus.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'}');
}