@webex/internal-plugin-metrics 3.0.0-beta.26 → 3.0.0-beta.261

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