@webex/internal-plugin-metrics 3.0.0-beta.32 → 3.0.0-beta.321

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 (68) hide show
  1. package/dist/batcher.js +2 -1
  2. package/dist/batcher.js.map +1 -1
  3. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +456 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.js +819 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +337 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  11. package/dist/call-diagnostic/config.js +610 -0
  12. package/dist/call-diagnostic/config.js.map +1 -0
  13. package/dist/client-metrics-batcher.js +2 -1
  14. package/dist/client-metrics-batcher.js.map +1 -1
  15. package/dist/config.js +22 -2
  16. package/dist/config.js.map +1 -1
  17. package/dist/index.js +30 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/metrics.js +30 -30
  20. package/dist/metrics.js.map +1 -1
  21. package/dist/metrics.types.js +7 -0
  22. package/dist/metrics.types.js.map +1 -0
  23. package/dist/new-metrics.js +333 -0
  24. package/dist/new-metrics.js.map +1 -0
  25. package/dist/types/batcher.d.ts +2 -0
  26. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  27. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +194 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +417 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +96 -0
  30. package/dist/types/call-diagnostic/config.d.ts +172 -0
  31. package/dist/types/client-metrics-batcher.d.ts +2 -0
  32. package/dist/types/config.d.ts +36 -0
  33. package/dist/types/index.d.ts +13 -0
  34. package/dist/types/metrics.d.ts +3 -0
  35. package/dist/types/metrics.types.d.ts +104 -0
  36. package/dist/types/new-metrics.d.ts +139 -0
  37. package/dist/types/utils.d.ts +6 -0
  38. package/dist/utils.js +27 -0
  39. package/dist/utils.js.map +1 -0
  40. package/package.json +13 -8
  41. package/src/batcher.js +1 -0
  42. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +75 -0
  43. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +419 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics.ts +861 -0
  45. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
  46. package/src/call-diagnostic/config.ts +666 -0
  47. package/src/client-metrics-batcher.js +1 -0
  48. package/src/config.js +20 -0
  49. package/src/index.ts +43 -0
  50. package/src/metrics.js +25 -27
  51. package/src/metrics.types.ts +160 -0
  52. package/src/new-metrics.ts +317 -0
  53. package/src/utils.ts +17 -0
  54. package/test/unit/spec/batcher.js +2 -0
  55. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +452 -0
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +506 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1973 -0
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
  59. package/test/unit/spec/client-metrics-batcher.js +2 -0
  60. package/test/unit/spec/metrics.js +66 -97
  61. package/test/unit/spec/new-metrics.ts +267 -0
  62. package/test/unit/spec/utils.ts +22 -0
  63. package/tsconfig.json +6 -0
  64. package/dist/call-diagnostic-events-batcher.js +0 -60
  65. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  66. package/src/call-diagnostic-events-batcher.js +0 -62
  67. package/src/index.js +0 -17
  68. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
