sendRefer method

void sendRefer(
  1. URI target,
  2. Map<String, dynamic> options
)

Implementation

void sendRefer(URI target, Map<String, dynamic> options) {
  logger.debug('sendRefer()');

  List<dynamic> extraHeaders = Utils.cloneArray(options['extraHeaders']);
  EventManager eventHandlers = options['eventHandlers'] ?? EventManager();

  // Set event handlers.
  addAllEventHandlers(eventHandlers);

  // Replaces URI header field.

  String replaces = '';

  if (options['replaces'] != null) {
    replaces = options['replaces'].call_id;
    replaces += ';to-tag=${options['replaces'].to_tag}';
    replaces += ';from-tag=${options['replaces'].from_tag}';
    replaces = Utils.encodeURIComponent(replaces);
  }

  // Refer-To header field.
  String referTo = 'Refer-To: <$target' +
      (replaces.isNotEmpty ? '?Replaces=$replaces' : '') +
      '>';

  extraHeaders.add(referTo);

  // Referred-By header field.
  String referredBy =
      'Referred-By: <${_session.ua!.configuration!.uri.scheme}:${_session.ua!.configuration!.uri.user}@${_session.ua!.configuration!.uri.host}>';

  extraHeaders.add(referredBy);
  extraHeaders.add('Contact: ${_session.contact}');

  EventManager handlers = EventManager();
  handlers.on(EventOnSuccessResponse(), (EventOnSuccessResponse event) {
    _requestSucceeded(event.response);
  });
  handlers.on(EventOnErrorResponse(), (EventOnErrorResponse event) {
    _requestFailed(event.response, DartSIP_C.CausesType.REJECTED);
  });
  handlers.on(EventOnTransportError(), (EventOnTransportError event) {
    _requestFailed(null, DartSIP_C.CausesType.CONNECTION_ERROR);
  });
  handlers.on(EventOnRequestTimeout(), (EventOnRequestTimeout event) {
    _requestFailed(null, DartSIP_C.CausesType.REQUEST_TIMEOUT);
  });
  handlers.on(EventOnDialogError(), (EventOnDialogError event) {
    _requestFailed(null, DartSIP_C.CausesType.DIALOG_ERROR);
  });

  OutgoingRequest request = _session.sendRequest(
      SipMethod.REFER, <String, dynamic>{
    'extraHeaders': extraHeaders,
    'eventHandlers': handlers
  });

  _id = request.cseq;
}