@webex/internal-plugin-metrics 3.0.0-beta.31 → 3.0.0-beta.310

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