add custom nye headers to completed hook (#1552)

This commit is contained in:
Sam Machin
2026-05-21 10:02:28 -04:00
committed by GitHub
parent c1a7f1146a
commit d84690dfb1
6 changed files with 60 additions and 16 deletions
+17 -3
View File
@@ -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) {