refer method

ReferSubscriber? refer(
  1. dynamic target, [
  2. Map<String, dynamic>? options
])

Refer

Implementation

ReferSubscriber? refer(dynamic target, [Map<String, dynamic>? options]) {
  logger.debug('refer()');

  options = options ?? <String, dynamic>{};

  dynamic originalTarget = target;

  if (_status != C.statusWaitingForAck && _status != C.statusConfirmed) {
    return null;
  }

  // Check target validity.
  target = _ua!.normalizeTarget(target);
  if (target == null) {
    throw exceptions.TypeError('Invalid target: $originalTarget');
  }

  ReferSubscriber referSubscriber = ReferSubscriber(this);

  referSubscriber.sendRefer(target, options);

  // Store in the map.
  int? id = referSubscriber.id;

  _referSubscribers[id] = referSubscriber;

  // Listen for ending events so we can remove it from the map.
  referSubscriber.on(EventReferRequestFailed(),
      (EventReferRequestFailed data) {
    _referSubscribers.remove(id);
  });
  referSubscriber.on(EventReferAccepted(), (EventReferAccepted data) {
    _referSubscribers.remove(id);
  });
  referSubscriber.on(EventReferFailed(), (EventReferFailed data) {
    _referSubscribers.remove(id);
  });

  return referSubscriber;
}