mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
address general case of sending completed status when we hangup the call
This commit is contained in:
@@ -434,6 +434,7 @@ class CallSession extends Emitter {
|
|||||||
uas.callSid = this.callSid;
|
uas.callSid = this.callSid;
|
||||||
uas.connectTime = moment();
|
uas.connectTime = moment();
|
||||||
this.dlg = uas;
|
this.dlg = uas;
|
||||||
|
this.wrapDialog(this.dlg);
|
||||||
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
|
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
|
||||||
this.logger.debug('CallSession:_evalEndpointPrecondition - answered call');
|
this.logger.debug('CallSession:_evalEndpointPrecondition - answered call');
|
||||||
};
|
};
|
||||||
@@ -556,6 +557,23 @@ class CallSession extends Emitter {
|
|||||||
return {ms: this.ms, ep: this.ep};
|
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
|
* Called any time call status changes. This method both invokes the
|
||||||
* call_status_hook callback as well as updates the realtime database
|
* call_status_hook callback as well as updates the realtime database
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class InboundCallSession extends CallSession {
|
|||||||
if (!this.dlg) {
|
if (!this.dlg) {
|
||||||
assert(this.ep);
|
assert(this.ep);
|
||||||
this.dlg = await this.srf.createUAS(this.req, this.res, {localSdp: this.ep.local.sdp});
|
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.dlg.on('destroy', this._callerHungup.bind(this));
|
||||||
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
|
this.emit('callStatusChange', {sipStatus: 200, callStatus: CallStatus.InProgress});
|
||||||
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
|
this.logger.debug(`CallSession:propagateAnswer - answered callSid ${this.callSid}`);
|
||||||
|
|||||||
@@ -31,15 +31,7 @@ class RestCallSession extends CallSession {
|
|||||||
setDialog(dlg) {
|
setDialog(dlg) {
|
||||||
this.dlg = dlg;
|
this.dlg = dlg;
|
||||||
dlg.on('destroy', this._callerHungup.bind(this));
|
dlg.on('destroy', this._callerHungup.bind(this));
|
||||||
dlg.connectTime = moment();
|
this.wrapDialog(dlg);
|
||||||
|
|
||||||
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();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user