@webex/internal-plugin-metrics 3.0.0-beta.4 → 3.0.0-beta.400

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 (74) hide show
  1. package/README.md +1 -3
  2. package/dist/batcher.js +42 -22
  3. package/dist/batcher.js.map +1 -1
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +508 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js +860 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +367 -0
  11. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  12. package/dist/call-diagnostic/config.js +627 -0
  13. package/dist/call-diagnostic/config.js.map +1 -0
  14. package/dist/client-metrics-batcher.js +3 -8
  15. package/dist/client-metrics-batcher.js.map +1 -1
  16. package/dist/config.js +23 -6
  17. package/dist/config.js.map +1 -1
  18. package/dist/index.js +46 -10
  19. package/dist/index.js.map +1 -1
  20. package/dist/metrics.js +47 -80
  21. package/dist/metrics.js.map +1 -1
  22. package/dist/metrics.types.js +7 -0
  23. package/dist/metrics.types.js.map +1 -0
  24. package/dist/new-metrics.js +300 -0
  25. package/dist/new-metrics.js.map +1 -0
  26. package/dist/prelogin-metrics-batcher.js +82 -0
  27. package/dist/prelogin-metrics-batcher.js.map +1 -0
  28. package/dist/types/batcher.d.ts +7 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +218 -0
  31. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +421 -0
  32. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +103 -0
  33. package/dist/types/call-diagnostic/config.d.ts +178 -0
  34. package/dist/types/client-metrics-batcher.d.ts +2 -0
  35. package/dist/types/config.d.ts +36 -0
  36. package/dist/types/index.d.ts +15 -0
  37. package/dist/types/metrics.d.ts +3 -0
  38. package/dist/types/metrics.types.d.ts +105 -0
  39. package/dist/types/new-metrics.d.ts +131 -0
  40. package/dist/types/prelogin-metrics-batcher.d.ts +2 -0
  41. package/dist/types/utils.d.ts +6 -0
  42. package/dist/utils.js +27 -0
  43. package/dist/utils.js.map +1 -0
  44. package/package.json +16 -8
  45. package/src/batcher.js +71 -26
  46. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +72 -0
  47. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +467 -0
  48. package/src/call-diagnostic/call-diagnostic-metrics.ts +919 -0
  49. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +395 -0
  50. package/src/call-diagnostic/config.ts +685 -0
  51. package/src/client-metrics-batcher.js +4 -4
  52. package/src/config.js +26 -5
  53. package/src/index.ts +56 -0
  54. package/src/metrics.js +47 -58
  55. package/src/metrics.types.ts +170 -0
  56. package/src/new-metrics.ts +278 -0
  57. package/src/prelogin-metrics-batcher.ts +95 -0
  58. package/src/utils.ts +17 -0
  59. package/test/unit/spec/batcher.js +28 -15
  60. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +457 -0
  61. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +657 -0
  62. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2303 -0
  63. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +634 -0
  64. package/test/unit/spec/client-metrics-batcher.js +28 -15
  65. package/test/unit/spec/metrics.js +94 -116
  66. package/test/unit/spec/new-metrics.ts +231 -0
  67. package/test/unit/spec/prelogin-metrics-batcher.ts +250 -0
  68. package/test/unit/spec/utils.ts +22 -0
  69. package/tsconfig.json +6 -0
  70. package/dist/call-diagnostic-events-batcher.js +0 -70
  71. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  72. package/src/call-diagnostic-events-batcher.js +0 -62
  73. package/src/index.js +0 -17
  74. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -180
