[SR-Users] Framework/Lib to create SIP packets

Alex Balashov abalashov at evaristesys.com
Wed Mar 30 21:52:57 CEST 2016


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 at 172.30.106.108:5060',
				params: { tag: 'abcxyz123444' }
			},

			to: {
				name: 'redirect',
				uri: 'sip:redirect at 208.52.173.7:5062',
				params: {}
			},

			'call-id': '9995551232344523 at 172.30.106.108',
			cseq: { seq: 1, method: 'INVITE' },
			contact: [ {
				name: undefined,
				uri: 'sip:node at 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();
	});
}

-- 
Alex Balashov | Principal | Evariste Systems LLC
1447 Peachtree Street NE, Suite 700
Atlanta, GA 30309
United States

Tel: +1-800-250-5920 (toll-free) / +1-678-954-0671 (direct)
Web: http://www.evaristesys.com/, http://www.csrpswitch.com/



More information about the sr-users mailing list