Last active
July 3, 2019 12:53
-
-
Save davehorton/64b9508b1136947bbeaca579e6d34b8f to your computer and use it in GitHub Desktop.
drachtio-srf snippets
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
/** | |
* 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