@webex/internal-plugin-metrics 3.0.0-beta.27 → 3.0.0-beta.271

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