genesys-cloud-streaming-client 13.5.0-develop.6 → 14.0.1-develop.9

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.
Files changed (53) hide show
  1. package/dist/cjs/client.d.ts +3 -0
  2. package/dist/cjs/client.js +56 -24
  3. package/dist/cjs/http-client.js +50 -8
  4. package/dist/cjs/reconnector.d.ts +1 -1
  5. package/dist/cjs/reconnector.js +19 -7
  6. package/dist/cjs/types/retry-utils.d.ts +54 -0
  7. package/dist/cjs/types/retry-utils.js +94 -0
  8. package/dist/cjs/utils.d.ts +1 -8
  9. package/dist/cjs/utils.js +14 -50
  10. package/dist/cjs/webrtc.d.ts +1 -0
  11. package/dist/cjs/webrtc.js +8 -1
  12. package/dist/deploy-info.json +6 -6
  13. package/dist/es/client.d.ts +3 -0
  14. package/dist/es/client.js +57 -23
  15. package/dist/es/http-client.js +50 -8
  16. package/dist/es/index.bundle.js +2323 -4641
  17. package/dist/es/reconnector.d.ts +1 -1
  18. package/dist/es/reconnector.js +23 -13
  19. package/dist/es/types/retry-utils.d.ts +54 -0
  20. package/dist/es/types/retry-utils.js +91 -0
  21. package/dist/es/utils.d.ts +1 -8
  22. package/dist/es/utils.js +1 -44
  23. package/dist/es/webrtc.d.ts +1 -0
  24. package/dist/es/webrtc.js +8 -1
  25. package/dist/npm/CHANGELOG.md +25 -1
  26. package/dist/npm/client.d.ts +3 -0
  27. package/dist/npm/client.js +56 -24
  28. package/dist/npm/http-client.js +50 -8
  29. package/dist/npm/reconnector.d.ts +1 -1
  30. package/dist/npm/reconnector.js +19 -7
  31. package/dist/npm/types/retry-utils.d.ts +54 -0
  32. package/dist/npm/types/retry-utils.js +94 -0
  33. package/dist/npm/utils.d.ts +1 -8
  34. package/dist/npm/utils.js +14 -50
  35. package/dist/npm/webrtc.d.ts +1 -0
  36. package/dist/npm/webrtc.js +8 -1
  37. package/dist/streaming-client.browser.ie.js +4 -4
  38. package/dist/streaming-client.browser.js +5 -5
  39. package/dist/v14/streaming-client.browser.ie.js +11 -0
  40. package/dist/v14/streaming-client.browser.js +40 -0
  41. package/dist/v14.0.1/streaming-client.browser.ie.js +11 -0
  42. package/dist/v14.0.1/streaming-client.browser.js +40 -0
  43. package/package.json +5 -4
  44. package/dist/cjs/request-logger.d.ts +0 -1
  45. package/dist/cjs/request-logger.js +0 -24
  46. package/dist/es/request-logger.d.ts +0 -1
  47. package/dist/es/request-logger.js +0 -21
  48. package/dist/npm/request-logger.d.ts +0 -1
  49. package/dist/npm/request-logger.js +0 -24
  50. package/dist/v13/streaming-client.browser.ie.js +0 -11
  51. package/dist/v13/streaming-client.browser.js +0 -40
  52. package/dist/v13.5.0/streaming-client.browser.ie.js +0 -11
  53. package/dist/v13.5.0/streaming-client.browser.js +0 -40
