Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel reason #10

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# drachtio-fn-b2b-sugar

## :bell: :bell: Warning :bell: :bell:
drachtio-fn-b2b-sugar now gives reasons on cancellations. In order to support that you need to use a version of drachtip-srf above 4.4.21
If you try to use this module without using the correct version of drachtio-srf you will get rejected promises due to errors from within drachtio-srf

A selection of useful and reusable functions dealing with common [B2BUA](https://drachtio.org/api#srf-create-b2bua) scenarios for the [drachtio](https://drachtio.org) SIP server.

## simring function
Expand Down
21 changes: 17 additions & 4 deletions lib/call-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class CallManager extends Emitter {
this.callOpts.calledNumber = opts.req.calledNumber;
}

this.req.on('cancel', () => {
this.req.on('cancel', (res) => {
this._logger.info(`caller hung up, terminating ${this.cip.size} calls in progress`);
this.callerGone = true;
this.killCalls();
this.killCalls(null, res && res.has('Reason') ? res.get('Reason') : null);
});

// this is the Promise we resolve when the simring finally concludes
Expand Down Expand Up @@ -163,7 +163,7 @@ class CallManager extends Emitter {
return p;
}

killCalls(spareMe) {
killCalls(spareMe, reason) {
for (const arr of this.cip) {
const uri = arr[0];
const req = arr[1];
Expand All @@ -173,7 +173,20 @@ class CallManager extends Emitter {
}
else {
this._logger.info(`killing call to ${uri}`);
req.cancel();

if (!reason && this.callAnswered) {
reason = 'SIP;cause=200;text="Call completed elsewhere"';
}

if (reason) {
req.cancel({
headers: {
'Reason': reason
}
});
} else {
req.cancel();
}
}
}
this.cip.clear();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"author": "Dave Horton",
"license": "MIT",
"peerDependencies": {
"drachtio-srf": "^4.4.x"
"drachtio-srf": "^4.4.21"
},
"devDependencies": {
"drachtio-srf": "^4.4.8"
"drachtio-srf": "^4.4.21"
}
}