address general case of sending completed status when we hangup the call

This commit is contained in:
Dave Horton
2020-03-09 21:55:41 +00:00
parent f3926d2c9c
commit 673eebcb2f
3 changed files with 20 additions and 10 deletions

View File

@@ -434,6 +434,7 @@ class CallSession extends Emitter {
uas.callSid = this.callSid;
uas.connectTime = moment();
this.dlg = uas;
this.wrapDialog(this.dlg);
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
this.logger.debug('CallSession:_evalEndpointPrecondition - answered call');
};
@@ -556,6 +557,23 @@ class CallSession extends Emitter {
return {ms: this.ms, ep: this.ep};
}
/**
* Call this whenever we answer the A leg, creating a dialog
* It wraps the 'destroy' method such that if we hang up the A leg
* (e.g. via 'hangup' verb) we emit a callStatusChange event
* @param {SipDialog} dlg
*/
wrapDialog(dlg) {
dlg.connectTime = moment();
const origDestroy = dlg.destroy.bind(dlg);
dlg.destroy = () => {
const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
this.logger.debug('CallSession: call terminated by jambones');
origDestroy();
};
}
/**
* Called any time call status changes. This method both invokes the
* call_status_hook callback as well as updates the realtime database

View File

@@ -46,7 +46,7 @@ class InboundCallSession extends CallSession {
if (!this.dlg) {
assert(this.ep);
this.dlg = await this.srf.createUAS(this.req, this.res, {localSdp: this.ep.local.sdp});
this.dlg.connectTime = moment();
this.wrapDialog(this.dlg);
this.dlg.on('destroy', this._callerHungup.bind(this));
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);

View File

@@ -31,15 +31,7 @@ class RestCallSession extends CallSession {
setDialog(dlg) {
this.dlg = dlg;
dlg.on('destroy', this._callerHungup.bind(this));
dlg.connectTime = moment();
const origDestroy = dlg.destroy.bind(dlg);
dlg.destroy = () => {
const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
this.logger.debug('RestCallSession: call terminated by jambones');
origDestroy();
};
this.wrapDialog(dlg);
}
/**