added call_termination_by on app call status (#168)

Co-authored-by: Joan Salvatella <joan@bookline.io>
This commit is contained in:
Joan
2022-09-23 09:13:55 +02:00
committed by GitHub
parent 32714d73f3
commit c2c8f00978
4 changed files with 9 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ class CallInfo {
let srf; let srf;
this.direction = opts.direction; this.direction = opts.direction;
this.traceId = opts.traceId; this.traceId = opts.traceId;
this.callTerminationBy = undefined;
if (opts.req) { if (opts.req) {
const u = opts.req.getParsedHeader('from'); const u = opts.req.getParsedHeader('from');
const uri = parseUri(u.uri); const uri = parseUri(u.uri);
@@ -119,7 +120,7 @@ class CallInfo {
applicationSid: this.applicationSid, applicationSid: this.applicationSid,
fsSipAddress: this.localSipAddress fsSipAddress: this.localSipAddress
}; };
['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName'].forEach((prop) => { ['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName', 'callTerminationBy'].forEach((prop) => {
if (this[prop]) obj[prop] = this[prop]; if (this[prop]) obj[prop] = this[prop];
}); });
if (typeof this.duration === 'number') obj.duration = this.duration; if (typeof this.duration === 'number') obj.duration = this.duration;

View File

@@ -638,6 +638,7 @@ class CallSession extends Emitter {
this._onTasksDone(); this._onTasksDone();
this._clearResources(); this._clearResources();
if (!this.isConfirmCallSession && !this.isSmsCallSession) sessionTracker.remove(this.callSid); if (!this.isConfirmCallSession && !this.isSmsCallSession) sessionTracker.remove(this.callSid);
} }
@@ -1188,6 +1189,7 @@ class CallSession extends Emitter {
} catch (err) { } catch (err) {
if (err === CALLER_CANCELLED_ERR_MSG) { if (err === CALLER_CANCELLED_ERR_MSG) {
this.logger.error(err, 'caller canceled quickly before we could respond, ending call'); this.logger.error(err, 'caller canceled quickly before we could respond, ending call');
this.callInfo.callTerminationBy = 'caller';
this._notifyCallStatusChange({ this._notifyCallStatusChange({
callStatus: CallStatus.NoAnswer, callStatus: CallStatus.NoAnswer,
sipStatus: 487, sipStatus: 487,
@@ -1495,8 +1497,9 @@ class CallSession extends Emitter {
dlg.connected = false; dlg.connected = false;
dlg.destroy = origDestroy; dlg.destroy = origDestroy;
const duration = moment().diff(this.dlg.connectTime, 'seconds'); const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.callInfo.callTerminationBy = 'jambonz';
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration}); 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'}); this.rootSpan.setAttributes({'call.termination': 'hangup by jambonz'});
origDestroy().catch((err) => this.logger.info({err}, 'CallSession - error destroying dialog')); origDestroy().catch((err) => this.logger.info({err}, 'CallSession - error destroying dialog'));
if (this.wakeupResolver) { if (this.wakeupResolver) {

View File

@@ -34,6 +34,7 @@ class InboundCallSession extends CallSession {
_onCancel() { _onCancel() {
this.rootSpan.setAttributes({'call.termination': 'caller abandoned'}); this.rootSpan.setAttributes({'call.termination': 'caller abandoned'});
this.callInfo.callTerminationBy = 'caller';
this._notifyCallStatusChange({ this._notifyCallStatusChange({
callStatus: CallStatus.NoAnswer, callStatus: CallStatus.NoAnswer,
sipStatus: 487, sipStatus: 487,
@@ -69,6 +70,7 @@ class InboundCallSession extends CallSession {
assert(this.dlg.connectTime); assert(this.dlg.connectTime);
const duration = moment().diff(this.dlg.connectTime, 'seconds'); const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.rootSpan.setAttributes({'call.termination': 'hangup by caller'}); this.rootSpan.setAttributes({'call.termination': 'hangup by caller'});
this.callInfo.callTerminationBy = 'caller';
this.emit('callStatusChange', { this.emit('callStatusChange', {
callStatus: CallStatus.Completed, callStatus: CallStatus.Completed,
duration duration

View File

@@ -44,6 +44,7 @@ class RestCallSession extends CallSession {
* This is invoked when the called party hangs up, in order to calculate the call duration. * This is invoked when the called party hangs up, in order to calculate the call duration.
*/ */
_callerHungup() { _callerHungup() {
this.callInfo.callTerminationBy = 'caller';
const duration = moment().diff(this.dlg.connectTime, 'seconds'); const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration}); this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
this.logger.debug('RestCallSession: called party hung up'); this.logger.debug('RestCallSession: called party hung up');