OutgoingRequest constructor

OutgoingRequest(
  1. SipMethod? method,
  2. URI? ruri,
  3. PitelUA? ua, [
  4. Map<String, dynamic>? params,
  5. List? extraHeaders,
  6. String? body,
])

Implementation

OutgoingRequest(this.method, this.ruri, this.ua,
    [Map<String, dynamic>? params,
    List<dynamic>? extraHeaders,
    String? body]) {
  // Mandatory parameters check.
  if (method == null || ruri == null || ua == null) {
    throw Exceptions.TypeError('OutgoingRequest: ctor parameters invalid!');
  }

  params = params ?? <String, dynamic>{};
  // ignore: prefer_initializing_formals
  this.body = body;
  if (extraHeaders != null)
    this.extraHeaders = utils.cloneArray(extraHeaders);

  // Fill the Common SIP Request Headers.

  // Route.
  if (params['route_set'] != null) {
    setHeader('route', params['route_set']);
  } else if (ua!.configuration!.usePreloadedRoute) {
    //! sip_domain
    // setHeader('route', '<${ua!.transport!.sip_uri};sipml5-outbound;lr>');
    setHeader(
        'route', '<sip:${ua!.configuration!.sipDomain};lr;transport=udp>');
  }

  // Via.
  // Empty Via header. Will be filled by the client transaction.
  setHeader('via', '');

  // Max-Forwards.
  setHeader('max-forwards', DartSIP_C.MAX_FORWARDS);

  // To
  dynamic to_uri = params['to_uri'] ?? ruri;
  dynamic to_params = params['to_tag'] != null
      ? <String, dynamic>{'tag': params['to_tag']}
      : null;
  String? to_display_name = params['to_display_name'];

  to = NameAddrHeader(to_uri, to_display_name, to_params);
  setHeader('to', to.toString());

  // From.
  dynamic from_uri = params['from_uri'] ?? ua!.configuration!.uri;
  Map<String, dynamic> from_params = <String, dynamic>{
    'tag': params['from_tag'] ?? utils.newTag()
  };
  String? display_name;

  if (params['from_display_name'] != null) {
    display_name = params['from_display_name'];
  } else if (ua!.configuration!.displayName != null) {
    display_name = ua!.configuration!.displayName;
  } else {
    display_name = null;
  }

  from = NameAddrHeader(from_uri, display_name, from_params);
  setHeader('from', from.toString());

  // Call-ID.
  String call_id = params['call_id'] ??
      (ua!.configuration!.jssip_id! + utils.createRandomToken(15));

  this.call_id = call_id;
  setHeader('call-id', call_id);

  // CSeq.
  num cseq =
      params['cseq'] ?? utils.Math.floor(utils.Math.randomDouble() * 10000);

  this.cseq = cseq as int?;
  setHeader('cseq', '$cseq ${SipMethodHelper.getName(method)}');
}