From 15829139c123f00298a96d0d1a3fe6ac5cda5a15 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Fri, 29 Dec 2023 02:59:59 +0700 Subject: [PATCH] fix hangup headers (#583) * fix hangup headers * no need for callback * fix test failure --------- Co-authored-by: Dave Horton --- lib/session/call-session.js | 4 +-- test/docker-compose-testbed.yaml | 4 +-- test/hangup-test.js | 53 ++++++++++++++++++++++++++++++++ test/index.js | 3 +- 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 test/hangup-test.js diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 714b3b1b..70d12838 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -1883,7 +1883,7 @@ Duration=${duration} ` wrapDialog(dlg) { dlg.connectTime = moment(); const origDestroy = dlg.destroy.bind(dlg); - dlg.destroy = () => { + dlg.destroy = (opts) => { if (dlg.connected) { dlg.connected = false; dlg.destroy = origDestroy; @@ -1892,7 +1892,7 @@ Duration=${duration} ` this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration}); this.logger.debug('CallSession: call terminated by jambonz'); this.rootSpan.setAttributes({'call.termination': 'hangup by jambonz'}); - origDestroy().catch((err) => this.logger.info({err}, 'CallSession - error destroying dialog')); + origDestroy(opts).catch((err) => this.logger.info({err}, 'CallSession - error destroying dialog')); if (this.wakeupResolver) { this.wakeupResolver({reason: 'session ended'}); this.wakeupResolver = null; diff --git a/test/docker-compose-testbed.yaml b/test/docker-compose-testbed.yaml index 97e43b9c..e1e3154f 100644 --- a/test/docker-compose-testbed.yaml +++ b/test/docker-compose-testbed.yaml @@ -42,7 +42,7 @@ services: ipv4_address: 172.38.0.7 drachtio: - image: drachtio/drachtio-server:latest + image: drachtio/drachtio-server:0.8.24 restart: always command: drachtio --contact "sip:*;transport=udp" --mtu 4096 --address 0.0.0.0 --port 9022 ports: @@ -57,7 +57,7 @@ services: condition: service_healthy freeswitch: - image: drachtio/drachtio-freeswitch-mrf:latest + image: drachtio/drachtio-freeswitch-mrf:0.6.1 restart: always command: freeswitch --rtp-range-start 20000 --rtp-range-end 20100 environment: diff --git a/test/hangup-test.js b/test/hangup-test.js new file mode 100644 index 00000000..ba78e606 --- /dev/null +++ b/test/hangup-test.js @@ -0,0 +1,53 @@ +const test = require('tape'); +const { sippUac } = require('./sipp')('test_fs'); +const clearModule = require('clear-module'); +const {provisionCallHook, provisionCustomHook} = require('./utils') +const bent = require('bent'); +const getJSON = bent('json') + +process.on('unhandledRejection', (reason, p) => { + console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); +}); + +function connect(connectable) { + return new Promise((resolve, reject) => { + connectable.on('connect', () => { + return resolve(); + }); + }); +} + +test('\'hangup\' custom headers', async(t) => { + clearModule.all(); + const {srf, disconnect} = require('../app'); + + try { + await connect(srf); + + // GIVEN + const verbs = [ + { + verb: 'play', + url: 'https://example.com/example.mp3' + }, + { + "verb": "hangup", + "headers": { + "X-Reason" : "maximum call duration exceeded" + } + } + ]; + + const from = 'hangup_custom_headers'; + await provisionCallHook(from, verbs) + + // THEN + await sippUac('uac-success-received-bye.xml', '172.38.0.10', from); + t.pass('play: succeeds when using single link'); + disconnect(); + } catch (err) { + console.log(`error received: ${err}`); + disconnect(); + t.error(err); + } +}); \ No newline at end of file diff --git a/test/index.js b/test/index.js index fa898493..cfd6b1ea 100644 --- a/test/index.js +++ b/test/index.js @@ -16,7 +16,8 @@ require('./listen-tests'); require('./config-test'); require('./queue-test'); require('./in-dialog-test'); -require('./http-proxy-test'); +require('./hangup-test'); require('./sdp-utils-test'); +require('./http-proxy-test'); require('./remove-test-db'); require('./docker_stop'); \ No newline at end of file