genesys-cloud-streaming-client 14.1.1-develop.14 → 14.1.1-develop.15
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.
- package/dist/cjs/client.d.ts +0 -1
- package/dist/cjs/client.js +21 -42
- package/dist/cjs/http-client.js +1 -1
- package/dist/cjs/reconnector.d.ts +1 -1
- package/dist/cjs/reconnector.js +7 -19
- package/dist/cjs/utils.d.ts +8 -1
- package/dist/cjs/utils.js +45 -4
- package/dist/deploy-info.json +2 -2
- package/dist/es/client.d.ts +0 -1
- package/dist/es/client.js +20 -43
- package/dist/es/http-client.js +1 -1
- package/dist/es/index.bundle.js +231 -311
- package/dist/es/reconnector.d.ts +1 -1
- package/dist/es/reconnector.js +13 -23
- package/dist/es/utils.d.ts +8 -1
- package/dist/es/utils.js +44 -1
- package/dist/npm/CHANGELOG.md +3 -0
- package/dist/npm/client.d.ts +0 -1
- package/dist/npm/client.js +21 -42
- package/dist/npm/http-client.js +1 -1
- package/dist/npm/reconnector.d.ts +1 -1
- package/dist/npm/reconnector.js +7 -19
- package/dist/npm/utils.d.ts +8 -1
- package/dist/npm/utils.js +45 -4
- package/dist/streaming-client.browser.ie.js +4 -4
- package/dist/streaming-client.browser.js +4 -4
- package/dist/v14/streaming-client.browser.ie.js +4 -4
- package/dist/v14/streaming-client.browser.js +4 -4
- package/dist/v14.1.1/streaming-client.browser.ie.js +4 -4
- package/dist/v14.1.1/streaming-client.browser.js +4 -4
- package/package.json +1 -1
- package/dist/cjs/types/retry-utils.d.ts +0 -54
- package/dist/cjs/types/retry-utils.js +0 -94
- package/dist/es/types/retry-utils.d.ts +0 -54
- package/dist/es/types/retry-utils.js +0 -91
- package/dist/npm/types/retry-utils.d.ts +0 -54
- package/dist/npm/types/retry-utils.js +0 -94
package/dist/es/utils.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
export { retryPromise, RetryPromise } from './types/retry-utils';
|
|
2
1
|
export declare function timeoutPromise(fn: Function, timeoutMs: number, msg: string, details?: any): Promise<void>;
|
|
3
2
|
export declare function splitIntoIndividualTopics(topicString: string): string[];
|
|
4
3
|
export declare const isAcdJid: (jid: string) => boolean;
|
|
5
4
|
export declare const isScreenRecordingJid: (jid: string) => boolean;
|
|
6
5
|
export declare const isSoftphoneJid: (jid: string) => boolean;
|
|
7
6
|
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>;
|
|
8
15
|
export declare const parseJwt: (token: string) => any;
|
|
9
16
|
export declare function calculatePayloadSize(trace: any): number;
|
package/dist/es/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { v4 } from 'uuid';
|
|
2
3
|
export function timeoutPromise(fn, timeoutMs, msg, details) {
|
|
3
4
|
return new Promise(function (resolve, reject) {
|
|
4
5
|
const timeout = setTimeout(function () {
|
|
@@ -45,6 +46,48 @@ export const isSoftphoneJid = function (jid) {
|
|
|
45
46
|
export const isVideoJid = function (jid) {
|
|
46
47
|
return !!(jid && jid.match(/@conference/) && !isAcdJid(jid));
|
|
47
48
|
};
|
|
49
|
+
export function retryPromise(promiseFn, retryFn, retryInterval = 15000, logger = console) {
|
|
50
|
+
let timeout;
|
|
51
|
+
let cancel;
|
|
52
|
+
let complete;
|
|
53
|
+
let tryPromiseFn;
|
|
54
|
+
let _hasCompleted = false;
|
|
55
|
+
const promise = new Promise((resolve, reject) => {
|
|
56
|
+
tryPromiseFn = () => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
const val = yield promiseFn();
|
|
59
|
+
complete(val);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (retryFn(error)) {
|
|
63
|
+
logger.debug('Retrying promise', error);
|
|
64
|
+
timeout = setTimeout(tryPromiseFn, retryInterval);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
cancel(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
complete = (value) => {
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
_hasCompleted = true;
|
|
74
|
+
resolve(value);
|
|
75
|
+
};
|
|
76
|
+
cancel = (reason) => {
|
|
77
|
+
clearTimeout(timeout);
|
|
78
|
+
_hasCompleted = true;
|
|
79
|
+
reject(reason);
|
|
80
|
+
};
|
|
81
|
+
tryPromiseFn();
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
promise,
|
|
85
|
+
cancel,
|
|
86
|
+
complete,
|
|
87
|
+
_id: v4(),
|
|
88
|
+
hasCompleted: () => _hasCompleted
|
|
89
|
+
};
|
|
90
|
+
}
|
|
48
91
|
// from https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript
|
|
49
92
|
export const parseJwt = (token) => {
|
|
50
93
|
const base64Url = token.split('.')[1];
|
package/dist/npm/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
# [Unreleased](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v14.1.0...HEAD)
|
|
7
7
|
|
|
8
|
+
### Fixed
|
|
9
|
+
* [PCM-1943](https://inindca.atlassian.net/browse/PCM-1943) – Reverted faulty connect/retry logic introduced with [PCM-1908](https://inindca.atlassian.net/browse/PCM-1908) (v14.0.0)
|
|
10
|
+
|
|
8
11
|
### Added
|
|
9
12
|
* [PCM-1935](https://inindca.atlassian.net/browse/PCM-1935) – added build, deploy, and publish notifications to the Jenkinsfile
|
|
10
13
|
|
package/dist/npm/client.d.ts
CHANGED
package/dist/npm/client.js
CHANGED
|
@@ -60,7 +60,7 @@ class Client {
|
|
|
60
60
|
constructor(options) {
|
|
61
61
|
this.connected = false;
|
|
62
62
|
this.connecting = false;
|
|
63
|
-
this.autoReconnect =
|
|
63
|
+
this.autoReconnect = true;
|
|
64
64
|
this.hardReconnectCount = 0;
|
|
65
65
|
this.reconnectLeakTime = 1000 * 60 * 10; // 10 minutes
|
|
66
66
|
this.deadChannels = [];
|
|
@@ -126,9 +126,8 @@ class Client {
|
|
|
126
126
|
this.on('connected', async (event) => {
|
|
127
127
|
this.streamId = event.resource;
|
|
128
128
|
this._ping.start();
|
|
129
|
-
this._reconnector.stop();
|
|
130
|
-
this.autoReconnect = true;
|
|
131
129
|
this.connected = true;
|
|
130
|
+
this._reconnector.stop();
|
|
132
131
|
this.connecting = false;
|
|
133
132
|
});
|
|
134
133
|
// remapped session:end
|
|
@@ -276,7 +275,16 @@ class Client {
|
|
|
276
275
|
this.logger.info('streamingClient.connect was called');
|
|
277
276
|
this.connecting = true;
|
|
278
277
|
if (this.config.jwt) {
|
|
279
|
-
return
|
|
278
|
+
return utils_1.timeoutPromise(resolve => {
|
|
279
|
+
this.once('connected', resolve);
|
|
280
|
+
const options = stanzaOptionsJwt(this.config);
|
|
281
|
+
this._stanzaio.updateConfig(options);
|
|
282
|
+
this._stanzaio.connect();
|
|
283
|
+
}, 10 * 1000, 'connecting to streaming service with jwt')
|
|
284
|
+
.catch((err) => {
|
|
285
|
+
this.connecting = false;
|
|
286
|
+
return Promise.reject(err);
|
|
287
|
+
});
|
|
280
288
|
}
|
|
281
289
|
let jidPromise;
|
|
282
290
|
if (this.config.jid) {
|
|
@@ -304,46 +312,17 @@ class Client {
|
|
|
304
312
|
.then(([jid, channelId]) => {
|
|
305
313
|
this.config.jid = jid;
|
|
306
314
|
this.config.channelId = channelId;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
? { usingJwt: true }
|
|
316
|
-
: { channelId: this.config.channelId, jidResource: this.config.jidResource };
|
|
317
|
-
/* if we already have a WS, we need to wait for the 2nd disconnect */
|
|
318
|
-
let skipDisconnectEvent = !!this._stanzaio.transport;
|
|
319
|
-
let rejectCallback;
|
|
320
|
-
return utils_1.timeoutPromise((resolve, reject) => {
|
|
321
|
-
rejectCallback = () => {
|
|
322
|
-
if (skipDisconnectEvent) {
|
|
323
|
-
this.logger.debug('received a --transport-disconnected event from existing WS. Not rejecting new attempt to connect WS.');
|
|
324
|
-
skipDisconnectEvent = false;
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
this.logger.debug('received a --transport-disconnected event while attempting to connect new WS. rejecting new attempt to connect WS.');
|
|
328
|
-
reject(new Error('unexpected disconnect from the WebSocket connecting streaming service'));
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
/* if stanza runs into an error, we want to reject right away. There is no reason to wait for our timeout */
|
|
332
|
-
this._stanzaio.on('--transport-disconnected', rejectCallback);
|
|
333
|
-
this.once('connected', resolve);
|
|
334
|
-
this._stanzaio.updateConfig(options);
|
|
335
|
-
this._stanzaio.connect();
|
|
336
|
-
}, 10 * 1000, timeoutMsg, timeoutDetails)
|
|
315
|
+
this.autoReconnect = true;
|
|
316
|
+
return utils_1.timeoutPromise(resolve => {
|
|
317
|
+
this.once('connected', resolve);
|
|
318
|
+
const options = stanzaioOptions(this.config);
|
|
319
|
+
this._stanzaio.updateConfig(options);
|
|
320
|
+
this._stanzaio.connect();
|
|
321
|
+
}, 10 * 1000, 'connecting to streaming service', { jid, channelId });
|
|
322
|
+
})
|
|
337
323
|
.catch((err) => {
|
|
338
324
|
this.connecting = false;
|
|
339
|
-
|
|
340
|
-
if (err.message === `Timeout: ${timeoutMsg}` && this._stanzaio.transport) {
|
|
341
|
-
this._stanzaio.disconnect();
|
|
342
|
-
this.logger.debug('timing out WS connect(), calling through to stanza to disconnect');
|
|
343
|
-
}
|
|
344
|
-
throw err;
|
|
345
|
-
}).finally(() => {
|
|
346
|
-
this._stanzaio.off('--transport-disconnected', rejectCallback);
|
|
325
|
+
return Promise.reject(err);
|
|
347
326
|
});
|
|
348
327
|
}
|
|
349
328
|
stopServerLogging() {
|
package/dist/npm/http-client.js
CHANGED
|
@@ -75,7 +75,7 @@ class HttpClient {
|
|
|
75
75
|
const value = this._httpRetryingRequests.get(retryId);
|
|
76
76
|
if (value) {
|
|
77
77
|
/* if the promise has already completed, this will do nothing. Still need to remove it from the map */
|
|
78
|
-
value.
|
|
78
|
+
value.cancel(new Error('Retry request cancelled'));
|
|
79
79
|
this._httpRetryingRequests.delete(retryId);
|
|
80
80
|
}
|
|
81
81
|
return true;
|
|
@@ -10,7 +10,7 @@ export declare class Reconnector {
|
|
|
10
10
|
_backoffActive: boolean;
|
|
11
11
|
_hardReconnectRetryInfo: null | RetryPromise<void>;
|
|
12
12
|
constructor(client: any);
|
|
13
|
-
hardReconnect(
|
|
13
|
+
hardReconnect(): Promise<void>;
|
|
14
14
|
cleanupReconnect(): void;
|
|
15
15
|
start(): void;
|
|
16
16
|
stop(error?: Error | string): void;
|
package/dist/npm/reconnector.js
CHANGED
|
@@ -95,15 +95,13 @@ class Reconnector {
|
|
|
95
95
|
});
|
|
96
96
|
this._backoffActive = false;
|
|
97
97
|
}
|
|
98
|
-
async hardReconnect(
|
|
98
|
+
async hardReconnect() {
|
|
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), (
|
|
105
|
-
return this._shouldRetryError(error, retryCount, maxAttempts);
|
|
106
|
-
}, interval, this.client.logger);
|
|
104
|
+
this._hardReconnectRetryInfo = utils_1.retryPromise(this._attemptHardReconnect.bind(this), this._shouldRetryError.bind(this), HARD_RECONNECT_RETRY_MS, this.client.logger);
|
|
107
105
|
try {
|
|
108
106
|
await this._hardReconnectRetryInfo.promise;
|
|
109
107
|
this._stopHardReconnect();
|
|
@@ -138,32 +136,22 @@ class Reconnector {
|
|
|
138
136
|
if (typeof error === 'string') {
|
|
139
137
|
error = new Error(error);
|
|
140
138
|
}
|
|
141
|
-
this._hardReconnectRetryInfo.
|
|
139
|
+
this._hardReconnectRetryInfo.cancel(error);
|
|
142
140
|
}
|
|
143
141
|
else {
|
|
144
|
-
this._hardReconnectRetryInfo.
|
|
142
|
+
this._hardReconnectRetryInfo.complete();
|
|
145
143
|
}
|
|
146
144
|
this._hardReconnectRetryInfo = null;
|
|
147
145
|
}
|
|
148
|
-
_attemptHardReconnect() {
|
|
146
|
+
async _attemptHardReconnect() {
|
|
149
147
|
/* if we aren't online, don't retry the new channel */
|
|
150
148
|
if (!navigator.onLine) {
|
|
151
149
|
throw new Error(OFFLINE_ERROR);
|
|
152
150
|
}
|
|
153
151
|
this.client.logger.info('Attempting to reconnect with new channel.');
|
|
154
|
-
|
|
152
|
+
await this.client.connect();
|
|
155
153
|
}
|
|
156
|
-
_shouldRetryError(error
|
|
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
|
-
}
|
|
154
|
+
_shouldRetryError(error) {
|
|
167
155
|
/* we throw this is we are offline */
|
|
168
156
|
if (error.message === OFFLINE_ERROR) {
|
|
169
157
|
this.client.logger.debug('Browser is offline. Not attempting to reconnect with new channel.');
|
package/dist/npm/utils.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
export { retryPromise, RetryPromise } from './types/retry-utils';
|
|
2
1
|
export declare function timeoutPromise(fn: Function, timeoutMs: number, msg: string, details?: any): Promise<void>;
|
|
3
2
|
export declare function splitIntoIndividualTopics(topicString: string): string[];
|
|
4
3
|
export declare const isAcdJid: (jid: string) => boolean;
|
|
5
4
|
export declare const isScreenRecordingJid: (jid: string) => boolean;
|
|
6
5
|
export declare const isSoftphoneJid: (jid: string) => boolean;
|
|
7
6
|
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>;
|
|
8
15
|
export declare const parseJwt: (token: string) => any;
|
|
9
16
|
export declare function calculatePayloadSize(trace: any): number;
|
package/dist/npm/utils.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculatePayloadSize = exports.parseJwt = exports.isVideoJid = exports.isSoftphoneJid = exports.isScreenRecordingJid = exports.isAcdJid = exports.splitIntoIndividualTopics = exports.timeoutPromise =
|
|
4
|
-
|
|
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; } });
|
|
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");
|
|
7
5
|
function timeoutPromise(fn, timeoutMs, msg, details) {
|
|
8
6
|
return new Promise(function (resolve, reject) {
|
|
9
7
|
const timeout = setTimeout(function () {
|
|
@@ -56,6 +54,49 @@ const isVideoJid = function (jid) {
|
|
|
56
54
|
return !!(jid && jid.match(/@conference/) && !exports.isAcdJid(jid));
|
|
57
55
|
};
|
|
58
56
|
exports.isVideoJid = isVideoJid;
|
|
57
|
+
function retryPromise(promiseFn, retryFn, retryInterval = 15000, logger = console) {
|
|
58
|
+
let timeout;
|
|
59
|
+
let cancel;
|
|
60
|
+
let complete;
|
|
61
|
+
let tryPromiseFn;
|
|
62
|
+
let _hasCompleted = false;
|
|
63
|
+
const promise = new Promise((resolve, reject) => {
|
|
64
|
+
tryPromiseFn = async () => {
|
|
65
|
+
try {
|
|
66
|
+
const val = await promiseFn();
|
|
67
|
+
complete(val);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (retryFn(error)) {
|
|
71
|
+
logger.debug('Retrying promise', error);
|
|
72
|
+
timeout = setTimeout(tryPromiseFn, retryInterval);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
cancel(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
complete = (value) => {
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
_hasCompleted = true;
|
|
82
|
+
resolve(value);
|
|
83
|
+
};
|
|
84
|
+
cancel = (reason) => {
|
|
85
|
+
clearTimeout(timeout);
|
|
86
|
+
_hasCompleted = true;
|
|
87
|
+
reject(reason);
|
|
88
|
+
};
|
|
89
|
+
tryPromiseFn();
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
promise,
|
|
93
|
+
cancel,
|
|
94
|
+
complete,
|
|
95
|
+
_id: uuid_1.v4(),
|
|
96
|
+
hasCompleted: () => _hasCompleted
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.retryPromise = retryPromise;
|
|
59
100
|
// from https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript
|
|
60
101
|
const parseJwt = (token) => {
|
|
61
102
|
const base64Url = token.split('.')[1];
|