renegotiate method

bool renegotiate([
  1. Map<String, dynamic>? options,
  2. Function? done
])

Implementation

bool renegotiate([Map<String, dynamic>? options, Function? done]) {
  logger.debug('renegotiate()');

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

  Map<String, dynamic>? rtcOfferConstraints =
      options['rtcOfferConstraints'] ?? _rtcOfferConstraints;

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

  if (!_isReadyToReOffer()) {
    return false;
  }

  EventManager handlers = EventManager();
  handlers.on(EventSucceeded(), (EventSucceeded event) {
    if (done != null) {
      done();
    }
  });

  handlers.on(EventCallFailed(), (EventCallFailed event) {
    terminate(<String, dynamic>{
      'cause': dart_sip_c.CausesType.WEBRTC_ERROR,
      'status_code': 500,
      'reason_phrase': 'Media Renegotiation Failed'
    });
  });

  _setLocalMediaStatus();

  if (options['useUpdate'] != null) {
    _sendUpdate(<String, dynamic>{
      'sdpOffer': true,
      'eventHandlers': handlers,
      'rtcOfferConstraints': rtcOfferConstraints,
      'extraHeaders': options['extraHeaders']
    });
  } else {
    _sendReinvite(<String, dynamic>{
      'eventHandlers': handlers,
      'rtcOfferConstraints': rtcOfferConstraints,
      'extraHeaders': options['extraHeaders']
    });
  }

  return true;
}