send method

void send(
  1. String tone,
  2. Map<String, dynamic> options
)

Implementation

void send(String tone, Map<String, dynamic> options) {
  if (tone == null) {
    throw Exceptions.TypeError('Not enough arguments');
  }

  _direction = 'outgoing';

  // Check RTCSession Status.
  if (_session.status != rtc.C.statusConfirmed &&
      _session.status != rtc.C.statusWaitingForAck) {
    throw Exceptions.InvalidStateError(_session.status);
  }

  print(options);
  List<dynamic> extraHeaders = options['extraHeaders'] != null
      ? Utils.cloneArray(options['extraHeaders'])
      : <dynamic>[];

  _eventHandlers = options['eventHandlers'] ?? EventManager();

  // Check tone value.
  if (!tone.contains(RegExp(r'^[0-9A-DR#*]$'))) {
    throw Exceptions.TypeError('Invalid tone: $tone');
  } else {
    _tone = tone;
  }

  // Duration is checked/corrected in RTCSession.
  _duration = options['duration'];
  _interToneGap = options['interToneGap'];

  if (_mode == DtmfMode.RFC2833) {
    RTCDTMFSender dtmfSender = _session.dtmfSender;
    dtmfSender.insertDTMF(_tone!,
        duration: _duration!, interToneGap: _interToneGap!);
  } else if (_mode == DtmfMode.INFO) {
    extraHeaders.add('Content-Type: application/dtmf-relay');

    String body = 'Signal=$_tone\r\n';

    body += 'Duration=$_duration';

    _session.newDTMF('local', this, _request);

    EventManager handlers = EventManager();
    handlers.on(EventOnSuccessResponse(), (EventOnSuccessResponse event) {
      emit(EventSucceeded(originator: 'remote', response: event.response));
    });
    handlers.on(EventOnErrorResponse(), (EventOnErrorResponse event) {
      _eventHandlers.emit(EventOnFialed());
      emit(EventOnFialed());
      emit(EventCallFailed(originator: 'remote', response: event.response));
    });
    handlers.on(EventOnRequestTimeout(), (EventOnRequestTimeout event) {
      _session.onRequestTimeout();
    });
    handlers.on(EventOnTransportError(), (EventOnTransportError event) {
      _session.onTransportError();
    });

    handlers.on(EventOnDialogError(), (EventOnDialogError event) {
      _session.onDialogError();
    });

    _session.sendRequest(SipMethod.INFO, <String, dynamic>{
      'extraHeaders': extraHeaders,
      'eventHandlers': handlers,
      'body': body
    });
  }
}