From 170c3c7ec4c6d1f653a83f82373c7b403dd377d4 Mon Sep 17 00:00:00 2001 From: Anton Voylenko Date: Tue, 14 Nov 2023 16:16:08 +0200 Subject: [PATCH] rest:dial: Support sipindialog hook (#531) * support sipindialog hook * rename sipindialog method --- lib/tasks/rest_dial.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tasks/rest_dial.js b/lib/tasks/rest_dial.js index bdf2f782..163970c4 100644 --- a/lib/tasks/rest_dial.js +++ b/lib/tasks/rest_dial.js @@ -16,6 +16,7 @@ class TaskRestDial extends Task { this.to = this.data.to; this.call_hook = this.data.call_hook; this.timeout = this.data.timeout || 60; + this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook; this.on('connect', this._onConnect.bind(this)); this.on('callStatus', this._onCallStatus.bind(this)); @@ -64,7 +65,7 @@ class TaskRestDial extends Task { const cs = this.callSession; cs.setDialog(dlg); this.logger.debug('TaskRestDial:_onConnect - call connected'); - + if (this.sipRequestWithinDialogHook) this._initSipRequestWithinDialogHandler(cs, dlg); try { const b3 = this.getTracingPropagation(); const httpHeaders = b3 && {b3}; @@ -142,6 +143,16 @@ class TaskRestDial extends Task { this.logger.error({err}, 'Rest:dial:_onAmdEvent - error calling actionHook'); }); } + + _initSipRequestWithinDialogHandler(cs, dlg) { + cs.sipRequestWithinDialogHook = this.sipRequestWithinDialogHook; + dlg.on('info', this._onRequestWithinDialog.bind(this, cs)); + dlg.on('message', this._onRequestWithinDialog.bind(this, cs)); + } + + async _onRequestWithinDialog(cs, req, res) { + cs._onRequestWithinDialog(req, res); + } } module.exports = TaskRestDial;