On 03/30/2016 03:47 PM, Igor Olhovskiy wrote:
Oh… Node. Too async for me ) But thanks.
Yeah, I know. But look how easy - seductively easy. :)
---
function LRNquery(tn, req, res) { sip.send({ method: 'INVITE', uri: 'sip:' + tn + '@208.52.173.7:5062', version: '2.0', headers: { from: { name: 'node', uri: 'sip:node@172.30.106.108:5060', params: { tag: 'abcxyz123444' } },
to: { name: 'redirect', uri: 'sip:redirect@208.52.173.7:5062', params: {} },
'call-id': '9995551232344523@172.30.106.108', cseq: { seq: 1, method: 'INVITE' }, contact: [ { name: undefined, uri: 'sip:node@172.30.106.108:5081', params: {} } ] } }, function(rs) { if(rs.status == 302 && 'headers' in rs && 'contact' in rs.headers && rs.headers.contact.length > 0) { var contact = rs.headers.contact.shift();
var lrn = contact.uri.match(/rn=(\d+)/);
if(lrn) { res.writeHead(200, 'OK', { 'Content-Length': lrn[1].length });
res.end(lrn[1]); return; } }
res.writeHead(500, 'Internal Server Error'); res.end(); }); }