send method
Implementation
void send(String target, String body, [Map<String, dynamic>? options]) {
String originalTarget = target;
options = options ?? <String, dynamic>{};
if (target == null || body == null) {
throw Exceptions.TypeError('Not enough arguments');
}
// Check target validity.
URI? normalized = _ua!.normalizeTarget(target);
if (normalized == null) {
throw Exceptions.TypeError('Invalid target: $originalTarget');
}
// Get call options.
List<dynamic> extraHeaders = Utils.cloneArray(options['extraHeaders']);
EventManager eventHandlers = options['eventHandlers'] ?? EventManager();
String contentType = options['contentType'] ?? 'text/plain';
// Set event handlers.
addAllEventHandlers(eventHandlers);
extraHeaders.add('Content-Type: $contentType');
_request =
OutgoingRequest(SipMethod.MESSAGE, normalized, _ua, null, extraHeaders);
if (body != null) {
_request.body = body;
}
EventManager handlers = EventManager();
handlers.on(EventOnRequestTimeout(), (EventOnRequestTimeout value) {
_onRequestTimeout();
});
handlers.on(EventOnTransportError(), (EventOnTransportError value) {
_onTransportError();
});
handlers.on(EventOnReceiveResponse(), (EventOnReceiveResponse event) {
_receiveResponse(event.response);
});
RequestSender request_sender = RequestSender(_ua!, _request, handlers);
_newMessage('local', _request);
request_sender.send();
}