Last active
June 9, 2019 07:10
-
-
Save davehorton/c4d99329c43f8530c4e3f0ed95fe3189 to your computer and use it in GitHub Desktop.
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 calls = require('./calls'); | |
srf.invite(async(req, res) => { | |
const ms = req.app.locals.ms; | |
const to_number = calls.convertToE164(req.calledNumber); | |
let ep, dlg; | |
try { | |
const {endpoint, dialog} = await ms.connectCaller(req, res); | |
ep = endpoint; | |
dlg = dialog; | |
const number = await calls.check_is_valid(to_number); | |
if (!number) { | |
console.log(`[${req.callid}] ${to_number} does not match`) | |
await calls.playback_failure(endpoint); | |
dialog.destroy(); | |
endpoint.destroy(); | |
} | |
else { | |
setHandlers(req, res, dialog, endpoint); | |
} | |
} catch (err) { | |
console.error(err, 'Error connecting call to media server'); | |
res.send(503); | |
if (dlg) dlg.destroy(); | |
if (ep) ep.destroy(); | |
} | |
}); | |
function setHandlers(req, res, dialog, endpoint) { | |
dialog.on('destroy', () => { | |
console.log(`Received BYE, deleting ${req.callid}`) | |
endpoint.destroy(); | |
// calls.delete_call(req.call_id); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment