Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davehorton/1b93ace680c049d740d646bf9976492c to your computer and use it in GitHub Desktop.
Save davehorton/1b93ace680c049d740d646bf9976492c to your computer and use it in GitHub Desktop.
simplified app.js
const Srf = require('drachtio-srf');
const srf = new Srf();
const SipError = Srf.SipError;
srf.invite((req, res) => {
console.log(`Received an Invite from ${req.source_address}:${req.source_port}`);
if (req.body.includes('Conferencing Control Leg')) {
handleControlLegInvite(req, res);
}
else {
handleMediaLegInvite(req, res);
}
});
async function handleMediaLegInvite(req, res) {
console.log('Handling Media Leg Invite`');
try {
const {uas, uac} = await srf.createB2BUA(req, res, 'sip:1234@192.168.47.161:5063', {
headers: {
'User-Agent': 'drachtio/iechyd-da',
'X-Linked-UUID': '1e2587c'
}
});
console.log('call connected');
uas.on('info', handleInfo.bind(uas));
[uas, uac].forEach((dlg) => dlg.on('destroy', () => {
console.log('call ended');
dlg.other.destroy();
}));
} catch (err) {
if (err instanceof SipError) {
console.log(`failed connecting call to media server; sip status: ${err.status}`);
}
else {
console.error(err, 'Unexpected error connecting call');
}
}
function handleInfo(req, res) {
console.log('Processing INFO. MSML=', req.body);
res.send(200, 'OK', {
headers: {
'Content-Type': 'application/msml+xml'
},
body: "<MSML value='response=200'/>"
});
parser.parseString(req.body, function (err, result) {
// console.log('Error =', err);
// console.log('Parsed to JSON =', JSON.stringify(result,null,2));
parseJSON(result.msml, this.sip.callId, this.id);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment