@webex/internal-plugin-metrics 3.0.0-beta.33 → 3.0.0-beta.330

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 +864 -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 +2035 -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,362 @@
1
+ /* eslint-disable valid-jsdoc */
2
+ import anonymize from 'ip-anonymize';
3
+ import util from 'util';
4
+
5
+ import {BrowserDetection} from '@webex/common';
6
+ import {WebexHttpError} from '@webex/webex-core';
7
+ import {isEmpty, merge} from 'lodash';
8
+ import {
9
+ ClientEvent,
10
+ Event,
11
+ MediaQualityEventAudioSetupDelayPayload,
12
+ MediaQualityEventVideoSetupDelayPayload,
13
+ MetricEventNames,
14
+ } from '../metrics.types';
15
+ import {
16
+ BROWSER_MEDIA_ERROR_NAME_TO_CLIENT_ERROR_CODES_MAP,
17
+ DTLS_HANDSHAKE_FAILED_CLIENT_CODE,
18
+ ICE_FAILED_WITHOUT_TURN_TLS_CLIENT_CODE,
19
+ ICE_FAILED_WITH_TURN_TLS_CLIENT_CODE,
20
+ ICE_FAILURE_CLIENT_CODE,
21
+ MISSING_ROAP_ANSWER_CLIENT_CODE,
22
+ WBX_APP_API_URL,
23
+ } from './config';
24
+
25
+ const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
26
+
27
+ export const anonymizeIPAddress = (localIp) => anonymize(localIp, 28, 96);
28
+
29
+ /**
30
+ * Returns a formated string of the user agent.
31
+ *
32
+ * @returns {string} formatted user agent information
33
+ */
34
+ export const userAgentToString = ({clientName, webexVersion}) => {
35
+ let userAgentOption;
36
+ let browserInfo;
37
+ const clientInfo = util.format('client=%s', `${clientName}`);
38
+
39
+ if (
40
+ ['chrome', 'firefox', 'msie', 'msedge', 'safari'].indexOf(getBrowserName().toLowerCase()) !== -1
41
+ ) {
42
+ browserInfo = util.format(
43
+ 'browser=%s',
44
+ `${getBrowserName().toLowerCase()}/${getBrowserVersion().split('.')[0]}`
45
+ );
46
+ }
47
+ const osInfo = util.format('os=%s', `${getOSName()}/${getOSVersion().split('.')[0]}`);
48
+
49
+ if (browserInfo) {
50
+ userAgentOption = `(${browserInfo}`;
51
+ }
52
+ if (osInfo) {
53
+ userAgentOption = userAgentOption
54
+ ? `${userAgentOption}; ${clientInfo}; ${osInfo}`
55
+ : `${clientInfo}; (${osInfo}`;
56
+ }
57
+ if (userAgentOption) {
58
+ userAgentOption += ')';
59
+
60
+ return util.format(
61
+ 'webex-js-sdk/%s %s',
62
+ `${process.env.NODE_ENV}-${webexVersion}`,
63
+ userAgentOption
64
+ );
65
+ }
66
+
67
+ return util.format('webex-js-sdk/%s', `${process.env.NODE_ENV}-${webexVersion}`);
68
+ };
69
+
70
+ /**
71
+ * Iterates object recursively and removes any
72
+ * property that returns isEmpty for it's associated value
73
+ * isEmpty = implementation from Lodash.
74
+ *
75
+ * It modifies the object in place (mutable)
76
+ *
77
+ * @param obj - input
78
+ * @returns
79
+ */
80
+ export const clearEmptyKeysRecursively = (obj: any) => {
81
+ // Check if the object is empty
82
+ if (Object.keys(obj).length === 0) {
83
+ return;
84
+ }
85
+
86
+ Object.keys(obj).forEach((key) => {
87
+ if (
88
+ (typeof obj[key] === 'object' || typeof obj[key] === 'string' || Array.isArray(obj[key])) &&
89
+ isEmpty(obj[key])
90
+ ) {
91
+ delete obj[key];
92
+ }
93
+ if (Array.isArray(obj[key])) {
94
+ obj[key] = [...obj[key].filter((x) => !!x)];
95
+ }
96
+ if (typeof obj[key] === 'object') {
97
+ clearEmptyKeysRecursively(obj[key]);
98
+ }
99
+ });
100
+ };
101
+
102
+ /**
103
+ * Locus error codes start with 2. The next three digits are the
104
+ * HTTP status code related to the error code (like 400, 403, 502, etc.)
105
+ * The remaining three digits are just an increasing integer.
106
+ * If it is 7 digits and starts with a 2, it is locus.
107
+ *
108
+ * @param errorCode
109
+ * @returns {boolean}
110
+ */
111
+ export const isLocusServiceErrorCode = (errorCode: string | number) => {
112
+ const code = `${errorCode}`;
113
+
114
+ if (code.length === 7 && code.charAt(0) === '2') {
115
+ return true;
116
+ }
117
+
118
+ return false;
119
+ };
120
+
121
+ /**
122
+ * MeetingInfo errors sometimes has body.data.meetingInfo object
123
+ * MeetingInfo errors come with a wbxappapi url
124
+ *
125
+ * @param {Object} rawError
126
+ * @returns {boolean}
127
+ */
128
+ export const isMeetingInfoServiceError = (rawError: any) => {
129
+ if (rawError.body?.data?.meetingInfo || rawError.body?.url?.includes(WBX_APP_API_URL)) {
130
+ return true;
131
+ }
132
+
133
+ return false;
134
+ };
135
+
136
+ /**
137
+ * Returns true if the raw error is a network related error
138
+ *
139
+ * @param {Object} rawError
140
+ * @returns {boolean}
141
+ */
142
+ export const isNetworkError = (rawError: any) => {
143
+ if (rawError instanceof WebexHttpError.NetworkOrCORSError) {
144
+ return true;
145
+ }
146
+
147
+ return false;
148
+ };
149
+
150
+ /**
151
+ * Returns true if the error is an unauthorized error
152
+ *
153
+ * @param {Object} rawError
154
+ * @returns {boolean}
155
+ */
156
+ export const isUnauthorizedError = (rawError: any) => {
157
+ if (rawError instanceof WebexHttpError.Unauthorized) {
158
+ return true;
159
+ }
160
+
161
+ return false;
162
+ };
163
+
164
+ /**
165
+ * MDN Media Devices getUserMedia() method returns a name if it errs
166
+ * Documentation can be found here: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
167
+ *
168
+ * @param errorCode
169
+ * @returns
170
+ */
171
+ export const isBrowserMediaErrorName = (errorName: any) => {
172
+ if (BROWSER_MEDIA_ERROR_NAME_TO_CLIENT_ERROR_CODES_MAP[errorName]) {
173
+ return true;
174
+ }
175
+
176
+ return false;
177
+ };
178
+
179
+ /**
180
+ * @param webClientDomain
181
+ * @returns
182
+ */
183
+ export const getBuildType = (
184
+ webClientDomain,
185
+ markAsTestEvent = false
186
+ ): Event['origin']['buildType'] => {
187
+ // used temporary to test pre join in production without creating noise data, SPARK-468456
188
+ if (markAsTestEvent) {
189
+ return 'test';
190
+ }
191
+
192
+ if (
193
+ webClientDomain?.includes('localhost') ||
194
+ webClientDomain?.includes('127.0.0.1') ||
195
+ process.env.NODE_ENV !== 'production'
196
+ ) {
197
+ return 'test';
198
+ }
199
+
200
+ return 'prod';
201
+ };
202
+
203
+ /**
204
+ * Prepare metric item for submission.
205
+ * @param {Object} webex sdk instance
206
+ * @param {Object} item
207
+ * @returns {Object} prepared item
208
+ */
209
+ export const prepareDiagnosticMetricItem = (webex: any, item: any) => {
210
+ const origin: Partial<Event['origin']> = {
211
+ buildType: exports.getBuildType(
212
+ item.eventPayload?.event?.eventData?.webClientDomain,
213
+ item.eventPayload?.event?.eventData?.markAsTestEvent
214
+ ),
215
+ networkType: 'unknown',
216
+ };
217
+
218
+ // check event names and append latencies?
219
+ const eventName = item.eventPayload?.event?.name as MetricEventNames;
220
+ const joinTimes: ClientEvent['payload']['joinTimes'] = {};
221
+ const audioSetupDelay: MediaQualityEventAudioSetupDelayPayload = {};
222
+ const videoSetupDelay: MediaQualityEventVideoSetupDelayPayload = {};
223
+
224
+ const cdl = webex.internal.newMetrics.callDiagnosticLatencies;
225
+
226
+ switch (eventName) {
227
+ case 'client.interstitial-window.launched':
228
+ joinTimes.meetingInfoReqResp = cdl.getMeetingInfoReqResp();
229
+ joinTimes.clickToInterstitial = cdl.getClickToInterstitial();
230
+ break;
231
+
232
+ case 'client.call.initiated':
233
+ joinTimes.meetingInfoReqResp = cdl.getMeetingInfoReqResp();
234
+ joinTimes.showInterstitialTime = cdl.getShowInterstitialTime();
235
+ break;
236
+
237
+ case 'client.locus.join.response':
238
+ joinTimes.meetingInfoReqResp = cdl.getMeetingInfoReqResp();
239
+ joinTimes.callInitJoinReq = cdl.getCallInitJoinReq();
240
+ joinTimes.joinReqResp = cdl.getJoinReqResp();
241
+ joinTimes.joinReqSentReceived = cdl.getJoinRespSentReceived();
242
+ joinTimes.pageJmt = cdl.getPageJMT();
243
+ joinTimes.clickToInterstitial = cdl.getClickToInterstitial();
244
+ joinTimes.interstitialToJoinOK = cdl.getInterstitialToJoinOK();
245
+ joinTimes.totalJmt = cdl.getTotalJMT();
246
+ joinTimes.clientJmt = cdl.getClientJMT();
247
+ break;
248
+
249
+ case 'client.ice.end':
250
+ joinTimes.ICESetupTime = cdl.getICESetupTime();
251
+ joinTimes.audioICESetupTime = cdl.getAudioICESetupTime();
252
+ joinTimes.videoICESetupTime = cdl.getVideoICESetupTime();
253
+ joinTimes.shareICESetupTime = cdl.getShareICESetupTime();
254
+ break;
255
+
256
+ case 'client.media.rx.start':
257
+ joinTimes.localSDPGenRemoteSDPRecv = cdl.getLocalSDPGenRemoteSDPRecv();
258
+ break;
259
+
260
+ case 'client.media-engine.ready':
261
+ joinTimes.totalMediaJMT = cdl.getTotalMediaJMT();
262
+ joinTimes.interstitialToMediaOKJMT = cdl.getInterstitialToMediaOKJMT();
263
+ joinTimes.callInitMediaEngineReady = cdl.getCallInitMediaEngineReady();
264
+ joinTimes.stayLobbyTime = cdl.getStayLobbyTime();
265
+ break;
266
+
267
+ case 'client.mediaquality.event':
268
+ audioSetupDelay.joinRespRxStart = cdl.getAudioJoinRespRxStart();
269
+ audioSetupDelay.joinRespTxStart = cdl.getAudioJoinRespTxStart();
270
+ videoSetupDelay.joinRespRxStart = cdl.getVideoJoinRespRxStart();
271
+ videoSetupDelay.joinRespTxStart = cdl.getVideoJoinRespTxStart();
272
+ }
273
+
274
+ if (!isEmpty(joinTimes)) {
275
+ item.eventPayload.event = merge(item.eventPayload.event, {joinTimes});
276
+ }
277
+
278
+ if (!isEmpty(audioSetupDelay)) {
279
+ item.eventPayload.event = merge(item.eventPayload.event, {audioSetupDelay});
280
+ }
281
+
282
+ if (!isEmpty(videoSetupDelay)) {
283
+ item.eventPayload.event = merge(item.eventPayload.event, {videoSetupDelay});
284
+ }
285
+
286
+ item.eventPayload.origin = Object.assign(origin, item.eventPayload.origin);
287
+
288
+ return item;
289
+ };
290
+
291
+ /**
292
+ * Sets the originTime value(s) before the request/fetch.
293
+ * This function is only useful if you are about to submit a metrics
294
+ * request using pre-built fetch options;
295
+ *
296
+ * @param {any} options
297
+ * @returns {any} the updated options object
298
+ */
299
+ export const setMetricTimings = (options) => {
300
+ if (options.body && options.json) {
301
+ const body = JSON.parse(options.body);
302
+
303
+ const now = new Date().toISOString();
304
+ body.metrics?.forEach((metric) => {
305
+ if (metric.eventPayload) {
306
+ // The event will effectively be triggered and sent at the same time.
307
+ // The existing triggered time is from when the options were built.
308
+ metric.eventPayload.originTime = {
309
+ triggered: now,
310
+ sent: now,
311
+ };
312
+ }
313
+ });
314
+ options.body = JSON.stringify(body);
315
+ }
316
+
317
+ return options;
318
+ };
319
+
320
+ export const extractVersionMetadata = (version: string) => {
321
+ // extract major and minor version
322
+ const [majorVersion, minorVersion] = version.split('.');
323
+
324
+ return {
325
+ majorVersion: parseInt(majorVersion, 10),
326
+ minorVersion: parseInt(minorVersion, 10),
327
+ };
328
+ };
329
+
330
+ /**
331
+ * Generates client error codes for specific ice failures
332
+ * that happen when trying to add media in a meeting.
333
+ */
334
+ export const generateClientErrorCodeForIceFailure = ({
335
+ signalingState,
336
+ iceConnectionState,
337
+ turnServerUsed,
338
+ }: {
339
+ signalingState: RTCPeerConnection['signalingState'];
340
+ iceConnectionState: RTCPeerConnection['iceConnectionState'];
341
+ turnServerUsed: boolean;
342
+ }) => {
343
+ let errorCode = ICE_FAILURE_CLIENT_CODE; // default;
344
+
345
+ if (signalingState === 'have-local-offer') {
346
+ errorCode = MISSING_ROAP_ANSWER_CLIENT_CODE;
347
+ }
348
+
349
+ if (signalingState === 'stable' && iceConnectionState === 'connected') {
350
+ errorCode = DTLS_HANDSHAKE_FAILED_CLIENT_CODE;
351
+ }
352
+
353
+ if (signalingState !== 'have-local-offer' && iceConnectionState !== 'connected') {
354
+ if (turnServerUsed) {
355
+ errorCode = ICE_FAILED_WITH_TURN_TLS_CLIENT_CODE;
356
+ } else {
357
+ errorCode = ICE_FAILED_WITHOUT_TURN_TLS_CLIENT_CODE;
358
+ }
359
+ }
360
+
361
+ return errorCode;
362
+ };