Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2013 21:19
Show Gist options
  • Save anonymous/6394383 to your computer and use it in GitHub Desktop.
Save anonymous/6394383 to your computer and use it in GitHub Desktop.
var sip = require('sip');
var digest = require('sip/digest');
var util = require('util');
var dns = require('dns');
var registry = {};
sip.start({}, function(rq) {
try {
if(rq.method === 'INVITE') {
var username = sip.parseUri(rq.uri).user;
var domain = sip.parseUri(rq.uri).host;
dns.resolveTxt('sip-'+username+'.'+domain, function (err, addresses) {
if (err) throw err;
addresses.every(function (a) {
var rs = sip.makeResponse(rq, 302, 'Moved Temporarily');
rs.headers = rq.headers;
rs.headers.contact = 'sip:'+a;
rs.content = rq.content;
sip.send(rs);
if (err) {
throw err;
}
return false;
});
});
}
else {
sip.send(sip.makeResponse(rq, 405, 'Method Not Allowed'));
}
} catch(e) {
util.debug(e);
util.debug(e.stack);
sip.send(sip.makeResponse(rq, 500, "Server Internal Error"));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment