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

Forward cancellation reason in simring #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
24 changes: 17 additions & 7 deletions lib/call-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class CallManager extends Emitter {
this.callOpts.calledNumber = opts.req.calledNumber;
}

this.req.on('cancel', () => {
this._logger.info(`caller hung up, terminating ${this.cip.size} calls in progress`);
this.req.on('cancel', (cancelReq) => {
const cancelReason = cancelReq.getParsedHeader('Reason');
jonastelzio marked this conversation as resolved.
Show resolved Hide resolved
this._logger.info(`caller hung up, terminating ${this.cip.size} calls in progress with reason ${cancelReason}`);
this.callerGone = true;
this.killCalls();
this.killCalls(null, cancelReason);
});

// this is the Promise we resolve when the simring finally concludes
Expand Down Expand Up @@ -125,7 +126,7 @@ class CallManager extends Emitter {
}
this.callAnswered = true;
uac = dlg;
this.killCalls(uri);
this.killCalls(uri, 'SIP;cause=200;text="Call completed elsewhere');
this.cip.delete(uri);
if (timer) clearTimeout(timer);

Expand Down Expand Up @@ -164,7 +165,7 @@ class CallManager extends Emitter {
return p;
}

killCalls(spareMe) {
killCalls(spareMe, cancelReason) {
for (const arr of this.cip) {
const uri = arr[0];
const req = arr[1];
Expand All @@ -173,8 +174,17 @@ class CallManager extends Emitter {
this._logger.info(`not killing call to ${uri} because we were asked to spare it`);
}
else {
this._logger.info(`killing call to ${uri}`);
req.cancel();
this._logger.info(`killing call to ${uri} with reason ${cancelReason}`);
if (cancelReason) {
req.cancel({
headers: {
'Reason': cancelReason
}
});
}
else {
req.cancel();
}
}
}
this.cip.clear();
Expand Down