package/dist/es/client.js CHANGED
@@ -59,7 +59,7 @@ export class Client {
59
59
  constructor(options) {
60
60
  this.connected = false;
61
61
  this.connecting = false;
62
- this.autoReconnect = true;
62
+ this.autoReconnect = false;
63
63
  this.hardReconnectCount = 0;
64
64
  this.reconnectLeakTime = 1000 * 60 * 10; // 10 minutes
65
65
  this.deadChannels = [];
@@ -116,8 +116,9 @@ export class Client {
116
116
  this.on('connected', (event) => __awaiter(this, void 0, void 0, function* () {
117
117
  this.streamId = event.resource;
118
118
  this._ping.start();
119
- this.connected = true;
120
119
  this._reconnector.stop();
120
+ this.autoReconnect = true;
121
+ this.connected = true;
121
122
  this.connecting = false;
122
123
  }));
123
124
  // remapped session:end
@@ -235,6 +236,7 @@ export class Client {
235
236
  }
236
237
  disconnect() {
237
238
  this.logger.info('streamingClient.disconnect was called');
239
+ this.stopServerLogging();
238
240
  return timeoutPromise(resolve => {
239
241
  this._stanzaio.once('disconnected', resolve);
240
242
  this.autoReconnect = false;
@@ -253,19 +255,11 @@ export class Client {
253
255
  }, 10 * 1000, 'reconnecting streaming service');
254
256
  }
255
257
  connect() {
258
+ this.startServerLogging();
256
259
  this.logger.info('streamingClient.connect was called');
257
260
  this.connecting = true;
258
261
  if (this.config.jwt) {
259
- return timeoutPromise(resolve => {
260
- this.once('connected', resolve);
261
- const options = stanzaOptionsJwt(this.config);
262
- this._stanzaio.updateConfig(options);
263
- this._stanzaio.connect();
264
- }, 10 * 1000, 'connecting to streaming service with jwt')
265
- .catch((err) => {
266
- this.connecting = false;
267
- return Promise.reject(err);
268
- });
262
+ return this._connectStanza();
269
263
  }
270
264
  let jidPromise;
271
265
  if (this.config.jid) {
@@ -279,7 +273,7 @@ export class Client {
279
273
  logger: this.logger
280
274
  };
281
275
  jidPromise = this.http.requestApiWithRetry('users/me', opts).promise
282
- .then(res => res.body.chat.jabberId);
276
+ .then(res => res.data.chat.jabberId);
283
277
  }
284
278
  const opts = {
285
279
  method: 'post',
@@ -288,24 +282,64 @@ export class Client {
288
282
  logger: this.logger
289
283
  };
290
284
  const channelPromise = this.http.requestApiWithRetry('notifications/channels?connectionType=streaming', opts).promise
291
- .then(res => res.body.id);
285
+ .then(res => res.data.id);
292
286
  return Promise.all([jidPromise, channelPromise])
293
287
  .then(([jid, channelId]) => {
294
288
  this.config.jid = jid;
295
289
  this.config.channelId = channelId;
296
- this.autoReconnect = true;
297
- return timeoutPromise(resolve => {
290
+ return this._connectStanza();
291
+ });
292
+ }
293
+ _connectStanza() {
294
+ return __awaiter(this, void 0, void 0, function* () {
295
+ const guestConnection = !!this.config.jwt;
296
+ const timeoutMsg = 'connecting to streaming service';
297
+ const options = guestConnection ? stanzaOptionsJwt(this.config) : stanzaioOptions(this.config);
298
+ const timeoutDetails = guestConnection
299
+ ? { usingJwt: true }
300
+ : { channelId: this.config.channelId, jidResource: this.config.jidResource };
301
+ /* if we already have a WS, we need to wait for the 2nd disconnect */
302
+ let skipDisconnectEvent = !!this._stanzaio.transport;
303
+ let rejectCallback;
304
+ return timeoutPromise((resolve, reject) => {
305
+ rejectCallback = () => {
306
+ if (skipDisconnectEvent) {
307
+ this.logger.debug('received a --transport-disconnected event from existing WS. Not rejecting new attempt to connect WS.');
308
+ skipDisconnectEvent = false;
309
+ }
310
+ else {
311
+ this.logger.debug('received a --transport-disconnected event while attempting to connect new WS. rejecting new attempt to connect WS.');
312
+ reject(new Error('unexpected disconnect from the WebSocket connecting streaming service'));
313
+ }
314
+ };
315
+ /* if stanza runs into an error, we want to reject right away. There is no reason to wait for our timeout */
316
+ this._stanzaio.on('--transport-disconnected', rejectCallback);
298
317
  this.once('connected', resolve);
299
- const options = stanzaioOptions(this.config);
300
318
  this._stanzaio.updateConfig(options);
301
319
  this._stanzaio.connect();
302
- }, 10 * 1000, 'connecting to streaming service', { jid, channelId });
303
- })
304
- .catch((err) => {
305
- this.connecting = false;
306
- return Promise.reject(err);
320
+ }, 10 * 1000, timeoutMsg, timeoutDetails)
321
+ .catch((err) => {
322
+ this.connecting = false;
323
+ /* if _we_ timed out but stanza is still trying to connect, we need to stop stanza's WS */
324
+ if (err.message === `Timeout: ${timeoutMsg}` && this._stanzaio.transport) {
325
+ this._stanzaio.disconnect();
326
+ this.logger.debug('timing out WS connect(), calling through to stanza to disconnect');
327
+ }
328
+ throw err;
329
+ }).finally(() => {
330
+ this._stanzaio.off('--transport-disconnected', rejectCallback);
331
+ });
307
332
  });
308
333
  }
334
+ stopServerLogging() {
335
+ /* flush all pending logs and webrtc stats – then turn off the logger */
336
+ this.logger.sendAllLogsInstantly();
337
+ this.logger.stopServerLogging();
338
+ this._webrtcSessions.flushStats();
339
+ }
340
+ startServerLogging() {
341
+ this.logger.startServerLogging();
342
+ }
309
343
  setAccessToken(token) {
310
344
  this.config.authToken = token;
311
345
  this.logger.setAccessToken(token);
@@ -317,6 +351,6 @@ export class Client {
317
351
  extensions[namespace] = extension;
318
352
  }
319
353
  static get version() {
320
- return '13.5.0';
354
+ return '14.0.1';
321
355
  }
322
356
  }
@@ -1,6 +1,6 @@
1
- import request from 'superagent';
2
- import reqlogger from './request-logger';
1
+ import axios, { AxiosError } from 'axios';
3
2
  import { retryPromise } from './utils';
3
+ const correlationIdHeaderName = 'inin-correlation-id';
4
4
  export class HttpClient {
5
5
  constructor() {
6
6
  this._httpRetryingRequests = new Map();
@@ -13,14 +13,56 @@ export class HttpClient {
13
13
  return retry;
14
14
  }
15
15
  requestApi(path, opts) {
16
- let response = request[opts.method](this._buildUri(opts.host, path, opts.version))
17
- .use(reqlogger.bind(this, opts.logger, opts.data))
18
- .type(opts.contentType || 'json');
16
+ const logger = opts.logger || console;
17
+ const start = new Date().getTime();
18
+ const url = this._buildUri(opts.host, path, opts.version);
19
+ const params = {
20
+ method: opts.method,
21
+ url,
22
+ headers: {
23
+ 'content-type': opts.contentType || 'application/json',
24
+ // we may not need this
25
+ 'accept-encoding': 'gzip, deflate'
26
+ }
27
+ };
19
28
  // default to include auth header
20
29
  if (!opts.noAuthHeader) {
21
- response.set('Authorization', `Bearer ${opts.authToken}`);
30
+ params.headers['Authorization'] = `Bearer ${opts.authToken}`;
22
31
  }
23
- return response.send(opts.data); // trigger request
32
+ const handleResponse = function (res) {
33
+ var _a;
34
+ let now = new Date().getTime();
35
+ let elapsed = (now - start) + 'ms';
36
+ if (res instanceof AxiosError) {
37
+ /* istanbul ignore next */
38
+ const response = res.response || {};
39
+ let status = response.status;
40
+ let correlationId = (_a = response.headers) === null || _a === void 0 ? void 0 : _a[correlationIdHeaderName];
41
+ let body = response.data;
42
+ logger.debug(`request error: ${params.url}`, {
43
+ message: res.message,
44
+ now,
45
+ elapsed,
46
+ status,
47
+ correlationId,
48
+ body
49
+ }, true);
50
+ return Promise.reject(res);
51
+ }
52
+ let status = res.status;
53
+ let correlationId = res.headers[correlationIdHeaderName];
54
+ let body = JSON.stringify(res.data);
55
+ logger.debug(`response: ${opts.method.toUpperCase()} ${params.url}`, {
56
+ now,
57
+ status,
58
+ elapsed,
59
+ correlationId,
60
+ body
61
+ }, true);
62
+ return Promise.resolve(res);
63
+ };
64
+ return axios(params)
65
+ .then(handleResponse.bind(this), handleResponse.bind(this));
24
66
  }
25
67
  stopAllRetries() {
26
68
  Array.from(this._httpRetryingRequests.keys())
@@ -30,7 +72,7 @@ export class HttpClient {
30
72
  const value = this._httpRetryingRequests.get(retryId);
31
73
  if (value) {
32
74
  /* if the promise has already completed, this will do nothing. Still need to remove it from the map */
33
- value.cancel(new Error('Retry request cancelled'));
75
+ value.reject(new Error('Retry request cancelled'));
34
76
  this._httpRetryingRequests.delete(retryId);
35
77
  }
36
78
  return true;