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.
- package/dist/cjs/client.d.ts +3 -0
- package/dist/cjs/client.js +56 -24
- package/dist/cjs/http-client.js +50 -8
- package/dist/cjs/reconnector.d.ts +1 -1
- package/dist/cjs/reconnector.js +19 -7
- package/dist/cjs/types/retry-utils.d.ts +54 -0
- package/dist/cjs/types/retry-utils.js +94 -0
- package/dist/cjs/utils.d.ts +1 -8
- package/dist/cjs/utils.js +14 -50
- package/dist/cjs/webrtc.d.ts +1 -0
- package/dist/cjs/webrtc.js +8 -1
- package/dist/deploy-info.json +6 -6
- package/dist/es/client.d.ts +3 -0
- package/dist/es/client.js +57 -23
- package/dist/es/http-client.js +50 -8
- package/dist/es/index.bundle.js +2323 -4641
- package/dist/es/reconnector.d.ts +1 -1
- package/dist/es/reconnector.js +23 -13
- package/dist/es/types/retry-utils.d.ts +54 -0
- package/dist/es/types/retry-utils.js +91 -0
- package/dist/es/utils.d.ts +1 -8
- package/dist/es/utils.js +1 -44
- package/dist/es/webrtc.d.ts +1 -0
- package/dist/es/webrtc.js +8 -1
- package/dist/npm/CHANGELOG.md +25 -1
- package/dist/npm/client.d.ts +3 -0
- package/dist/npm/client.js +56 -24
- package/dist/npm/http-client.js +50 -8
- package/dist/npm/reconnector.d.ts +1 -1
- package/dist/npm/reconnector.js +19 -7
- package/dist/npm/types/retry-utils.d.ts +54 -0
- package/dist/npm/types/retry-utils.js +94 -0
- package/dist/npm/utils.d.ts +1 -8
- package/dist/npm/utils.js +14 -50
- package/dist/npm/webrtc.d.ts +1 -0
- package/dist/npm/webrtc.js +8 -1
- package/dist/streaming-client.browser.ie.js +4 -4
- package/dist/streaming-client.browser.js +5 -5
- package/dist/v14/streaming-client.browser.ie.js +11 -0
- package/dist/v14/streaming-client.browser.js +40 -0
- package/dist/v14.0.1/streaming-client.browser.ie.js +11 -0
- package/dist/v14.0.1/streaming-client.browser.js +40 -0
- package/package.json +5 -4
- package/dist/cjs/request-logger.d.ts +0 -1
- package/dist/cjs/request-logger.js +0 -24
- package/dist/es/request-logger.d.ts +0 -1
- package/dist/es/request-logger.js +0 -21
- package/dist/npm/request-logger.d.ts +0 -1
- package/dist/npm/request-logger.js +0 -24
- package/dist/v13/streaming-client.browser.ie.js +0 -11
- package/dist/v13/streaming-client.browser.js +0 -40
- package/dist/v13.5.0/streaming-client.browser.ie.js +0 -11
- 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 =
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
297
|
-
|
|
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,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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 '
|
|
354
|
+
return '14.0.1';
|
|
321
355
|
}
|
|
322
356
|
}
|
package/dist/es/http-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
30
|
+
params.headers['Authorization'] = `Bearer ${opts.authToken}`;
|
|
22
31
|
}
|
|
23
|
-
|
|
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.
|
|
75
|
+
value.reject(new Error('Retry request cancelled'));
|
|
34
76
|
this._httpRetryingRequests.delete(retryId);
|
|
35
77
|
}
|
|
36
78
|
return true;
|