@@ -0,0 +1,467 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ /* eslint-disable valid-jsdoc */
3
+ import {WebexPlugin} from '@webex/webex-core';
4
+
5
+ import {MetricEventNames, PreComputedLatencies} from '../metrics.types';
6
+
7
+ // we only care about client event and feature event for now
8
+
9
+ /**
10
+ * @description Helper class to store latencies timestamp and to calculate various latencies for CA.
11
+ * @exports
12
+ * @class CallDiagnosticLatencies
13
+ */
14
+ export default class CallDiagnosticLatencies extends WebexPlugin {
15
+ latencyTimestamps: Map<MetricEventNames, number>;
16
+ precomputedLatencies: Map<PreComputedLatencies, number>;
17
+ // meetingId that the current latencies are for
18
+ private meetingId?: string;
19
+
20
+ /**
21
+ * @constructor
22
+ */
23
+ constructor(...args) {
24
+ super(...args);
25
+ this.latencyTimestamps = new Map();
26
+ this.precomputedLatencies = new Map();
27
+ }
28
+
29
+ /**
30
+ * Clear timestamps
31
+ */
32
+ public clearTimestamps() {
33
+ this.latencyTimestamps.clear();
34
+ }
35
+
36
+ /**
37
+ * Associate current latencies with a meeting id
38
+ * @param meetingId
39
+ */
40
+ private setMeetingId(meetingId: string) {
41
+ this.meetingId = meetingId;
42
+ }
43
+
44
+ /**
45
+ * Returns the meeting object associated with current latencies
46
+ * @returns meeting object
47
+ */
48
+ private getMeeting() {
49
+ if (this.meetingId) {
50
+ // @ts-ignore
51
+ return this.webex.meetings.meetingCollection.get(this.meetingId);
52
+ }
53
+
54
+ return undefined;
55
+ }
56
+
57
+ /**
58
+ * Store timestamp value
59
+ * @param key - key
60
+ * @param value -value
61
+ * @throws
62
+ * @returns
63
+ */
64
+ public saveTimestamp({
65
+ key,
66
+ value = new Date().getTime(),
67
+ options = {},
68
+ }: {
69
+ key: MetricEventNames;
70
+ value?: number;
71
+ options?: {meetingId?: string};
72
+ }) {
73
+ // save the meetingId so we can use the meeting object in latency calculations if needed
74
+ const {meetingId} = options;
75
+ if (meetingId) {
76
+ this.setMeetingId(meetingId);
77
+ }
78
+ // for some events we're only interested in the first timestamp not last
79
+ // as these events can happen multiple times
80
+ if (
81
+ key === 'client.media.rx.start' ||
82
+ key === 'client.media.tx.start' ||
83
+ key === 'internal.client.meetinginfo.request' ||
84
+ key === 'internal.client.meetinginfo.response'
85
+ ) {
86
+ this.saveFirstTimestampOnly(key, value);
87
+ } else {
88
+ this.latencyTimestamps.set(key, value);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Store precomputed latency value
94
+ * @param key - key
95
+ * @param value - value
96
+ * @param overwrite - overwrite existing value or add it
97
+ * @throws
98
+ * @returns
99
+ */
100
+ public saveLatency(key: PreComputedLatencies, value: number, overwrite = true) {
101
+ const existingValue = overwrite ? 0 : this.precomputedLatencies.get(key) || 0;
102
+ this.precomputedLatencies.set(key, value + existingValue);
103
+ }
104
+
105
+ /**
106
+ * Measure latency for a request
107
+ * @param key - key
108
+ * @param callback - callback for which you would like to measure latency
109
+ * @param overwrite - overwite existing value or add to it
110
+ * @returns
111
+ */
112
+ public measureLatency(
113
+ callback: () => Promise<any>,
114
+ key: PreComputedLatencies,
115
+ overwrite = false
116
+ ) {
117
+ const start = performance.now();
118
+
119
+ return callback().finally(() => {
120
+ this.saveLatency(key, performance.now() - start, overwrite);
121
+ });
122
+ }
123
+
124
+ /**
125
+ * Store only the first timestamp value for the given key
126
+ * @param key - key
127
+ * @param value -value
128
+ * @throws
129
+ * @returns
130
+ */
131
+ saveFirstTimestampOnly(key: MetricEventNames, value: number = new Date().getTime()) {
132
+ if (this.latencyTimestamps.has(key)) {
133
+ return;
134
+ }
135
+ this.latencyTimestamps.set(key, value);
136
+ }
137
+
138
+ /**
139
+ * Helper to calculate end - start
140
+ * @param a start
141
+ * @param b end
142
+ * @returns latency
143
+ */
144
+ public getDiffBetweenTimestamps(a: MetricEventNames, b: MetricEventNames) {
145
+ const start = this.latencyTimestamps.get(a);
146
+ const end = this.latencyTimestamps.get(b);
147
+ if (start && end) {
148
+ return end - start;
149
+ }
150
+
151
+ return undefined;
152
+ }
153
+
154
+ /**
155
+ * Meeting Info Request
156
+ * @note Meeting Info request happen not just in the join phase. CA requires
157
+ * metrics around meeting info request that are only part of join phase.
158
+ * This internal.* event is used to track the real timestamps
159
+ * (when the actual request/response happen). This is because the actual CA event is
160
+ * sent inside the join method on the meeting object based on some logic, but that's not exactly when
161
+ * those events are actually fired. The logic only confirms that they have happened, and we send them over.
162
+ * @returns - latency
163
+ */
164
+ public getMeetingInfoReqResp() {
165
+ return this.getDiffBetweenTimestamps(
166
+ 'internal.client.meetinginfo.request',
167
+ 'internal.client.meetinginfo.response'
168
+ );
169
+ }
170
+
171
+ /**
172
+ * Interstitial Time
173
+ * @returns - latency
174
+ */
175
+ public getShowInterstitialTime() {
176
+ return this.getDiffBetweenTimestamps(
177
+ 'client.interstitial-window.start-launch',
178
+ 'internal.client.interstitial-window.click.joinbutton'
179
+ );
180
+ }
181
+
182
+ /**
183
+ * getU2CTime
184
+ * @returns - latency
185
+ */
186
+ public getU2CTime() {
187
+ const u2cLatency = this.precomputedLatencies.get('internal.get.u2c.time');
188
+
189
+ return u2cLatency ? Math.floor(u2cLatency) : undefined;
190
+ }
191
+
192
+ /**
193
+ * Device Register Time
194
+ * @returns - latency
195
+ */
196
+ public getRegisterWDMDeviceJMT() {
197
+ return this.getDiffBetweenTimestamps(
198
+ 'internal.register.device.request',
199
+ 'internal.register.device.response'
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Call Init Join Request
205
+ * @returns - latency
206
+ */
207
+ public getCallInitJoinReq() {
208
+ return this.getDiffBetweenTimestamps(
209
+ 'internal.client.interstitial-window.click.joinbutton',
210
+ 'client.locus.join.request'
211
+ );
212
+ }
213
+
214
+ /**
215
+ * Locus Join Request
216
+ * @returns - latency
217
+ */
218
+ public getJoinReqResp() {
219
+ return this.getDiffBetweenTimestamps('client.locus.join.request', 'client.locus.join.response');
220
+ }
221
+
222
+ /**
223
+ * Time taken to do turn discovery
224
+ * @returns - latency
225
+ */
226
+ public getTurnDiscoveryTime() {
227
+ return this.getDiffBetweenTimestamps(
228
+ 'internal.client.add-media.turn-discovery.start',
229
+ 'internal.client.add-media.turn-discovery.end'
230
+ );
231
+ }
232
+
233
+ /**
234
+ * Local SDP Generated Remote SDP REceived
235
+ * @returns - latency
236
+ */
237
+ public getLocalSDPGenRemoteSDPRecv() {
238
+ return this.getDiffBetweenTimestamps(
239
+ 'client.media-engine.local-sdp-generated',
240
+ 'client.media-engine.remote-sdp-received'
241
+ );
242
+ }
243
+
244
+ /**
245
+ * ICE Setup Time
246
+ * @returns - latency
247
+ */
248
+ public getICESetupTime() {
249
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
250
+ }
251
+
252
+ /**
253
+ * Audio ICE time
254
+ * @returns - latency
255
+ */
256
+ public getAudioICESetupTime() {
257
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
258
+ }
259
+
260
+ /**
261
+ * Video ICE Time
262
+ * @returns - latency
263
+ */
264
+ public getVideoICESetupTime() {
265
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
266
+ }
267
+
268
+ /**
269
+ * Share ICE Time
270
+ * @returns - latency
271
+ */
272
+ public getShareICESetupTime() {
273
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
274
+ }
275
+
276
+ /**
277
+ * Stay Lobby Time
278
+ * @returns - latency
279
+ */
280
+ public getStayLobbyTime() {
281
+ return this.getDiffBetweenTimestamps(
282
+ 'client.locus.join.response',
283
+ 'internal.host.meeting.participant.admitted'
284
+ );
285
+ }
286
+
287
+ /**
288
+ * Page JMT
289
+ * @returns - latency
290
+ */
291
+ public getPageJMT() {
292
+ return this.precomputedLatencies.get('internal.client.pageJMT') || undefined;
293
+ }
294
+
295
+ /**
296
+ * Download Time JMT
297
+ * @returns - latency
298
+ */
299
+ public getDownloadTimeJMT() {
300
+ return this.precomputedLatencies.get('internal.download.time') || undefined;
301
+ }
302
+
303
+ /**
304
+ * Click To Interstitial
305
+ * @returns - latency
306
+ */
307
+ public getClickToInterstitial() {
308
+ // for normal join (where green join button exists before interstitial, i.e reminder, space list etc)
309
+ if (this.latencyTimestamps.get('internal.client.meeting.click.joinbutton')) {
310
+ return this.getDiffBetweenTimestamps(
311
+ 'internal.client.meeting.click.joinbutton',
312
+ 'internal.client.meeting.interstitial-window.showed'
313
+ );
314
+ }
315
+
316
+ // for cross launch and guest flows
317
+ return this.precomputedLatencies.get('internal.click.to.interstitial') || undefined;
318
+ }
319
+
320
+ /**
321
+ * Interstitial To Join Ok
322
+ * @returns - latency
323
+ */
324
+ public getInterstitialToJoinOK() {
325
+ return this.getDiffBetweenTimestamps(
326
+ 'internal.client.interstitial-window.click.joinbutton',
327
+ 'client.locus.join.response'
328
+ );
329
+ }
330
+
331
+ /**
332
+ * Call Init To MediaEngineReady
333
+ * @returns - latency
334
+ */
335
+ public getCallInitMediaEngineReady() {
336
+ return this.getDiffBetweenTimestamps(
337
+ 'internal.client.interstitial-window.click.joinbutton',
338
+ 'client.media-engine.ready'
339
+ );
340
+ }
341
+
342
+ /**
343
+ * Interstitial To Media Ok
344
+ * @returns - latency
345
+ */
346
+ public getInterstitialToMediaOKJMT() {
347
+ const interstitialJoinClickTimestamp = this.latencyTimestamps.get(
348
+ 'internal.client.interstitial-window.click.joinbutton'
349
+ );
350
+
351
+ // get the first timestamp
352
+ const connectedMedia = this.latencyTimestamps.get('client.ice.end');
353
+
354
+ const lobbyTime = this.getStayLobbyTime() || 0;
355
+
356
+ if (interstitialJoinClickTimestamp && connectedMedia) {
357
+ return connectedMedia - interstitialJoinClickTimestamp - lobbyTime;
358
+ }
359
+
360
+ return undefined;
361
+ }
362
+
363
+ /**
364
+ * Total JMT
365
+ * @returns - latency
366
+ */
367
+ public getTotalJMT() {
368
+ const clickToInterstitial = this.getClickToInterstitial();
369
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
370
+
371
+ if (clickToInterstitial && interstitialToJoinOk) {
372
+ return clickToInterstitial + interstitialToJoinOk;
373
+ }
374
+
375
+ return undefined;
376
+ }
377
+
378
+ /**
379
+ * Join Conf JMT
380
+ * @returns - latency
381
+ */
382
+ public getJoinConfJMT() {
383
+ const joinReqResp = this.getJoinReqResp();
384
+ const ICESetupTime = this.getICESetupTime();
385
+
386
+ if (joinReqResp && ICESetupTime) {
387
+ return joinReqResp + ICESetupTime;
388
+ }
389
+
390
+ return undefined;
391
+ }
392
+
393
+ /**
394
+ * Total Media JMT
395
+ * @returns - latency
396
+ */
397
+ public getTotalMediaJMT() {
398
+ const clickToInterstitial = this.getClickToInterstitial();
399
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
400
+ const joinConfJMT = this.getJoinConfJMT();
401
+ const lobbyTime = this.getStayLobbyTime();
402
+
403
+ if (clickToInterstitial && interstitialToJoinOk && joinConfJMT) {
404
+ const totalMediaJMT = clickToInterstitial + interstitialToJoinOk + joinConfJMT;
405
+ if (this.getMeeting()?.allowMediaInLobby) {
406
+ return totalMediaJMT;
407
+ }
408
+
409
+ return totalMediaJMT - lobbyTime;
410
+ }
411
+
412
+ return undefined;
413
+ }
414
+
415
+ /**
416
+ * Client JMT
417
+ * @returns - latency
418
+ */
419
+ public getClientJMT() {
420
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
421
+ const joinConfJMT = this.getJoinConfJMT();
422
+
423
+ if (interstitialToJoinOk && joinConfJMT) {
424
+ return interstitialToJoinOk - joinConfJMT;
425
+ }
426
+
427
+ return undefined;
428
+ }
429
+
430
+ /**
431
+ * Audio setup delay receive
432
+ */
433
+ public getAudioJoinRespRxStart() {
434
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.rx.start');
435
+ }
436
+
437
+ /**
438
+ * Video setup delay receive
439
+ */
440
+ public getVideoJoinRespRxStart() {
441
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.rx.start');
442
+ }
443
+
444
+ /**
445
+ * Audio setup delay transmit
446
+ */
447
+ public getAudioJoinRespTxStart() {
448
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.tx.start');
449
+ }
450
+
451
+ /**
452
+ * Video setup delay transmit
453
+ */
454
+ public getVideoJoinRespTxStart() {
455
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.tx.start');
456
+ }
457
+
458
+ /**
459
+ * Total latency for all other app api requests.
460
+ * Excludes meeting info, because it's measured separately.
461
+ */
462
+ public getOtherAppApiReqResp() {
463
+ const otherAppApiJMT = this.precomputedLatencies.get('internal.other.app.api.time');
464
+
465
+ return otherAppApiJMT > 0 ? Math.floor(otherAppApiJMT) : undefined;
466
+ }
467
+ }