From 78a76bb1f42e986b4c3ff0121ca1c3b67d72ab8b Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 9 Dec 2022 10:55:22 -0500 Subject: [PATCH] bugfix: when handing over from wss to http close the wss socket --- lib/session/call-session.js | 4 ++++ lib/utils/ws-requestor.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 82338a88..af32cde9 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -83,6 +83,10 @@ class CallSession extends Emitter { this.requestor.on('command', this._onCommand.bind(this)); this.requestor.on('connection-dropped', this._onWsConnectionDropped.bind(this)); + this.requestor.on('handover', (newRequestor) => { + this.logger.info(`handover to new base url ${newRequestor.url}`); + this.application.requestor = newRequestor; + }); } /** diff --git a/lib/utils/ws-requestor.js b/lib/utils/ws-requestor.js index 9946f6f7..fba4761d 100644 --- a/lib/utils/ws-requestor.js +++ b/lib/utils/ws-requestor.js @@ -55,6 +55,11 @@ class WsRequestor extends BaseRequestor { if (this._isAbsoluteUrl(url) && url.startsWith('http')) { this.logger.debug({hook}, 'WsRequestor: sending a webhook (HTTP)'); const requestor = new HttpRequestor(this.logger, this.account_sid, hook, this.secret); + //const requestor = new HttpRequestor(this.logger, this.account_sid, {url: hook}, this.secret); + if (type === 'session:redirect') { + this.close(); + this.emit('handover', requestor); + } return requestor.request(type, hook, params, httpHeaders); }