init_incoming method
Implementation
void init_incoming(IncomingRequest request,
[Function(RTCSession)? initCallback]) {
logger.debug('init_incoming()');
int? expires;
String? contentType = request.getHeader('Content-Type');
// Check body and content type.
if (request.body != null && (contentType != 'application/sdp')) {
request.reply(415);
return;
}
// Session parameter initialization.
_status = C.statusInviteReceived;
_from_tag = request.from_tag;
_id = request.call_id! + _from_tag!;
_request = request;
_contact = _ua!.contact.toString();
// Get the Expires header value if exists.
if (request.hasHeader('expires')) {
expires = request.getHeader('expires') * 1000;
}
/* Set the to_tag before
* replying a response code that will create a dialog.
*/
request.to_tag = utils.newTag();
// An error on dialog creation will fire 'failed' event.
if (!_createDialog(request, 'UAS', true)) {
request.reply(500, 'Missing Contact header field');
return;
}
if (request.body != null) {
_late_sdp = false;
} else {
_late_sdp = true;
}
_status = C.statusWaitingForAnswer;
// Set userNoAnswerTimer.
_timers.userNoAnswerTimer = setTimeout(() {
request.reply(408);
_failed('local', null, null, null, 408, dart_sip_c.CausesType.NO_ANSWER,
'No Answer');
}, _ua!.configuration!.noAnswerTimeout);
/* Set expiresTimer
* RFC3261 13.3.1
*/
if (expires != null) {
_timers.expiresTimer = setTimeout(() {
if (_status == C.statusWaitingForAnswer) {
request.reply(487);
_failed('system', null, null, null, 487,
dart_sip_c.CausesType.EXPIRES, 'Timeout');
}
}, expires);
}
// Set internal properties.
_direction = 'incoming';
_local_identity = request.to;
_remote_identity = request.from;
// A init callback was specifically defined.
if (initCallback != null) {
initCallback(this);
}
// Fire 'newRTCSession' event.
_newRTCSession('remote', request);
// The user may have rejected the call in the 'newRTCSession' event.
if (_status == C.statusTerminated) {
return;
}
// Reply 180.
request.reply(180, null, <dynamic>['Contact: $_contact']);
// Fire 'progress' event.
// TODO(cloudwebrtc): Document that 'response' field in 'progress' event is null for incoming calls.
_progress('local', null);
}