Skip to content

Instantly share code, notes, and snippets.

@davehorton
Last active July 3, 2019 12:53
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/64b9508b1136947bbeaca579e6d34b8f to your computer and use it in GitHub Desktop.
Save davehorton/64b9508b1136947bbeaca579e6d34b8f to your computer and use it in GitHub Desktop.
drachtio-srf snippets
/**
* How to cancel an outbound call
*
* Note: example below illustrates using srf.createUAC, but the same logic and callback is available
* for srf.createB2BUA
*
* For another example, see https://drachtio.org/api#srf-create-uac and the last example there
*/
let dlg, reqSent, timer;
srf.createUAC(uri, {
localSdp: mySdp
}, (err, r) => {
// we get this callback when the request has been sent
// save the request object because we may want to cancel it later
reqSent = r;
})
.then((uac) => {
console.log('call is answered');
if (timer) clearTimeout(timer);
dlg = uac;
dlg.on('destroy', () => console.log('call ended'));
.catch((err) => {
if (timer) clearTimeout(timer);
if (err.status === 487) console.log('call canceled by us');
else console.log(`call rejected with status ${err.status}`);
});
// give 15 seconds to answer
timer = setTimeout(() => {
// see https://drachtio.org/api#sip-request-cancel
reqSent.cancel();
}, 15000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment