From 38185426e2a989d835beda8e215b973d0235d6e9 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Sat, 7 Jan 2023 14:49:59 -0500 Subject: [PATCH] further fixes for #210 --- lib/session/call-session.js | 14 ++++++++++---- lib/utils/http-requestor.js | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 194ce1c4..645fedcb 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -82,12 +82,18 @@ class CallSession extends Emitter { this._pool = srf.locals.dbHelpers.pool; + const handover = (newRequestor) => { + this.logger.info(`handover to new base url ${newRequestor.url}`); + this.requestor.removeAllListeners(); + this.application.requestor = newRequestor; + this.requestor.on('command', this._onCommand.bind(this)); + this.requestor.on('connection-dropped', this._onWsConnectionDropped.bind(this)); + this.requestor.on('handover', handover.bind(this)); + }; + 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; - }); + this.requestor.on('handover', handover.bind(this)); } /** diff --git a/lib/utils/http-requestor.js b/lib/utils/http-requestor.js index 68e8e2c4..6e71e0ff 100644 --- a/lib/utils/http-requestor.js +++ b/lib/utils/http-requestor.js @@ -101,7 +101,7 @@ class HttpRequestor extends BaseRequestor { this.close(); this.emit('handover', requestor); } - return requestor.request(type, hook, params, httpHeaders); + return requestor.request('session:new', hook, params, httpHeaders); } let newClient;