botium-connector-voip 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -236,21 +236,31 @@ class BotiumConnectorVoip {
|
|
|
236
236
|
let httpInitRetries = 0;
|
|
237
237
|
const connectHttp = async retryIndex => {
|
|
238
238
|
retryIndex = retryIndex || 0;
|
|
239
|
+
let initCallUrl = '';
|
|
239
240
|
try {
|
|
240
241
|
const workerUrl = this.caps[Capabilities.VOIP_USE_GLOBAL_VOIP_WORKER] ? process.env.BOTIUM_VOIP_WORKER_URL : this.caps[Capabilities.VOIP_WORKER_URL].replace('wss', 'https').replace('ws', 'http');
|
|
241
242
|
const baseUrl = workerUrl.endsWith('/') ? workerUrl.slice(0, -1) : workerUrl;
|
|
243
|
+
initCallUrl = `${baseUrl}/initCall`;
|
|
244
|
+
const postPayload = {
|
|
245
|
+
API_KEY: this.caps[Capabilities.VOIP_USE_GLOBAL_VOIP_WORKER] ? process.env.BOTIUM_VOIP_WORKER_APIKEY : this.caps[Capabilities.VOIP_WORKER_APIKEY]
|
|
246
|
+
};
|
|
247
|
+
const payloadForLog = {
|
|
248
|
+
...postPayload,
|
|
249
|
+
API_KEY: postPayload.API_KEY != null && postPayload.API_KEY !== '' ? '[REDACTED]' : postPayload.API_KEY
|
|
250
|
+
};
|
|
251
|
+
debug$3(`HTTP initCall: POST ${initCallUrl} payload=${JSON.stringify(payloadForLog)}`);
|
|
242
252
|
const res = await axios__default["default"]({
|
|
243
253
|
method: 'post',
|
|
244
|
-
data:
|
|
245
|
-
|
|
246
|
-
},
|
|
247
|
-
url: `${baseUrl}/initCall`
|
|
254
|
+
data: postPayload,
|
|
255
|
+
url: initCallUrl
|
|
248
256
|
});
|
|
249
257
|
if (res) {
|
|
250
258
|
data = res.data;
|
|
251
259
|
headers = res.headers;
|
|
260
|
+
debug$3(`HTTP initCall: response status=${res.status} data=${this._getAxiosShortenedOutput(res.data)}`);
|
|
252
261
|
}
|
|
253
262
|
} catch (err) {
|
|
263
|
+
debug$3(`HTTP initCall: failed ${initCallUrl} — ${this._getAxiosErrOutput(err)}`);
|
|
254
264
|
debug$3(`Retry ${retryIndex} / ${this.caps[Capabilities.VOIP_WEBSOCKET_CONNECT_MAXRETRIES]}: Connecting to VOIP Worker failed: ${err.message || 'Not reachable'}`);
|
|
255
265
|
if (retryIndex === this.caps[Capabilities.VOIP_WEBSOCKET_CONNECT_MAXRETRIES]) {
|
|
256
266
|
throw new Error(`Connecting to VOIP Worker failed: ${err.message || 'Not reachable'}`);
|
|
@@ -275,7 +285,15 @@ class BotiumConnectorVoip {
|
|
|
275
285
|
const connectWs = retryIndex => {
|
|
276
286
|
retryIndex = retryIndex || 0;
|
|
277
287
|
return new Promise((resolve, reject) => {
|
|
278
|
-
|
|
288
|
+
const useCookie = headers && 'set-cookie' in headers;
|
|
289
|
+
const connectPayload = useCookie ? {
|
|
290
|
+
withCookie: true,
|
|
291
|
+
cookieSize: headers['set-cookie'] && String(headers['set-cookie']).length || 0
|
|
292
|
+
} : {
|
|
293
|
+
withCookie: false
|
|
294
|
+
};
|
|
295
|
+
debug$3(`WebSocket connect: url=${wsEndpoint} attempt=${retryIndex + 1} max=${this.caps[Capabilities.VOIP_WEBSOCKET_CONNECT_MAXRETRIES] + 1} ` + `options=${JSON.stringify(connectPayload)}`);
|
|
296
|
+
if (useCookie) {
|
|
279
297
|
this.ws = new ws__default["default"](wsEndpoint, {
|
|
280
298
|
headers: {
|
|
281
299
|
Cookie: headers['set-cookie']
|
|
@@ -285,9 +303,11 @@ class BotiumConnectorVoip {
|
|
|
285
303
|
this.ws = new ws__default["default"](wsEndpoint);
|
|
286
304
|
}
|
|
287
305
|
this.ws.on('open', () => {
|
|
306
|
+
debug$3(`WebSocket connect: result=open url=${wsEndpoint} attempt=${retryIndex + 1} ` + `readyState=${this.ws && this.ws.readyState}`);
|
|
288
307
|
resolve(retryIndex);
|
|
289
308
|
});
|
|
290
|
-
this.ws.on('error',
|
|
309
|
+
this.ws.on('error', err => {
|
|
310
|
+
debug$3(`WebSocket connect: result=error url=${wsEndpoint} attempt=${retryIndex + 1} ` + `err=${err && err.message || err || 'unknown'}`);
|
|
291
311
|
if (retryIndex === this.caps[Capabilities.VOIP_WEBSOCKET_CONNECT_MAXRETRIES]) {
|
|
292
312
|
reject(new Error(`Websocket connection failed to ${wsEndpoint}`));
|
|
293
313
|
}
|