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
@@ -95,13 +95,15 @@ class Reconnector {
95
95
  });
96
96
  this._backoffActive = false;
97
97
  }
98
- async hardReconnect() {
98
+ async hardReconnect(maxAttempts, interval = HARD_RECONNECT_RETRY_MS) {
99
99
  if (this._hardReconnectRetryInfo) {
100
100
  return this._hardReconnectRetryInfo.promise;
101
101
  }
102
102
  this.cleanupReconnect();
103
103
  this._hasConnected = false;
104
- this._hardReconnectRetryInfo = utils_1.retryPromise(this._attemptHardReconnect.bind(this), this._shouldRetryError.bind(this), HARD_RECONNECT_RETRY_MS, this.client.logger);
104
+ this._hardReconnectRetryInfo = utils_1.retryPromise(this._attemptHardReconnect.bind(this), (error, retryCount) => {
105
+ return this._shouldRetryError(error, retryCount, maxAttempts);
106
+ }, interval, this.client.logger);
105
107
  try {
106
108
  await this._hardReconnectRetryInfo.promise;
107
109
  this._stopHardReconnect();
@@ -136,22 +138,32 @@ class Reconnector {
136
138
  if (typeof error === 'string') {
137
139
  error = new Error(error);
138
140
  }
139
- this._hardReconnectRetryInfo.cancel(error);
141
+ this._hardReconnectRetryInfo.reject(error);
140
142
  }
141
143
  else {
142
- this._hardReconnectRetryInfo.complete();
144
+ this._hardReconnectRetryInfo.resolve();
143
145
  }
144
146
  this._hardReconnectRetryInfo = null;
145
147
  }
146
- async _attemptHardReconnect() {
148
+ _attemptHardReconnect() {
147
149
  /* if we aren't online, don't retry the new channel */
148
150
  if (!navigator.onLine) {
149
151
  throw new Error(OFFLINE_ERROR);
150
152
  }
151
153
  this.client.logger.info('Attempting to reconnect with new channel.');
152
- await this.client.connect();
154
+ return this.client.connect();
153
155
  }
154
- _shouldRetryError(error) {
156
+ _shouldRetryError(error, attemptNumber, maxAttempts) {
157
+ if (typeof maxAttempts === 'number' && typeof attemptNumber === 'number') {
158
+ if (attemptNumber > maxAttempts) {
159
+ this.client.logger.debug('Max retry attempts reached trying to connect to new channel. Stopping retry', { attemptNumber, maxAttempts });
160
+ return false;
161
+ }
162
+ else {
163
+ this.client.logger.debug('Max retry attempts NOT reached trying to connect to new channel. Retrying', { attemptNumber, maxAttempts });
164
+ return true;
165
+ }
166
+ }
155
167
  /* we throw this is we are offline */
156
168
  if (error.message === OFFLINE_ERROR) {
157
169
  this.client.logger.debug('Browser is offline. Not attempting to reconnect with new channel.');
@@ -0,0 +1,54 @@
1
+ import WildEmitter from 'wildemitter';
2
+ export interface IRetryConfig<T = any> {
3
+ /**
4
+ * Function to attempt until it completes or rejects based on the
5
+ * criteria for retrying.
6
+ */
7
+ promiseFn: () => Promise<T>;
8
+ /**
9
+ * Retry criteria to retry the promise function on failure. Available options:
10
+ * - `boolean`: if `true`, it will _always_ be retried. if `false`, it will _never_
11
+ * be retried.
12
+ * - `number`: max attempts to retry
13
+ * - `function`: a function that accepts the error thrown and determines if it
14
+ * should be retried. It will be passed the `Error` and the `attemptCount`.
15
+ *
16
+ * Default: `false`
17
+ */
18
+ retry?: boolean | number | ((error?: Error | any, attemptCount?: number) => boolean);
19
+ /**
20
+ * Milliseconds to wait inbetween next retry of the promise function on failure.
21
+ *
22
+ * Default: `15000`
23
+ */
24
+ retryInterval?: number;
25
+ }
26
+ export declare class RetryPromise<T = any> extends WildEmitter {
27
+ promise: Promise<T>;
28
+ _id: string;
29
+ private _reject;
30
+ private _resolve;
31
+ private _hasCompleted;
32
+ private _attemptCount;
33
+ private _timeout;
34
+ private _config;
35
+ constructor(config: IRetryConfig);
36
+ /**
37
+ * @deprecated use `reject(reason)`
38
+ * @param reason value to reject the promise with
39
+ * @returns void
40
+ */
41
+ cancel(reason?: string | Error | any): void;
42
+ reject(reason?: string | Error | any): void;
43
+ /**
44
+ * @deprecated use `resolve(reason)`
45
+ * @param value to resolve the promise with
46
+ * @returns void
47
+ */
48
+ complete(value: T | PromiseLike<T>): void;
49
+ resolve(value: T | PromiseLike<T>): void;
50
+ hasCompleted(): boolean;
51
+ attemptCount(): number;
52
+ private _tryPromiseFn;
53
+ }
54
+ export declare function retryPromise<T = any>(promiseFn: () => Promise<T>, retry?: boolean | number | ((error?: Error | any, attemptCount?: number) => boolean), retryInterval?: number, _logger?: any): RetryPromise<T>;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retryPromise = exports.RetryPromise = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const uuid_1 = require("uuid");
6
+ const wildemitter_1 = tslib_1.__importDefault(require("wildemitter"));
7
+ class RetryPromise extends wildemitter_1.default {
8
+ constructor(config) {
9
+ super();
10
+ this._id = uuid_1.v4();
11
+ this._hasCompleted = false;
12
+ this._attemptCount = 0;
13
+ this.promise = new Promise((resolve, reject) => {
14
+ this._resolve = resolve;
15
+ this._reject = reject;
16
+ });
17
+ this._config = {
18
+ promiseFn: config.promiseFn,
19
+ retry: config.retry || false,
20
+ retryInterval: config.retryInterval !== undefined && config.retryInterval > -1 ? config.retryInterval : 15000
21
+ };
22
+ /* tslint:disable:no-floating-promises */
23
+ this._tryPromiseFn();
24
+ }
25
+ /**
26
+ * @deprecated use `reject(reason)`
27
+ * @param reason value to reject the promise with
28
+ * @returns void
29
+ */
30
+ cancel(reason) {
31
+ return this.reject(reason);
32
+ }
33
+ reject(reason) {
34
+ this._reject(reason);
35
+ clearTimeout(this._timeout);
36
+ this._hasCompleted = true;
37
+ this.emit('rejected', reason);
38
+ }
39
+ /**
40
+ * @deprecated use `resolve(reason)`
41
+ * @param value to resolve the promise with
42
+ * @returns void
43
+ */
44
+ complete(value) {
45
+ return this.resolve(value);
46
+ }
47
+ resolve(value) {
48
+ this._resolve(value);
49
+ clearTimeout(this._timeout);
50
+ this._hasCompleted = true;
51
+ this.emit('resolved', value);
52
+ }
53
+ hasCompleted() {
54
+ return this._hasCompleted;
55
+ }
56
+ attemptCount() {
57
+ return this._attemptCount;
58
+ }
59
+ async _tryPromiseFn() {
60
+ const { retry, retryInterval } = this._config;
61
+ try {
62
+ this._attemptCount++;
63
+ this.emit('trying', {
64
+ attemptCount: this._attemptCount,
65
+ promise: this.promise
66
+ });
67
+ const val = await this._config.promiseFn();
68
+ this.resolve(val);
69
+ }
70
+ catch (error) {
71
+ if (
72
+ /* always retry */
73
+ retry === true ||
74
+ /* retry if under max retry attempts */
75
+ typeof retry === 'number' && this._attemptCount <= retry ||
76
+ /* retry if retry function returns true */
77
+ typeof retry === 'function' && retry(error, this._attemptCount + 1)) {
78
+ this.emit('retrying', {
79
+ error,
80
+ attemptCount: this._attemptCount,
81
+ retryInterval
82
+ });
83
+ this._timeout = setTimeout(this._tryPromiseFn.bind(this), retryInterval);
84
+ return;
85
+ }
86
+ this.reject(error);
87
+ }
88
+ }
89
+ }
90
+ exports.RetryPromise = RetryPromise;
91
+ function retryPromise(promiseFn, retry, retryInterval = 15000, _logger = console) {
92
+ return new RetryPromise({ promiseFn, retry, retryInterval });
93
+ }
94
+ exports.retryPromise = retryPromise;
@@ -1,16 +1,9 @@
1
+ export { retryPromise, RetryPromise } from './types/retry-utils';
1
2
  export declare function timeoutPromise(fn: Function, timeoutMs: number, msg: string, details?: any): Promise<void>;
2
3
  export declare function splitIntoIndividualTopics(topicString: string): string[];
3
4
  export declare const isAcdJid: (jid: string) => boolean;
4
5
  export declare const isScreenRecordingJid: (jid: string) => boolean;
5
6
  export declare const isSoftphoneJid: (jid: string) => boolean;
6
7
  export declare const isVideoJid: (jid: string) => boolean;
7
- export declare type RetryPromise<T = any> = {
8
- promise: Promise<T>;
9
- cancel: (reason?: string | Error) => void;
10
- complete: (value?: T) => void;
11
- hasCompleted: () => boolean;
12
- _id: string;
13
- };
14
- export declare function retryPromise<T = any>(promiseFn: () => Promise<T>, retryFn: (error?: Error | any) => boolean, retryInterval?: number, logger?: any): RetryPromise<T>;
15
8
  export declare const parseJwt: (token: string) => any;
16
9
  export declare function calculatePayloadSize(trace: any): number;
package/dist/npm/utils.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculatePayloadSize = exports.parseJwt = exports.retryPromise = exports.isVideoJid = exports.isSoftphoneJid = exports.isScreenRecordingJid = exports.isAcdJid = exports.splitIntoIndividualTopics = exports.timeoutPromise = void 0;
4
- const uuid_1 = require("uuid");
3
+ exports.calculatePayloadSize = exports.parseJwt = exports.isVideoJid = exports.isSoftphoneJid = exports.isScreenRecordingJid = exports.isAcdJid = exports.splitIntoIndividualTopics = exports.timeoutPromise = exports.RetryPromise = exports.retryPromise = void 0;
4
+ var retry_utils_1 = require("./types/retry-utils");
5
+ Object.defineProperty(exports, "retryPromise", { enumerable: true, get: function () { return retry_utils_1.retryPromise; } });
6
+ Object.defineProperty(exports, "RetryPromise", { enumerable: true, get: function () { return retry_utils_1.RetryPromise; } });
5
7
  function timeoutPromise(fn, timeoutMs, msg, details) {
6
8
  return new Promise(function (resolve, reject) {
7
9
  const timeout = setTimeout(function () {
@@ -35,66 +37,27 @@ function splitIntoIndividualTopics(topicString) {
35
37
  return topics;
36
38
  }
37
39
  exports.splitIntoIndividualTopics = splitIntoIndividualTopics;
38
- exports.isAcdJid = function (jid) {
40
+ const isAcdJid = function (jid) {
39
41
  return jid.startsWith('acd-');
40
42
  };
41
- exports.isScreenRecordingJid = function (jid) {
43
+ exports.isAcdJid = isAcdJid;
44
+ const isScreenRecordingJid = function (jid) {
42
45
  return jid.startsWith('screenrecording-');
43
46
  };
44
- exports.isSoftphoneJid = function (jid) {
47
+ exports.isScreenRecordingJid = isScreenRecordingJid;
48
+ const isSoftphoneJid = function (jid) {
45
49
  if (!jid) {
46
50
  return false;
47
51
  }
48
52
  return !!jid.match(/.*@.*gjoll.*/i);
49
53
  };
50
- exports.isVideoJid = function (jid) {
54
+ exports.isSoftphoneJid = isSoftphoneJid;
55
+ const isVideoJid = function (jid) {
51
56
  return !!(jid && jid.match(/@conference/) && !exports.isAcdJid(jid));
52
57
  };
53
- function retryPromise(promiseFn, retryFn, retryInterval = 15000, logger = console) {
54
- let timeout;
55
- let cancel;
56
- let complete;
57
- let tryPromiseFn;
58
- let _hasCompleted = false;
59
- const promise = new Promise((resolve, reject) => {
60
- tryPromiseFn = async () => {
61
- try {
62
- const val = await promiseFn();
63
- complete(val);
64
- }
65
- catch (error) {
66
- if (retryFn(error)) {
67
- logger.debug('Retrying promise', error);
68
- timeout = setTimeout(tryPromiseFn, retryInterval);
69
- }
70
- else {
71
- cancel(error);
72
- }
73
- }
74
- };
75
- complete = (value) => {
76
- clearTimeout(timeout);
77
- _hasCompleted = true;
78
- resolve(value);
79
- };
80
- cancel = (reason) => {
81
- clearTimeout(timeout);
82
- _hasCompleted = true;
83
- reject(reason);
84
- };
85
- tryPromiseFn();
86
- });
87
- return {
88
- promise,
89
- cancel,
90
- complete,
91
- _id: uuid_1.v4(),
92
- hasCompleted: () => _hasCompleted
93
- };
94
- }
95
- exports.retryPromise = retryPromise;
58
+ exports.isVideoJid = isVideoJid;
96
59
  // from https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript
97
- exports.parseJwt = (token) => {
60
+ const parseJwt = (token) => {
98
61
  const base64Url = token.split('.')[1];
99
62
  const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
100
63
  const jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function (c) {
@@ -102,6 +65,7 @@ exports.parseJwt = (token) => {
102
65
  }).join(''));
103
66
  return JSON.parse(jsonPayload);
104
67
  };
68
+ exports.parseJwt = parseJwt;
105
69
  function calculatePayloadSize(trace) {
106
70
  const str = JSON.stringify(trace);
107
71
  // http://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript
@@ -46,6 +46,7 @@ export declare class WebrtcExtension extends EventEmitter {
46
46
  sessionId: string;
47
47
  sessionType?: SessionTypes;
48
48
  };
49
+ flushStats(): void;
49
50
  sendStats(): Promise<void>;
50
51
  addEventListeners(): void;
51
52
  proxyEvents(): void;
@@ -102,6 +102,10 @@ class WebrtcExtension extends events_1.EventEmitter {
102
102
  // This should be moved when the sdk is the primary consumer
103
103
  proxyStatsForSession(session) {
104
104
  session.on('stats', (statsEvent) => {
105
+ /* if our logger was stopped, we need to stop stats logging too */
106
+ if (this.client.logger['stopReason']) {
107
+ return;
108
+ }
105
109
  const statsCopy = JSON.parse(JSON.stringify(statsEvent));
106
110
  const extraDetails = {
107
111
  conference: session.conversationId,
@@ -117,7 +121,7 @@ class WebrtcExtension extends events_1.EventEmitter {
117
121
  this.statBuffer += currentEventSize;
118
122
  // If it exceeds max size, don't append just send current payload.
119
123
  if (exceedsMaxStatSize) {
120
- this.throttledSendStats.flush();
124
+ this.flushStats();
121
125
  }
122
126
  else {
123
127
  this.throttledSendStats();
@@ -135,6 +139,9 @@ class WebrtcExtension extends events_1.EventEmitter {
135
139
  }
136
140
  return logDetails;
137
141
  }
142
+ flushStats() {
143
+ this.throttledSendStats.flush();
144
+ }
138
145
  async sendStats() {
139
146
  const statsToSend = [];
140
147
  let currentSize = 0;