Skip to content

Instantly share code, notes, and snippets.

@WhiteyDude
Created Jun 8, 2019
Embed
What would you like to do?
calls = require('./calls')
srf.invite((req, res) => {
const ms = req.app.locals.ms;
ms.connectCaller(req, res, next)
.then(({endpoint, dialog}) => {
setHandlers(req, res, dialog, endpoint)
to = calls.parseURI(req.msg.headers.to);
to_number = calls.convertToE164(to.user)
calls.check_is_valid(to_number)
.then((number) => {
if (!number) {
console.log(`[${req.callid}] ${to_number} does not match`)
calls.playback_failure(endpoint)
.then(() => {
hangup(endpoint, dialog, req.callid);
// Stop execution somehow?
});
}
console.log("Never get here")
});
}); // End ms.ConnectCaller
}); // End invite
function hangup(endpoint, dialog, call_id) {
if (call_id) console.log(`[${call_id}] Destroying ${call_id} from hangup function`)
if (dialog) dialog.destroy()
if (endpoint) endpoint.destroy
return true
}
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