Skip to content

Instantly share code, notes, and snippets.

@WhiteyDude
Created June 8, 2019 16:16
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 WhiteyDude/8dfe7c612cafa7dbf6f3970d5f8d946e to your computer and use it in GitHub Desktop.
Save WhiteyDude/8dfe7c612cafa7dbf6f3970d5f8d946e to your computer and use it in GitHub Desktop.
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