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/cjs/client.d.ts
CHANGED
package/dist/cjs/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/cjs/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/cjs/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/cjs/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/cjs/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];
|
package/dist/deploy-info.json
CHANGED
package/dist/es/client.d.ts
CHANGED
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 =
|
|
62
|
+
this.autoReconnect = true;
|
|
63
63
|
this.hardReconnectCount = 0;
|
|
64
64
|
this.reconnectLeakTime = 1000 * 60 * 10; // 10 minutes
|
|
65
65
|
this.deadChannels = [];
|
|
@@ -125,9 +125,8 @@ export class Client {
|
|
|
125
125
|
this.on('connected', (event) => __awaiter(this, void 0, void 0, function* () {
|
|
126
126
|
this.streamId = event.resource;
|
|
127
127
|
this._ping.start();
|
|
128
|
-
this._reconnector.stop();
|
|
129
|
-
this.autoReconnect = true;
|
|
130
128
|
this.connected = true;
|
|
129
|
+
this._reconnector.stop();
|
|
131
130
|
this.connecting = false;
|
|
132
131
|
}));
|
|
133
132
|
// remapped session:end
|
|
@@ -275,7 +274,16 @@ export class Client {
|
|
|
275
274
|
this.logger.info('streamingClient.connect was called');
|
|
276
275
|
this.connecting = true;
|
|
277
276
|
if (this.config.jwt) {
|
|
278
|
-
return
|
|
277
|
+
return timeoutPromise(resolve => {
|
|
278
|
+
this.once('connected', resolve);
|
|
279
|
+
const options = stanzaOptionsJwt(this.config);
|
|
280
|
+
this._stanzaio.updateConfig(options);
|
|
281
|
+
this._stanzaio.connect();
|
|
282
|
+
}, 10 * 1000, 'connecting to streaming service with jwt')
|
|
283
|
+
.catch((err) => {
|
|
284
|
+
this.connecting = false;
|
|
285
|
+
return Promise.reject(err);
|
|
286
|
+
});
|
|
279
287
|
}
|
|
280
288
|
let jidPromise;
|
|
281
289
|
if (this.config.jid) {
|
|
@@ -303,48 +311,17 @@ export class Client {
|
|
|
303
311
|
.then(([jid, channelId]) => {
|
|
304
312
|
this.config.jid = jid;
|
|
305
313
|
this.config.channelId = channelId;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
_connectStanza() {
|
|
310
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
311
|
-
const guestConnection = !!this.config.jwt;
|
|
312
|
-
const timeoutMsg = 'connecting to streaming service';
|
|
313
|
-
const options = guestConnection ? stanzaOptionsJwt(this.config) : stanzaioOptions(this.config);
|
|
314
|
-
const timeoutDetails = guestConnection
|
|
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 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);
|
|
314
|
+
this.autoReconnect = true;
|
|
315
|
+
return timeoutPromise(resolve => {
|
|
333
316
|
this.once('connected', resolve);
|
|
317
|
+
const options = stanzaioOptions(this.config);
|
|
334
318
|
this._stanzaio.updateConfig(options);
|
|
335
319
|
this._stanzaio.connect();
|
|
336
|
-
}, 10 * 1000,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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);
|
|
347
|
-
});
|
|
320
|
+
}, 10 * 1000, 'connecting to streaming service', { jid, channelId });
|
|
321
|
+
})
|
|
322
|
+
.catch((err) => {
|
|
323
|
+
this.connecting = false;
|
|
324
|
+
return Promise.reject(err);
|
|
348
325
|
});
|
|
349
326
|
}
|
|
350
327
|
stopServerLogging() {
|
package/dist/es/http-client.js
CHANGED
|
@@ -71,7 +71,7 @@ export class HttpClient {
|
|
|
71
71
|
const value = this._httpRetryingRequests.get(retryId);
|
|
72
72
|
if (value) {
|
|
73
73
|
/* if the promise has already completed, this will do nothing. Still need to remove it from the map */
|
|
74
|
-
value.
|
|
74
|
+
value.cancel(new Error('Retry request cancelled'));
|
|
75
75
|
this._httpRetryingRequests.delete(retryId);
|
|
76
76
|
}
|
|
77
77
|
return true;
|