@@ -0,0 +1,419 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ /* eslint-disable valid-jsdoc */
3
+ import {WebexPlugin} from '@webex/webex-core';
4
+
5
+ import {MetricEventNames} 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<string, 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
+ * @throws
97
+ * @returns
98
+ */
99
+ public saveLatency(key: string, value: number) {
100
+ this.precomputedLatencies.set(key, value);
101
+ }
102
+
103
+ /**
104
+ * Store only the first timestamp value for the given key
105
+ * @param key - key
106
+ * @param value -value
107
+ * @throws
108
+ * @returns
109
+ */
110
+ saveFirstTimestampOnly(key: MetricEventNames, value: number = new Date().getTime()) {
111
+ if (this.latencyTimestamps.has(key)) {
112
+ return;
113
+ }
114
+ this.latencyTimestamps.set(key, value);
115
+ }
116
+
117
+ /**
118
+ * Helper to calculate end - start
119
+ * @param a start
120
+ * @param b end
121
+ * @returns latency
122
+ */
123
+ public getDiffBetweenTimestamps(a: MetricEventNames, b: MetricEventNames) {
124
+ const start = this.latencyTimestamps.get(a);
125
+ const end = this.latencyTimestamps.get(b);
126
+ if (start && end) {
127
+ return end - start;
128
+ }
129
+
130
+ return undefined;
131
+ }
132
+
133
+ /**
134
+ * Meeting Info Request
135
+ * @note Meeting Info request happen not just in the join phase. CA requires
136
+ * metrics around meeting info request that are only part of join phase.
137
+ * This internal.* event is used to track the real timestamps
138
+ * (when the actual request/response happen). This is because the actual CA event is
139
+ * sent inside the join method on the meeting object based on some logic, but that's not exactly when
140
+ * those events are actually fired. The logic only confirms that they have happened, and we send them over.
141
+ * @returns - latency
142
+ */
143
+ public getMeetingInfoReqResp() {
144
+ return this.getDiffBetweenTimestamps(
145
+ 'internal.client.meetinginfo.request',
146
+ 'internal.client.meetinginfo.response'
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Interstitial Time
152
+ * @returns - latency
153
+ */
154
+ public getShowInterstitialTime() {
155
+ return this.getDiffBetweenTimestamps(
156
+ 'client.interstitial-window.start-launch',
157
+ 'internal.client.interstitial-window.click.joinbutton'
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Call Init Join Request
163
+ * @returns - latency
164
+ */
165
+ public getCallInitJoinReq() {
166
+ return this.getDiffBetweenTimestamps(
167
+ 'internal.client.interstitial-window.click.joinbutton',
168
+ 'client.locus.join.request'
169
+ );
170
+ }
171
+
172
+ /**
173
+ * Locus Join Request
174
+ * @returns - latency
175
+ */
176
+ public getJoinReqResp() {
177
+ return this.getDiffBetweenTimestamps('client.locus.join.request', 'client.locus.join.response');
178
+ }
179
+
180
+ /**
181
+ * Locus Join Response Sent Received
182
+ * @returns - latency
183
+ */
184
+ public getJoinRespSentReceived() {
185
+ // TODO: not clear SPARK-440554
186
+ return undefined;
187
+ }
188
+
189
+ /**
190
+ * Time taken to do turn discovery
191
+ * @returns - latency
192
+ */
193
+ public getTurnDiscoveryTime() {
194
+ return this.getDiffBetweenTimestamps(
195
+ 'internal.client.add-media.turn-discovery.start',
196
+ 'internal.client.add-media.turn-discovery.end'
197
+ );
198
+ }
199
+
200
+ /**
201
+ * Local SDP Generated Remote SDP REceived
202
+ * @returns - latency
203
+ */
204
+ public getLocalSDPGenRemoteSDPRecv() {
205
+ return this.getDiffBetweenTimestamps(
206
+ 'client.media-engine.local-sdp-generated',
207
+ 'client.media-engine.remote-sdp-received'
208
+ );
209
+ }
210
+
211
+ /**
212
+ * ICE Setup Time
213
+ * @returns - latency
214
+ */
215
+ public getICESetupTime() {
216
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
217
+ }
218
+
219
+ /**
220
+ * Audio ICE time
221
+ * @returns - latency
222
+ */
223
+ public getAudioICESetupTime() {
224
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
225
+ }
226
+
227
+ /**
228
+ * Video ICE Time
229
+ * @returns - latency
230
+ */
231
+ public getVideoICESetupTime() {
232
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
233
+ }
234
+
235
+ /**
236
+ * Share ICE Time
237
+ * @returns - latency
238
+ */
239
+ public getShareICESetupTime() {
240
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
241
+ }
242
+
243
+ /**
244
+ * Stay Lobby Time
245
+ * @returns - latency
246
+ */
247
+ public getStayLobbyTime() {
248
+ return this.getDiffBetweenTimestamps(
249
+ 'client.locus.join.response',
250
+ 'internal.host.meeting.participant.admitted'
251
+ );
252
+ }
253
+
254
+ /**
255
+ * Page JMT
256
+ * @returns - latency
257
+ */
258
+ public getPageJMT() {
259
+ return this.precomputedLatencies.get('internal.client.pageJMT') || undefined;
260
+ }
261
+
262
+ /**
263
+ * Click To Interstitial
264
+ * @returns - latency
265
+ */
266
+ public getClickToInterstitial() {
267
+ // for normal join (where green join button exists before interstitial, i.e reminder, space list etc)
268
+ if (this.latencyTimestamps.get('internal.client.meeting.click.joinbutton')) {
269
+ return this.getDiffBetweenTimestamps(
270
+ 'internal.client.meeting.click.joinbutton',
271
+ 'internal.client.meeting.interstitial-window.showed'
272
+ );
273
+ }
274
+
275
+ // for cross launch and guest flows
276
+ return this.precomputedLatencies.get('internal.click.to.interstitial') || undefined;
277
+ }
278
+
279
+ /**
280
+ * Interstitial To Join Ok
281
+ * @returns - latency
282
+ */
283
+ public getInterstitialToJoinOK() {
284
+ return this.getDiffBetweenTimestamps(
285
+ 'internal.client.interstitial-window.click.joinbutton',
286
+ 'client.locus.join.response'
287
+ );
288
+ }
289
+
290
+ /**
291
+ * Call Init To MediaEngineReady
292
+ * @returns - latency
293
+ */
294
+ public getCallInitMediaEngineReady() {
295
+ return this.getDiffBetweenTimestamps(
296
+ 'internal.client.interstitial-window.click.joinbutton',
297
+ 'client.media-engine.ready'
298
+ );
299
+ }
300
+
301
+ /**
302
+ * Interstitial To Media Ok
303
+ * @returns - latency
304
+ */
305
+ public getInterstitialToMediaOKJMT() {
306
+ const interstitialJoinClickTimestamp = this.latencyTimestamps.get(
307
+ 'internal.client.interstitial-window.click.joinbutton'
308
+ );
309
+
310
+ // get the first timestamp
311
+ const mediaFlowStartedTimestamp = Math.min(
312
+ this.latencyTimestamps.get('client.media.rx.start'),
313
+ this.latencyTimestamps.get('client.media.tx.start')
314
+ );
315
+
316
+ const lobbyTime = this.getStayLobbyTime() || 0;
317
+
318
+ if (interstitialJoinClickTimestamp && mediaFlowStartedTimestamp) {
319
+ return mediaFlowStartedTimestamp - interstitialJoinClickTimestamp - lobbyTime;
320
+ }
321
+
322
+ return undefined;
323
+ }
324
+
325
+ /**
326
+ * Total JMT
327
+ * @returns - latency
328
+ */
329
+ public getTotalJMT() {
330
+ const clickToInterstitial = this.getClickToInterstitial();
331
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
332
+
333
+ if (clickToInterstitial && interstitialToJoinOk) {
334
+ return clickToInterstitial + interstitialToJoinOk;
335
+ }
336
+
337
+ return undefined;
338
+ }
339
+
340
+ /**
341
+ * Join Conf JMT
342
+ * @returns - latency
343
+ */
344
+ public getJoinConfJMT() {
345
+ const joinReqResp = this.getJoinReqResp();
346
+ const ICESetupTime = this.getICESetupTime();
347
+
348
+ if (joinReqResp && ICESetupTime) {
349
+ return joinReqResp + ICESetupTime;
350
+ }
351
+
352
+ return undefined;
353
+ }
354
+
355
+ /**
356
+ * Total Media JMT
357
+ * @returns - latency
358
+ */
359
+ public getTotalMediaJMT() {
360
+ const clickToInterstitial = this.getClickToInterstitial();
361
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
362
+ const joinConfJMT = this.getJoinConfJMT();
363
+ const lobbyTime = this.getStayLobbyTime();
364
+
365
+ if (clickToInterstitial && interstitialToJoinOk && joinConfJMT) {
366
+ const totalMediaJMT = clickToInterstitial + interstitialToJoinOk + joinConfJMT;
367
+ if (this.getMeeting()?.allowMediaInLobby) {
368
+ return totalMediaJMT;
369
+ }
370
+
371
+ return totalMediaJMT - lobbyTime;
372
+ }
373
+
374
+ return undefined;
375
+ }
376
+
377
+ /**
378
+ * Client JMT
379
+ * @returns - latency
380
+ */
381
+ public getClientJMT() {
382
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
383
+ const joinConfJMT = this.getJoinConfJMT();
384
+
385
+ if (interstitialToJoinOk && joinConfJMT) {
386
+ return interstitialToJoinOk - joinConfJMT;
387
+ }
388
+
389
+ return undefined;
390
+ }
391
+
392
+ /**
393
+ * Audio setup delay receive
394
+ */
395
+ public getAudioJoinRespRxStart() {
396
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.rx.start');
397
+ }
398
+
399
+ /**
400
+ * Video setup delay receive
401
+ */
402
+ public getVideoJoinRespRxStart() {
403
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.rx.start');
404
+ }
405
+
406
+ /**
407
+ * Audio setup delay transmit
408
+ */
409
+ public getAudioJoinRespTxStart() {
410
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.tx.start');
411
+ }
412
+
413
+ /**
414
+ * Video setup delay transmit
415
+ */
416
+ public getVideoJoinRespTxStart() {
417
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.tx.start');
418
+ }
419
+ }