bugfix: when handing over from wss to http close the wss socket

This commit is contained in:
Dave Horton
2022-12-09 10:55:22 -05:00
parent 39fb762a15
commit 78a76bb1f4
2 changed files with 9 additions and 0 deletions

View File

@@ -83,6 +83,10 @@ class CallSession extends Emitter {
this.requestor.on('command', this._onCommand.bind(this)); this.requestor.on('command', this._onCommand.bind(this));
this.requestor.on('connection-dropped', this._onWsConnectionDropped.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;
});
} }
/** /**

View File

@@ -55,6 +55,11 @@ class WsRequestor extends BaseRequestor {
if (this._isAbsoluteUrl(url) && url.startsWith('http')) { if (this._isAbsoluteUrl(url) && url.startsWith('http')) {
this.logger.debug({hook}, 'WsRequestor: sending a webhook (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, 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); return requestor.request(type, hook, params, httpHeaders);
} }