@webex/internal-plugin-metrics 3.0.0-beta.22 → 3.0.0-beta.220

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 (67) hide show
  1. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +56 -0
  2. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  3. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +451 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +645 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +276 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  9. package/dist/call-diagnostic/config.js +580 -0
  10. package/dist/call-diagnostic/config.js.map +1 -0
  11. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js +7 -0
  12. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js.map +1 -0
  13. package/dist/call-diagnostic/generated-types-temp/Event.js +7 -0
  14. package/dist/call-diagnostic/generated-types-temp/Event.js.map +1 -0
  15. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js +7 -0
  16. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js.map +1 -0
  17. package/dist/config.js +20 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/index.js +25 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/metrics.js +30 -30
  22. package/dist/metrics.js.map +1 -1
  23. package/dist/metrics.types.js +7 -0
  24. package/dist/metrics.types.js.map +1 -0
  25. package/dist/new-metrics.js +249 -0
  26. package/dist/new-metrics.js.map +1 -0
  27. package/dist/types/batcher.d.ts +2 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +189 -0
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +356 -0
  31. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +73 -0
  32. package/dist/types/call-diagnostic/config.d.ts +86 -0
  33. package/dist/types/call-diagnostic/generated-types-temp/ClientEvent.d.ts +1112 -0
  34. package/dist/types/call-diagnostic/generated-types-temp/Event.d.ts +4851 -0
  35. package/dist/types/call-diagnostic/generated-types-temp/MediaQualityEvent.d.ts +2121 -0
  36. package/dist/types/client-metrics-batcher.d.ts +2 -0
  37. package/dist/types/config.d.ts +35 -0
  38. package/dist/types/index.d.ts +11 -0
  39. package/dist/types/metrics.d.ts +3 -0
  40. package/dist/types/metrics.types.d.ts +95 -0
  41. package/dist/types/new-metrics.d.ts +119 -0
  42. package/package.json +12 -8
  43. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +51 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +408 -0
  45. package/src/call-diagnostic/call-diagnostic-metrics.ts +655 -0
  46. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +280 -0
  47. package/src/call-diagnostic/config.ts +578 -0
  48. package/src/call-diagnostic/generated-types-temp/ClientEvent.ts +2395 -0
  49. package/src/call-diagnostic/generated-types-temp/Event.ts +7762 -0
  50. package/src/call-diagnostic/generated-types-temp/MediaQualityEvent.ts +2321 -0
  51. package/src/config.js +19 -0
  52. package/src/index.ts +41 -0
  53. package/src/metrics.js +25 -27
  54. package/src/metrics.types.ts +140 -0
  55. package/src/new-metrics.ts +223 -0
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +243 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +474 -0
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1015 -0
  59. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +454 -0
  60. package/test/unit/spec/metrics.js +65 -97
  61. package/test/unit/spec/new-metrics.ts +155 -0
  62. package/tsconfig.json +6 -0
  63. package/dist/call-diagnostic-events-batcher.js +0 -60
  64. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  65. package/src/call-diagnostic-events-batcher.js +0 -62
  66. package/src/index.js +0 -17
  67. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
