reply_sl method
Stateless reply. -param {Number} code status code -param {String} reason reason phrase
Implementation
void reply_sl(int code, [String? reason]) {
List<dynamic> vias = getHeaders('via');
// Validate code and reason values.
if (code == null || (code < 100 || code > 699)) {
throw Exceptions.TypeError('Invalid status_code: $code');
} else if (reason != null) {
throw Exceptions.TypeError('Invalid reason_phrase: $reason');
}
reason = reason ?? DartSIP_C.REASON_PHRASE[code] ?? '';
String response = 'SIP/2.0 $code $reason\r\n';
for (dynamic via in vias) {
response += 'Via: $via\r\n';
}
dynamic to = getHeader('To');
if (to_tag == null && code > 100) {
to += ';tag=${utils.newTag()}';
} else if (to_tag != null && !s('to').hasParam('tag')) {
to += ';tag=$to_tag';
}
response += 'To: $to\r\n';
response += 'From: ${getHeader('From')}\r\n';
response += 'Call-ID: $call_id\r\n';
response += 'CSeq: $cseq ${SipMethodHelper.getName(method)}\r\n';
response += 'Content-Length: ${0}\r\n\r\n';
transport!.send(response);
}