mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-10-09 21:14:37 +00:00
add custom nye headers to completed hook (#1552)
This commit is contained in:
@@ -265,10 +265,11 @@ class SingleDialer extends Emitter {
|
||||
}
|
||||
|
||||
this.dlg
|
||||
.on('destroy', () => {
|
||||
.on('destroy', (req) => {
|
||||
const duration = moment().diff(connectTime, 'seconds');
|
||||
const headers = this._extractCustomHeaders(req);
|
||||
this.logger.debug('SingleDialer:exec called party hung up');
|
||||
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
|
||||
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration, ...(headers && {headers})});
|
||||
this.ep && this.ep.destroy();
|
||||
})
|
||||
.on('refresh', () => this.logger.info('SingleDialer:exec - dialog refreshed by uas'))
|
||||
@@ -530,7 +531,19 @@ class SingleDialer extends Emitter {
|
||||
}
|
||||
}
|
||||
|
||||
_notifyCallStatusChange({callStatus, sipStatus, sipReason, duration}) {
|
||||
_extractCustomHeaders(req) {
|
||||
const dominated = ['via', 'from', 'to', 'call-id', 'cseq', 'max-forwards',
|
||||
'content-length', 'contact', 'route', 'record-route', 'content-type',
|
||||
'authorization', 'proxy-authorization', 'www-authenticate', 'proxy-authenticate'];
|
||||
if (!req || !req.headers) return null;
|
||||
const headers = {};
|
||||
Object.keys(req.headers).forEach((h) => {
|
||||
if (!dominated.includes(h)) headers[h] = req.headers[h];
|
||||
});
|
||||
return Object.keys(headers).length ? headers : null;
|
||||
}
|
||||
|
||||
_notifyCallStatusChange({callStatus, sipStatus, sipReason, duration, headers}) {
|
||||
assert((typeof duration === 'number' && callStatus === CallStatus.Completed) ||
|
||||
(!duration && callStatus !== CallStatus.Completed),
|
||||
'duration MUST be supplied when call completed AND ONLY when call completed');
|
||||
@@ -538,6 +551,7 @@ class SingleDialer extends Emitter {
|
||||
if (this.callInfo) {
|
||||
this.callInfo.updateCallStatus(callStatus, sipStatus, sipReason);
|
||||
if (typeof duration === 'number') this.callInfo.duration = duration;
|
||||
if (headers) this.callInfo.sipHeaders = headers;
|
||||
try {
|
||||
this.notifier.request('call:status', this.application.call_status_hook, this.callInfo.toJSON());
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user