From 8671592deba88637320dd78992960f7c9123fb45 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Thu, 7 Nov 2019 13:40:01 +0000 Subject: [PATCH 1/3] set correct cancel reason if answered Set Reason header to SIP;cause=200;text="Call completed elsewhere" if the call has been answered --- lib/call-manager.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/call-manager.js b/lib/call-manager.js index d6ca881..f378968 100644 --- a/lib/call-manager.js +++ b/lib/call-manager.js @@ -173,7 +173,15 @@ class CallManager extends Emitter { } else { this._logger.info(`killing call to ${uri}`); - req.cancel(); + if (this.callAnswered) { + req.cancel({ + headers: { + 'Reason': 'SIP;cause=200;text="Call completed elsewhere"' + } + }); + } else { + req.cancel(); + } } } this.cip.clear(); From 25795ba7645995daecbd471f7031126aa6ea5399 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Fri, 8 Nov 2019 09:59:37 +0000 Subject: [PATCH 2/3] propagate the Reason header if got one in cancel --- lib/call-manager.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/call-manager.js b/lib/call-manager.js index f378968..d0ee0ec 100644 --- a/lib/call-manager.js +++ b/lib/call-manager.js @@ -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.has('Reason') ? res.get('Reason') : null); }); // this is the Promise we resolve when the simring finally concludes @@ -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]; @@ -173,10 +173,15 @@ class CallManager extends Emitter { } else { this._logger.info(`killing call to ${uri}`); - if (this.callAnswered) { + + if (!reason && this.callAnswered) { + reason = 'SIP;cause=200;text="Call completed elsewhere"'; + } + + if (reason) { req.cancel({ headers: { - 'Reason': 'SIP;cause=200;text="Call completed elsewhere"' + 'Reason': reason } }); } else { From c47d00b26c4f34b3366fe06377081fc6d2344895 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Wed, 13 Nov 2019 14:22:24 +0000 Subject: [PATCH 3/3] Enable reasons on cancellations in simringer --- README.md | 4 ++++ lib/call-manager.js | 2 +- package.json | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 87c3ea8..b15fdd9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/call-manager.js b/lib/call-manager.js index d0ee0ec..9ab4c72 100644 --- a/lib/call-manager.js +++ b/lib/call-manager.js @@ -34,7 +34,7 @@ class CallManager extends Emitter { this.req.on('cancel', (res) => { this._logger.info(`caller hung up, terminating ${this.cip.size} calls in progress`); this.callerGone = true; - this.killCalls(null, res.has('Reason') ? res.get('Reason') : null); + this.killCalls(null, res && res.has('Reason') ? res.get('Reason') : null); }); // this is the Promise we resolve when the simring finally concludes diff --git a/package.json b/package.json index 558b2e9..1518eab 100644 --- a/package.json +++ b/package.json @@ -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" } }