mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
38 lines
1003 B
JavaScript
38 lines
1003 B
JavaScript
const CallSession = require('./call-session');
|
|
const {CallStatus} = require('../utils/constants');
|
|
const moment = require('moment');
|
|
|
|
class RestCallSession extends CallSession {
|
|
constructor({logger, application, srf, req, ep, tasks, callInfo}) {
|
|
super({
|
|
logger,
|
|
application,
|
|
srf,
|
|
callSid: callInfo.callSid,
|
|
tasks,
|
|
callInfo
|
|
});
|
|
this.req = req;
|
|
this.ep = ep;
|
|
|
|
this.on('callStatusChange', this._notifyCallStatusChange.bind(this));
|
|
this._notifyCallStatusChange({callStatus: CallStatus.Trying, sipStatus: 100});
|
|
}
|
|
|
|
setDialog(dlg) {
|
|
this.dlg = dlg;
|
|
dlg.on('destroy', this._callerHungup.bind(this));
|
|
dlg.connectTime = moment();
|
|
}
|
|
|
|
_callerHungup() {
|
|
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
|
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
|
|
this.logger.debug('InboundCallSession: caller hung up');
|
|
this._callReleased();
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = RestCallSession;
|