diff --git a/lib/utils/http-requestor.js b/lib/utils/http-requestor.js index 6e71e0ff..1464d4df 100644 --- a/lib/utils/http-requestor.js +++ b/lib/utils/http-requestor.js @@ -2,7 +2,6 @@ const {Client, Pool} = require('undici'); const parseUrl = require('parse-url'); const assert = require('assert'); const BaseRequestor = require('./base-requestor'); -const WsRequestor = require('./ws-requestor'); const {HookMsgTypes} = require('./constants.json'); const snakeCaseKeys = require('./snakecase-keys'); const pools = new Map(); @@ -94,6 +93,7 @@ class HttpRequestor extends BaseRequestor { /* if we have an absolute url, and it is ws then do a websocket connection */ if (this._isAbsoluteUrl(url) && url.startsWith('ws')) { + const WsRequestor = require('./ws-requestor'); this.logger.debug({hook}, 'HttpRequestor: switching to websocket connection'); const h = typeof hook === 'object' ? hook : {url: hook}; const requestor = new WsRequestor(this.logger, this.account_sid, h, this.secret); diff --git a/lib/utils/ws-requestor.js b/lib/utils/ws-requestor.js index d38cbdc9..816599c7 100644 --- a/lib/utils/ws-requestor.js +++ b/lib/utils/ws-requestor.js @@ -4,7 +4,6 @@ const short = require('short-uuid'); const {HookMsgTypes} = require('./constants.json'); const Websocket = require('ws'); const snakeCaseKeys = require('./snakecase-keys'); -const HttpRequestor = require('./http-requestor'); const MAX_RECONNECTS = 5; const RESPONSE_TIMEOUT_MS = process.env.JAMBONES_WS_API_MSG_RESPONSE_TIMEOUT || 5000; @@ -53,6 +52,7 @@ class WsRequestor extends BaseRequestor { /* if we have an absolute url, and it is http then do a standard webhook */ if (this._isAbsoluteUrl(url) && url.startsWith('http')) { + const HttpRequestor = require('./http-requestor'); this.logger.debug({hook}, 'WsRequestor: sending a webhook (HTTP)'); const h = typeof hook === 'object' ? hook : {url: hook}; const requestor = new HttpRequestor(this.logger, this.account_sid, h, this.secret);