From c2c8f00978fa05ce5171a381712350834dd3622c Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 23 Sep 2022 09:13:55 +0200 Subject: [PATCH] added call_termination_by on app call status (#168) Co-authored-by: Joan Salvatella --- lib/session/call-info.js | 3 ++- lib/session/call-session.js | 5 ++++- lib/session/inbound-call-session.js | 2 ++ lib/session/rest-call-session.js | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/session/call-info.js b/lib/session/call-info.js index dcf31ce9..f4f0ae9e 100644 --- a/lib/session/call-info.js +++ b/lib/session/call-info.js @@ -11,6 +11,7 @@ class CallInfo { let srf; this.direction = opts.direction; this.traceId = opts.traceId; + this.callTerminationBy = undefined; if (opts.req) { const u = opts.req.getParsedHeader('from'); const uri = parseUri(u.uri); @@ -119,7 +120,7 @@ class CallInfo { applicationSid: this.applicationSid, fsSipAddress: this.localSipAddress }; - ['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName'].forEach((prop) => { + ['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName', 'callTerminationBy'].forEach((prop) => { if (this[prop]) obj[prop] = this[prop]; }); if (typeof this.duration === 'number') obj.duration = this.duration; diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 8d5c2f92..7d25ec11 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -638,6 +638,7 @@ class CallSession extends Emitter { this._onTasksDone(); this._clearResources(); + if (!this.isConfirmCallSession && !this.isSmsCallSession) sessionTracker.remove(this.callSid); } @@ -1188,6 +1189,7 @@ class CallSession extends Emitter { } catch (err) { if (err === CALLER_CANCELLED_ERR_MSG) { this.logger.error(err, 'caller canceled quickly before we could respond, ending call'); + this.callInfo.callTerminationBy = 'caller'; this._notifyCallStatusChange({ callStatus: CallStatus.NoAnswer, sipStatus: 487, @@ -1495,8 +1497,9 @@ class CallSession extends Emitter { dlg.connected = false; dlg.destroy = origDestroy; const duration = moment().diff(this.dlg.connectTime, 'seconds'); + this.callInfo.callTerminationBy = 'jambonz'; this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration}); - this.logger.debug('CallSession: call terminated by jambones'); + this.logger.debug('CallSession: call terminated by jambonz'); this.rootSpan.setAttributes({'call.termination': 'hangup by jambonz'}); origDestroy().catch((err) => this.logger.info({err}, 'CallSession - error destroying dialog')); if (this.wakeupResolver) { diff --git a/lib/session/inbound-call-session.js b/lib/session/inbound-call-session.js index 1db790dd..92fedf65 100644 --- a/lib/session/inbound-call-session.js +++ b/lib/session/inbound-call-session.js @@ -34,6 +34,7 @@ class InboundCallSession extends CallSession { _onCancel() { this.rootSpan.setAttributes({'call.termination': 'caller abandoned'}); + this.callInfo.callTerminationBy = 'caller'; this._notifyCallStatusChange({ callStatus: CallStatus.NoAnswer, sipStatus: 487, @@ -69,6 +70,7 @@ class InboundCallSession extends CallSession { assert(this.dlg.connectTime); const duration = moment().diff(this.dlg.connectTime, 'seconds'); this.rootSpan.setAttributes({'call.termination': 'hangup by caller'}); + this.callInfo.callTerminationBy = 'caller'; this.emit('callStatusChange', { callStatus: CallStatus.Completed, duration diff --git a/lib/session/rest-call-session.js b/lib/session/rest-call-session.js index 3acf7400..b19552ff 100644 --- a/lib/session/rest-call-session.js +++ b/lib/session/rest-call-session.js @@ -44,6 +44,7 @@ class RestCallSession extends CallSession { * This is invoked when the called party hangs up, in order to calculate the call duration. */ _callerHungup() { + this.callInfo.callTerminationBy = 'caller'; const duration = moment().diff(this.dlg.connectTime, 'seconds'); this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration}); this.logger.debug('RestCallSession: called party hung up');