Created
June 27, 2019 15:03
-
-
Save davehorton/1b93ace680c049d740d646bf9976492c to your computer and use it in GitHub Desktop.
simplified app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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