@@ -0,0 +1,1015 @@
1
+ import sinon from 'sinon';
2
+ import {assert} from '@webex/test-helper-chai';
3
+
4
+ import CallDiagnosticMetrics from '../../../../src/call-diagnostic/call-diagnostic-metrics';
5
+ import CallDiagnosticLatencies from '../../../../src/call-diagnostic/call-diagnostic-metrics-latencies';
6
+ import * as Utils from '../../../../src/call-diagnostic/call-diagnostic-metrics.util';
7
+ import {BrowserDetection} from '@webex/common';
8
+ import {getOSNameInternal} from '@webex/internal-plugin-metrics';
9
+ import uuid from 'uuid';
10
+
11
+ //@ts-ignore
12
+ global.window = {location: {hostname: 'whatever'}};
13
+
14
+ const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
15
+ const userAgent = `webex-js-sdk/test-webex-version client=Cantina; (os=${getOSName()}/${
16
+ getOSVersion().split('.')[0]
17
+ })`;
18
+
19
+ describe.only('internal-plugin-metrics', () => {
20
+ describe('CallDiagnosticMetrics', () => {
21
+ var now = new Date();
22
+
23
+ let cd: CallDiagnosticMetrics;
24
+
25
+ const fakeMeeting = {
26
+ id: '1',
27
+ correlationId: 'correlationId',
28
+ environment: 'meeting_evn',
29
+ locusUrl: 'locus/url',
30
+ locusInfo: {
31
+ fullState: {
32
+ lastActive: 'lastActive',
33
+ },
34
+ },
35
+ meetingInfo: {},
36
+ getCurUserType: () => 'host',
37
+ };
38
+
39
+ let webex;
40
+
41
+ beforeEach(() => {
42
+ webex = {
43
+ canAuthorize: true,
44
+ version: 'webex-version',
45
+ internal: {
46
+ services: {
47
+ get: () => 'locus-url',
48
+ },
49
+ metrics: {
50
+ submitClientMetrics: sinon.stub(),
51
+ },
52
+ newMetrics: {},
53
+ device: {
54
+ userId: 'userId',
55
+ url: 'deviceUrl',
56
+ orgId: 'orgId',
57
+ },
58
+ },
59
+ meetings: {
60
+ config: {
61
+ metrics: {
62
+ clientType: 'TEAMS_CLIENT',
63
+ subClientType: 'WEB_APP',
64
+ },
65
+ },
66
+ metrics: {
67
+ clientName: 'Cantina',
68
+ },
69
+ meetingCollection: {
70
+ get: () => fakeMeeting,
71
+ },
72
+ geoHintInfo: {
73
+ clientAddress: '1.3.4.5',
74
+ countryCode: 'UK',
75
+ },
76
+ },
77
+ credentials: {
78
+ isUnverifiedGuest: false,
79
+ },
80
+ prepareFetchOptions: sinon.stub().callsFake((opts: any) => ({...opts, foo: 'bar'})),
81
+ };
82
+
83
+ webex.internal.newMetrics.callDiagnosticLatencies = new CallDiagnosticLatencies(
84
+ {},
85
+ {parent: webex}
86
+ );
87
+
88
+ sinon.createSandbox();
89
+ sinon.useFakeTimers(now.getTime());
90
+ cd = new CallDiagnosticMetrics({}, {parent: webex});
91
+ sinon.stub(uuid, 'v4').returns('my-fake-id');
92
+ });
93
+
94
+ afterEach(() => {
95
+ sinon.restore();
96
+ });
97
+
98
+ describe('#getOrigin', () => {
99
+ it('should build origin correctly', () => {
100
+ sinon.stub(Utils, 'anonymizeIPAddress').returns('1.1.1.1');
101
+
102
+ //@ts-ignore
103
+ const res = cd.getOrigin(
104
+ {subClientType: 'WEB_APP', clientType: 'TEAMS_CLIENT'},
105
+ fakeMeeting.id
106
+ );
107
+
108
+ assert.deepEqual(res, {
109
+ clientInfo: {
110
+ browser: getBrowserName(),
111
+ browserVersion: getBrowserVersion(),
112
+ clientType: 'TEAMS_CLIENT',
113
+ clientVersion: 'webex-js-sdk/webex-version',
114
+ localNetworkPrefix: '1.1.1.1',
115
+ os: getOSNameInternal(),
116
+ osVersion: getOSVersion(),
117
+ subClientType: 'WEB_APP',
118
+ },
119
+ environment: 'meeting_evn',
120
+ name: 'endpoint',
121
+ networkType: 'unknown',
122
+ userAgent,
123
+ });
124
+ });
125
+
126
+ it('should build origin correctly with no meeting', () => {
127
+ sinon.stub(Utils, 'anonymizeIPAddress').returns('1.1.1.1');
128
+
129
+ //@ts-ignore
130
+ const res = cd.getOrigin();
131
+
132
+ assert.deepEqual(res, {
133
+ clientInfo: {
134
+ browser: getBrowserName(),
135
+ browserVersion: getBrowserVersion(),
136
+ clientType: 'TEAMS_CLIENT',
137
+ clientVersion: 'webex-js-sdk/webex-version',
138
+ localNetworkPrefix: '1.1.1.1',
139
+ os: getOSNameInternal(),
140
+ osVersion: getOSVersion(),
141
+ subClientType: 'WEB_APP',
142
+ },
143
+ name: 'endpoint',
144
+ networkType: 'unknown',
145
+ userAgent,
146
+ });
147
+ });
148
+
149
+ it('builds origin correctly, when overriding clientVersion', () => {
150
+ webex.meetings.config.metrics.clientVersion = '43.9.0.1234';
151
+
152
+ //@ts-ignore
153
+ const res = cd.getOrigin(
154
+ {subClientType: 'WEB_APP', clientType: 'TEAMS_CLIENT'},
155
+ fakeMeeting.id
156
+ );
157
+
158
+ assert.deepEqual(res, {
159
+ clientInfo: {
160
+ browser: getBrowserName(),
161
+ browserVersion: getBrowserVersion(),
162
+ clientType: 'TEAMS_CLIENT',
163
+ "clientVersion": "43.9.0.1234",
164
+ "localNetworkPrefix": "1.3.4.0",
165
+ "majorVersion": 43,
166
+ "minorVersion": 9,
167
+ os: getOSNameInternal(),
168
+ osVersion: getOSVersion(),
169
+ subClientType: 'WEB_APP',
170
+ },
171
+ environment: 'meeting_evn',
172
+ name: 'endpoint',
173
+ networkType: 'unknown',
174
+ userAgent,
175
+ });
176
+ })
177
+ });
178
+
179
+ describe('#getIdentifiers', () => {
180
+ it('should build identifiers correctly', () => {
181
+ const res = cd.getIdentifiers({
182
+ mediaConnections: [
183
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
184
+ ],
185
+ meeting: fakeMeeting,
186
+ });
187
+
188
+ assert.deepEqual(res, {
189
+ correlationId: 'correlationId',
190
+ deviceId: 'deviceUrl',
191
+ locusId: 'url',
192
+ locusStartTime: 'lastActive',
193
+ locusUrl: 'locus/url',
194
+ mediaAgentAlias: 'mediaAgentAlias',
195
+ mediaAgentGroupId: 'mediaAgentGroupId',
196
+ orgId: 'orgId',
197
+ userId: 'userId',
198
+ });
199
+ });
200
+
201
+ it('should build identifiers correctly given correlationId', () => {
202
+ const res = cd.getIdentifiers({
203
+ correlationId: 'correlationId',
204
+ });
205
+
206
+ assert.deepEqual(res, {
207
+ correlationId: 'correlationId',
208
+ deviceId: 'deviceUrl',
209
+ locusUrl: 'locus-url',
210
+ orgId: 'orgId',
211
+ userId: 'userId',
212
+ });
213
+ });
214
+
215
+ it('should throw Error if correlationId is missing', () => {
216
+ assert.throws(() =>
217
+ cd.getIdentifiers({
218
+ mediaConnections: [
219
+ {mediaAgentAlias: 'mediaAgentAlias', mediaAgentGroupId: 'mediaAgentGroupId'},
220
+ ],
221
+ meeting: {...fakeMeeting, correlationId: undefined},
222
+ })
223
+ );
224
+ });
225
+ });
226
+
227
+ it('should prepare diagnostic event successfully', () => {
228
+ const options = {meetingId: fakeMeeting.id};
229
+ const getOriginStub = sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
230
+ const clearEmptyKeysRecursivelyStub = sinon.stub(Utils, 'clearEmptyKeysRecursively');
231
+
232
+ const res = cd.prepareDiagnosticEvent(
233
+ {
234
+ canProceed: false,
235
+ identifiers: {correlationId: 'id'},
236
+ name: 'client.alert.displayed',
237
+ },
238
+ options
239
+ );
240
+
241
+ assert.calledWith(getOriginStub, options, options.meetingId);
242
+ assert.calledOnce(clearEmptyKeysRecursivelyStub);
243
+ assert.deepEqual(res, {
244
+ event: {
245
+ canProceed: false,
246
+ identifiers: {
247
+ correlationId: 'id',
248
+ },
249
+ name: 'client.alert.displayed',
250
+ },
251
+ eventId: 'my-fake-id',
252
+ origin: {
253
+ origin: 'fake-origin',
254
+ },
255
+ originTime: {
256
+ sent: 'not_defined_yet',
257
+ triggered: now.toISOString(),
258
+ },
259
+ senderCountryCode: 'UK',
260
+ version: 1,
261
+ });
262
+ });
263
+
264
+ describe('#submitClientEvent', () => {
265
+ it('should submit client event successfully with meetingId', () => {
266
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
267
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
268
+ const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
269
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
270
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
271
+ const options = {
272
+ meetingId: fakeMeeting.id,
273
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
274
+ };
275
+
276
+ cd.submitClientEvent({
277
+ name: 'client.alert.displayed',
278
+ options,
279
+ });
280
+
281
+ assert.calledWith(getIdentifiersSpy, {
282
+ meeting: fakeMeeting,
283
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
284
+ });
285
+ assert.notCalled(generateClientEventErrorPayloadSpy);
286
+ assert.calledWith(
287
+ prepareDiagnosticEventSpy,
288
+ {
289
+ canProceed: true,
290
+ eventData: {
291
+ webClientDomain: 'whatever',
292
+ },
293
+ identifiers: {
294
+ correlationId: 'correlationId',
295
+ deviceId: 'deviceUrl',
296
+ locusId: 'url',
297
+ locusStartTime: 'lastActive',
298
+ locusUrl: 'locus/url',
299
+ mediaAgentAlias: 'alias',
300
+ mediaAgentGroupId: '1',
301
+ orgId: 'orgId',
302
+ userId: 'userId',
303
+ },
304
+ loginType: 'login-ci',
305
+ name: 'client.alert.displayed',
306
+ userType: 'host',
307
+ isConvergedArchitectureEnabled: undefined,
308
+ },
309
+ options
310
+ );
311
+ assert.calledWith(submitToCallDiagnosticsSpy, {
312
+ event: {
313
+ canProceed: true,
314
+ eventData: {
315
+ webClientDomain: 'whatever',
316
+ },
317
+ identifiers: {
318
+ correlationId: 'correlationId',
319
+ deviceId: 'deviceUrl',
320
+ locusId: 'url',
321
+ locusStartTime: 'lastActive',
322
+ locusUrl: 'locus/url',
323
+ mediaAgentAlias: 'alias',
324
+ mediaAgentGroupId: '1',
325
+ orgId: 'orgId',
326
+ userId: 'userId',
327
+ },
328
+ loginType: 'login-ci',
329
+ name: 'client.alert.displayed',
330
+ userType: 'host',
331
+ isConvergedArchitectureEnabled: undefined,
332
+ },
333
+ eventId: 'my-fake-id',
334
+ origin: {
335
+ origin: 'fake-origin',
336
+ },
337
+ originTime: {
338
+ sent: 'not_defined_yet',
339
+ triggered: now.toISOString(),
340
+ },
341
+ senderCountryCode: 'UK',
342
+ version: 1,
343
+ });
344
+ });
345
+
346
+ it('should submit client event successfully with correlationId', () => {
347
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
348
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
349
+ const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
350
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
351
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
352
+
353
+ const options = {
354
+ correlationId: 'correlationId',
355
+ };
356
+
357
+ cd.submitClientEvent({
358
+ name: 'client.alert.displayed',
359
+ options,
360
+ });
361
+
362
+ assert.calledWith(getIdentifiersSpy, {
363
+ correlationId: 'correlationId',
364
+ });
365
+
366
+ assert.notCalled(generateClientEventErrorPayloadSpy);
367
+ assert.calledWith(
368
+ prepareDiagnosticEventSpy,
369
+ {
370
+ canProceed: true,
371
+ eventData: {
372
+ webClientDomain: 'whatever',
373
+ },
374
+ identifiers: {
375
+ correlationId: 'correlationId',
376
+ deviceId: 'deviceUrl',
377
+ locusUrl: 'locus-url',
378
+ orgId: 'orgId',
379
+ userId: 'userId',
380
+ },
381
+ loginType: 'login-ci',
382
+ name: 'client.alert.displayed',
383
+ },
384
+ options
385
+ );
386
+ assert.calledWith(submitToCallDiagnosticsSpy, {
387
+ event: {
388
+ canProceed: true,
389
+ eventData: {
390
+ webClientDomain: 'whatever',
391
+ },
392
+ identifiers: {
393
+ correlationId: 'correlationId',
394
+ deviceId: 'deviceUrl',
395
+ locusUrl: 'locus-url',
396
+ orgId: 'orgId',
397
+ userId: 'userId',
398
+ },
399
+ loginType: 'login-ci',
400
+ name: 'client.alert.displayed',
401
+ },
402
+ eventId: 'my-fake-id',
403
+ origin: {
404
+ origin: 'fake-origin',
405
+ },
406
+ originTime: {
407
+ sent: 'not_defined_yet',
408
+ triggered: now.toISOString(),
409
+ },
410
+ senderCountryCode: 'UK',
411
+ version: 1,
412
+ });
413
+ });
414
+
415
+ it('it should include errors if provided with meetingId', () => {
416
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
417
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
418
+
419
+ const options = {
420
+ meetingId: fakeMeeting.id,
421
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
422
+ rawError: {
423
+ body: {
424
+ errorCode: 2409005,
425
+ },
426
+ },
427
+ };
428
+
429
+ cd.submitClientEvent({
430
+ name: 'client.alert.displayed',
431
+ options,
432
+ });
433
+
434
+ assert.calledWith(submitToCallDiagnosticsSpy, {
435
+ event: {
436
+ canProceed: true,
437
+ eventData: {
438
+ webClientDomain: 'whatever',
439
+ },
440
+ identifiers: {
441
+ correlationId: 'correlationId',
442
+ deviceId: 'deviceUrl',
443
+ locusId: 'url',
444
+ locusStartTime: 'lastActive',
445
+ locusUrl: 'locus/url',
446
+ mediaAgentAlias: 'alias',
447
+ mediaAgentGroupId: '1',
448
+ orgId: 'orgId',
449
+ userId: 'userId',
450
+ },
451
+ errors: [
452
+ {
453
+ category: 'expected',
454
+ errorDescription: 'StartRecordingFailed',
455
+ fatal: true,
456
+ name: 'other',
457
+ shownToUser: false,
458
+ serviceErrorCode: 2409005,
459
+ errorCode: 4029,
460
+ },
461
+ ],
462
+ loginType: 'login-ci',
463
+ name: 'client.alert.displayed',
464
+ userType: 'host',
465
+ isConvergedArchitectureEnabled: undefined,
466
+ },
467
+ eventId: 'my-fake-id',
468
+ origin: {
469
+ origin: 'fake-origin',
470
+ },
471
+ originTime: {
472
+ sent: 'not_defined_yet',
473
+ triggered: now.toISOString(),
474
+ },
475
+ senderCountryCode: 'UK',
476
+ version: 1,
477
+ });
478
+ });
479
+
480
+ it('it should include errors if provided with correlationId', () => {
481
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
482
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
483
+
484
+ const options = {
485
+ correlationId: 'correlationId',
486
+ rawError: {
487
+ body: {
488
+ errorCode: 2409005,
489
+ },
490
+ },
491
+ };
492
+
493
+ cd.submitClientEvent({
494
+ name: 'client.alert.displayed',
495
+ options,
496
+ });
497
+
498
+ assert.calledWith(submitToCallDiagnosticsSpy, {
499
+ event: {
500
+ canProceed: true,
501
+ eventData: {
502
+ webClientDomain: 'whatever',
503
+ },
504
+ identifiers: {
505
+ correlationId: 'correlationId',
506
+ deviceId: 'deviceUrl',
507
+ locusUrl: 'locus-url',
508
+ orgId: 'orgId',
509
+ userId: 'userId',
510
+ },
511
+ errors: [
512
+ {
513
+ category: 'expected',
514
+ errorDescription: 'StartRecordingFailed',
515
+ fatal: true,
516
+ name: 'other',
517
+ shownToUser: false,
518
+ serviceErrorCode: 2409005,
519
+ errorCode: 4029,
520
+ },
521
+ ],
522
+ loginType: 'login-ci',
523
+ name: 'client.alert.displayed',
524
+ },
525
+ eventId: 'my-fake-id',
526
+ origin: {
527
+ origin: 'fake-origin',
528
+ },
529
+ originTime: {
530
+ sent: 'not_defined_yet',
531
+ triggered: now.toISOString(),
532
+ },
533
+ senderCountryCode: 'UK',
534
+ version: 1,
535
+ });
536
+ });
537
+
538
+ it('should include errors in payload if provided via payload', () => {
539
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
540
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
541
+
542
+ const options = {
543
+ meetingId: fakeMeeting.id,
544
+ mediaConnections: [{mediaAgentAlias: 'alias', mediaAgentGroupId: '1'}],
545
+ };
546
+
547
+ cd.submitClientEvent({
548
+ name: 'client.alert.displayed',
549
+ payload: {
550
+ errors: [
551
+ {
552
+ name: 'locus.response',
553
+ fatal: true,
554
+ category: 'signaling',
555
+ shownToUser: false,
556
+ },
557
+ ],
558
+ },
559
+ options,
560
+ });
561
+
562
+ assert.calledWith(submitToCallDiagnosticsSpy, {
563
+ event: {
564
+ canProceed: true,
565
+ eventData: {
566
+ webClientDomain: 'whatever',
567
+ },
568
+ identifiers: {
569
+ correlationId: 'correlationId',
570
+ deviceId: 'deviceUrl',
571
+ locusId: 'url',
572
+ locusStartTime: 'lastActive',
573
+ locusUrl: 'locus/url',
574
+ mediaAgentAlias: 'alias',
575
+ mediaAgentGroupId: '1',
576
+ orgId: 'orgId',
577
+ userId: 'userId',
578
+ },
579
+ errors: [
580
+ {
581
+ name: 'locus.response',
582
+ fatal: true,
583
+ category: 'signaling',
584
+ shownToUser: false,
585
+ },
586
+ ],
587
+ loginType: 'login-ci',
588
+ name: 'client.alert.displayed',
589
+ userType: 'host',
590
+ isConvergedArchitectureEnabled: undefined,
591
+ },
592
+ eventId: 'my-fake-id',
593
+ origin: {
594
+ origin: 'fake-origin',
595
+ },
596
+ originTime: {
597
+ sent: 'not_defined_yet',
598
+ triggered: now.toISOString(),
599
+ },
600
+ senderCountryCode: 'UK',
601
+ version: 1,
602
+ });
603
+ });
604
+
605
+ it('should throw if meetingId nor correlationId not provided', () => {
606
+ assert.throws(() =>
607
+ cd.submitClientEvent({
608
+ name: 'client.alert.displayed',
609
+ })
610
+ );
611
+ });
612
+
613
+ it('should send behavioral event if meetingId provided but meeting is undefined', () => {
614
+ webex.meetings.meetingCollection.get = sinon.stub().returns(undefined);
615
+ cd.submitClientEvent({name: 'client.alert.displayed', options: {meetingId: 'meetingId'}});
616
+ assert.calledWith(
617
+ webex.internal.metrics.submitClientMetrics,
618
+ 'js_sdk_call_diagnostic_event_failed_to_send',
619
+ {
620
+ fields: {meetingId: 'meetingId', name: 'client.alert.displayed'},
621
+ }
622
+ );
623
+ });
624
+ });
625
+
626
+ it('should send request to call diagnostic batcher', () => {
627
+ const requestStub = sinon.stub();
628
+ //@ts-ignore
629
+ cd.callDiagnosticEventsBatcher = {request: requestStub};
630
+ //@ts-ignore
631
+ cd.submitToCallDiagnostics({event: 'test'});
632
+ assert.calledWith(requestStub, {eventPayload: {event: 'test'}, type: ['diagnostic-event']});
633
+ });
634
+
635
+ describe('#submitMQE', () => {
636
+ it('submits the event correctly', () => {
637
+ const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
638
+ const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
639
+ const getErrorPayloadForClientErrorCodeSpy = sinon.spy(
640
+ cd,
641
+ 'getErrorPayloadForClientErrorCode'
642
+ );
643
+ const getIdentifiersSpy = sinon.spy(cd, 'getIdentifiers');
644
+ sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
645
+ const options = {
646
+ networkType: 'wifi' as const,
647
+ meetingId: fakeMeeting.id,
648
+ };
649
+
650
+ cd.submitMQE({
651
+ name: 'client.mediaquality.event',
652
+ payload: {
653
+ //@ts-ignore
654
+ intervals: [{}],
655
+ },
656
+ options,
657
+ });
658
+
659
+ assert.calledWith(getIdentifiersSpy, {
660
+ meeting: fakeMeeting,
661
+ mediaConnections: undefined,
662
+ });
663
+ assert.notCalled(getErrorPayloadForClientErrorCodeSpy);
664
+ assert.calledWith(
665
+ prepareDiagnosticEventSpy,
666
+ {
667
+ name: 'client.mediaquality.event',
668
+ canProceed: true,
669
+ identifiers: {
670
+ correlationId: 'correlationId',
671
+ userId: 'userId',
672
+ deviceId: 'deviceUrl',
673
+ orgId: 'orgId',
674
+ locusUrl: 'locus/url',
675
+ locusId: 'url',
676
+ locusStartTime: 'lastActive',
677
+ },
678
+ eventData: {webClientDomain: 'whatever'},
679
+ intervals: [{}],
680
+ sourceMetadata: {
681
+ applicationSoftwareType: 'webex-js-sdk',
682
+ applicationSoftwareVersion: 'webex-version',
683
+ mediaEngineSoftwareType: 'browser',
684
+ mediaEngineSoftwareVersion: getOSVersion(),
685
+ startTime: now.toISOString(),
686
+ },
687
+ },
688
+ options
689
+ );
690
+
691
+ assert.calledWith(submitToCallDiagnosticsSpy, {
692
+ eventId: 'my-fake-id',
693
+ version: 1,
694
+ origin: {origin: 'fake-origin'},
695
+ originTime: {triggered: now.toISOString(), sent: 'not_defined_yet'},
696
+ senderCountryCode: 'UK',
697
+ event: {
698
+ name: 'client.mediaquality.event',
699
+ canProceed: true,
700
+ identifiers: {
701
+ correlationId: 'correlationId',
702
+ userId: 'userId',
703
+ deviceId: 'deviceUrl',
704
+ orgId: 'orgId',
705
+ locusUrl: 'locus/url',
706
+ locusId: 'url',
707
+ locusStartTime: 'lastActive',
708
+ },
709
+ eventData: {webClientDomain: 'whatever'},
710
+ intervals: [{}],
711
+ sourceMetadata: {
712
+ applicationSoftwareType: 'webex-js-sdk',
713
+ applicationSoftwareVersion: 'webex-version',
714
+ mediaEngineSoftwareType: 'browser',
715
+ mediaEngineSoftwareVersion: getOSVersion(),
716
+ startTime: now.toISOString(),
717
+ },
718
+ },
719
+ });
720
+ });
721
+
722
+ it('throws if meeting id not provided', () => {
723
+ assert.throws(() =>
724
+ cd.submitMQE({
725
+ name: 'client.mediaquality.event',
726
+ payload: {
727
+ //@ts-ignore
728
+ intervals: [{}],
729
+ },
730
+ //@ts-ignore
731
+ options: {meetingId: undefined, networkType: 'wifi'},
732
+ })
733
+ );
734
+ });
735
+
736
+ it('should send behavioral event if meeting is undefined', () => {
737
+ webex.meetings.meetingCollection.get = sinon.stub().returns(undefined);
738
+ cd.submitMQE({
739
+ name: 'client.mediaquality.event',
740
+ payload: {
741
+ //@ts-ignore
742
+ intervals: [{}],
743
+ },
744
+ options: {meetingId: 'meetingId'},
745
+ });
746
+ assert.calledWith(
747
+ webex.internal.metrics.submitClientMetrics,
748
+ 'js_sdk_call_diagnostic_event_failed_to_send',
749
+ {
750
+ fields: {meetingId: 'meetingId', name: 'client.mediaquality.event'},
751
+ }
752
+ );
753
+ });
754
+ });
755
+ describe('#getErrorPayloadForClientErrorCode', () => {
756
+ it('it should grab the payload for client error code correctly', () => {
757
+ const res = cd.getErrorPayloadForClientErrorCode({
758
+ clientErrorCode: 4008,
759
+ serviceErrorCode: 10000,
760
+ });
761
+ assert.deepEqual(res, {
762
+ category: 'signaling',
763
+ errorDescription: 'NewLocusError',
764
+ fatal: true,
765
+ name: 'other',
766
+ shownToUser: false,
767
+ errorCode: 4008,
768
+ serviceErrorCode: 10000,
769
+ });
770
+ });
771
+
772
+ it('it should return undefined if trying to get payload for client error code that doesnt exist', () => {
773
+ const res = cd.getErrorPayloadForClientErrorCode({
774
+ clientErrorCode: 123456,
775
+ serviceErrorCode: 100000,
776
+ });
777
+ assert.deepEqual(res, undefined);
778
+ });
779
+ });
780
+
781
+ describe('#generateClientEventErrorPayload', () => {
782
+ const defaultExpectedRes = {
783
+ category: 'expected',
784
+ errorDescription: 'StartRecordingFailed',
785
+ fatal: true,
786
+ name: 'other',
787
+ shownToUser: false,
788
+ errorCode: 4029,
789
+ serviceErrorCode: 2409005,
790
+ };
791
+
792
+ const checkNameError = (payload: any, isExpectedToBeCalled: boolean) => {
793
+ const res = cd.generateClientEventErrorPayload(payload);
794
+ const expectedResult = {
795
+ category: 'expected',
796
+ errorDescription: 'CameraPermissionDenied',
797
+ fatal: true,
798
+ name: 'other',
799
+ shownToUser: false,
800
+ serviceErrorCode: undefined,
801
+ errorCode: 4032,
802
+ errorData: {errorName: payload.name},
803
+ };
804
+
805
+ if (isExpectedToBeCalled) {
806
+ assert.deepEqual(res, expectedResult);
807
+ } else {
808
+ assert.notDeepEqual(res, expectedResult);
809
+ }
810
+ }
811
+
812
+ it('should generate media event error payload if rawError has a media error name', () => {
813
+ checkNameError({name: 'PermissionDeniedError'}, true);
814
+ });
815
+
816
+ it('should not generate media event error payload if rawError has a name that is not recognized', () => {
817
+ checkNameError({name: 'SomeRandomError'}, false);
818
+ });
819
+
820
+ const checkCodeError = (payload: any, expetedRes: any) => {
821
+ const res = cd.generateClientEventErrorPayload(payload);
822
+ assert.deepEqual(res, expetedRes);
823
+ }
824
+ it('should generate event error payload correctly', () => {
825
+ checkCodeError({body: {errorCode: 2409005}}, defaultExpectedRes)
826
+ });
827
+
828
+ it('should generate event error payload correctly if rawError has body.code', () => {
829
+ checkCodeError({body: {code: 2409005}}, defaultExpectedRes)
830
+ });
831
+
832
+ it('should generate event error payload correctly if rawError has body.reason.reasonCode', () => {
833
+ checkCodeError({body: {reason: {reasonCode: 2409005}}}, defaultExpectedRes);
834
+ });
835
+
836
+ it('should generate event error payload correctly if rawError has error.body.errorCode', () => {
837
+ checkCodeError({error: {body: {errorCode: 2409005}}}, defaultExpectedRes);
838
+ });
839
+
840
+ const checkLocusError = (payload: any, isExpectedToBeCalled: boolean) => {
841
+ const res = cd.generateClientEventErrorPayload(payload);
842
+ const expectedResult = {
843
+ category: 'signaling',
844
+ errorDescription: 'NewLocusError',
845
+ fatal: true,
846
+ name: 'other',
847
+ shownToUser: false,
848
+ serviceErrorCode: 2400000,
849
+ errorCode: 4008,
850
+ };
851
+
852
+ if (isExpectedToBeCalled) {
853
+ assert.deepEqual(res, expectedResult);
854
+ } else {
855
+ assert.notDeepEqual(res, expectedResult);
856
+ }
857
+ }
858
+
859
+ it('should return default new locus event error payload correctly if locus error is recognized', () => {
860
+ checkLocusError({body: {errorCode: 2400000}}, true);
861
+ });
862
+
863
+ it('should not return default new locus event error payload correctly if locus is not recognized', () => {
864
+ checkLocusError({body: {errorCode: 1400000}}, false);
865
+ });
866
+
867
+ const checkMeetingInfoError = (payload: any, isExpectedToBeCalled: boolean) => {
868
+ const res = cd.generateClientEventErrorPayload(payload);
869
+ const expectedResult = {
870
+ category: 'signaling',
871
+ errorDescription: 'MeetingInfoLookupError',
872
+ fatal: true,
873
+ name: 'other',
874
+ shownToUser: false,
875
+ serviceErrorCode: undefined,
876
+ errorCode: 4100,
877
+ };
878
+
879
+ if (isExpectedToBeCalled) {
880
+ assert.deepEqual(res, expectedResult);
881
+ } else {
882
+ assert.notDeepEqual(res, expectedResult);
883
+ }
884
+ }
885
+
886
+ it('should return default meeting info lookup error payload if data.meetingInfo was found on error body', () => {
887
+ checkMeetingInfoError({body: {data: {meetingInfo: 'something'}}}, true);
888
+ });
889
+
890
+ it('should return default meeting info lookup error payload if body.url contains wbxappapi', () => {
891
+ checkMeetingInfoError({body: {url: '1234567-wbxappapiabcdefg'}}, true);
892
+ });
893
+
894
+
895
+ it('should not return default meeting info lookup error payload if body.url does not contain wbxappapi and data.meetingInfo was not found on error body', () => {
896
+ checkMeetingInfoError({body: {data: '1234567-wbxappapiabcdefg'}}, false);
897
+ });
898
+
899
+ it('should return unknown error otherwise', () => {
900
+ const res = cd.generateClientEventErrorPayload({somethgin: 'new'});
901
+ assert.deepEqual(res, {
902
+ category: 'other',
903
+ errorDescription: 'UnknownError',
904
+ fatal: true,
905
+ name: 'other',
906
+ shownToUser: false,
907
+ serviceErrorCode: 9999,
908
+ errorCode: 9999,
909
+ });
910
+ });
911
+ });
912
+
913
+ describe('#getCurLoginType', () => {
914
+ it('returns login-ci if not unverified guest', () => {
915
+ webex.credentials.isUnverifiedGuest = false;
916
+ assert.deepEqual(cd.getCurLoginType(), 'login-ci');
917
+ });
918
+ it('returns unverified guest', () => {
919
+ webex.credentials.isUnverifiedGuest = true;
920
+ assert.deepEqual(cd.getCurLoginType(), 'unverified-guest');
921
+ });
922
+ });
923
+
924
+ describe('#getIsConvergedArchitectureEnabled', () => {
925
+ it('returns true if converged architecture is enabled', () => {
926
+ fakeMeeting.meetingInfo = {enableConvergedArchitecture: true};
927
+ assert.deepEqual(cd.getIsConvergedArchitectureEnabled({meetingId: fakeMeeting.id}), true);
928
+ });
929
+ it('returns false if converged architecture is not enabled', () => {
930
+ fakeMeeting.meetingInfo = {enableConvergedArchitecture: false};
931
+ assert.deepEqual(cd.getIsConvergedArchitectureEnabled({meetingId: fakeMeeting.id}), false);
932
+
933
+ });
934
+ it('returns undefined if converged architecture is not defined', () => {
935
+ fakeMeeting.meetingInfo = {};
936
+ assert.deepEqual(cd.getIsConvergedArchitectureEnabled({meetingId: fakeMeeting.id}), undefined);
937
+ });
938
+ })
939
+
940
+ describe('#buildClientEventFetchRequestOptions', () => {
941
+ it('returns expected options', async () => {
942
+ const options = {
943
+ meetingId: fakeMeeting.id,
944
+ };
945
+
946
+ const triggered = new Date();
947
+ const fetchOptions = await cd.buildClientEventFetchRequestOptions({
948
+ name: 'client.exit.app',
949
+ payload: {trigger: 'user-interaction', canProceed: false},
950
+ options,
951
+ });
952
+
953
+ assert.deepEqual(fetchOptions, {
954
+ body: {
955
+ metrics: [
956
+ {
957
+ eventPayload: {
958
+ event: {
959
+ canProceed: false,
960
+ eventData: {
961
+ webClientDomain: 'whatever',
962
+ },
963
+ identifiers: {
964
+ correlationId: 'correlationId',
965
+ deviceId: 'deviceUrl',
966
+ locusId: 'url',
967
+ locusStartTime: 'lastActive',
968
+ locusUrl: 'locus/url',
969
+ orgId: 'orgId',
970
+ userId: 'userId',
971
+ },
972
+ loginType: 'login-ci',
973
+ name: 'client.exit.app',
974
+ trigger: 'user-interaction',
975
+ userType: 'host',
976
+ isConvergedArchitectureEnabled: undefined,
977
+ },
978
+ eventId: 'my-fake-id',
979
+ origin: {
980
+ buildType: 'test',
981
+ clientInfo: {
982
+ clientType: 'TEAMS_CLIENT',
983
+ clientVersion: 'webex-js-sdk/webex-version',
984
+ localNetworkPrefix:
985
+ Utils.anonymizeIPAddress(webex.meetings.geoHintInfo?.clientAddress) ||
986
+ undefined,
987
+ os: getOSNameInternal() || 'unknown',
988
+ osVersion: getOSVersion(),
989
+ subClientType: 'WEB_APP',
990
+ },
991
+ environment: 'meeting_evn',
992
+ name: 'endpoint',
993
+ networkType: 'unknown',
994
+ userAgent,
995
+ },
996
+ originTime: {
997
+ sent: 'not_defined_yet',
998
+ triggered: triggered.toISOString(),
999
+ },
1000
+ senderCountryCode: webex.meetings.geoHintInfo?.countryCode,
1001
+ version: 1,
1002
+ },
1003
+ type: ['diagnostic-event'],
1004
+ },
1005
+ ],
1006
+ },
1007
+ foo: 'bar',
1008
+ method: 'POST',
1009
+ resource: 'clientmetrics',
1010
+ service: 'metrics',
1011
+ });
1012
+ });
1013
+ });
1014
+ });
1015
+ });