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

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 +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 +189 -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 +403 -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 +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 +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,744 @@
1
+ "use strict";
2
+
3
+ var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
4
+ var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
5
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
6
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
7
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
8
+ var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
9
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
10
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
11
+ _Object$defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.default = void 0;
15
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
16
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
17
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
18
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
19
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
20
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
21
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
22
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
23
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
25
+ var _merge2 = _interopRequireDefault(require("lodash/merge"));
26
+ var _internalPluginMetrics = require("@webex/internal-plugin-metrics");
27
+ var _common = require("@webex/common");
28
+ var _uuid = _interopRequireDefault(require("uuid"));
29
+ var _webexCore = require("@webex/webex-core");
30
+ var _callDiagnosticMetrics = require("./call-diagnostic-metrics.util");
31
+ var _config = require("../config");
32
+ var _callDiagnosticMetricsBatcher = _interopRequireDefault(require("./call-diagnostic-metrics-batcher"));
33
+ var _config2 = require("./config");
34
+ var _utils = require("../utils");
35
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
36
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
37
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
38
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39
+ var _BrowserDetection = (0, _common.BrowserDetection)(),
40
+ getOSVersion = _BrowserDetection.getOSVersion,
41
+ getBrowserName = _BrowserDetection.getBrowserName,
42
+ getBrowserVersion = _BrowserDetection.getBrowserVersion;
43
+ /**
44
+ * @description Util class to handle Call Analyzer Metrics
45
+ * @export
46
+ * @class CallDiagnosticMetrics
47
+ */
48
+ var CallDiagnosticMetrics = /*#__PURE__*/function (_StatelessWebexPlugin) {
49
+ (0, _inherits2.default)(CallDiagnosticMetrics, _StatelessWebexPlugin);
50
+ var _super = _createSuper(CallDiagnosticMetrics);
51
+ // @ts-ignore
52
+
53
+ // to avoid adding @ts-ignore everywhere
54
+
55
+ /**
56
+ * Constructor
57
+ * @param args
58
+ */
59
+ function CallDiagnosticMetrics() {
60
+ var _this;
61
+ (0, _classCallCheck2.default)(this, CallDiagnosticMetrics);
62
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
63
+ args[_key] = arguments[_key];
64
+ }
65
+ _this = _super.call.apply(_super, [this].concat(args));
66
+ // @ts-ignore
67
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "callDiagnosticEventsBatcher", void 0);
68
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "logger", void 0);
69
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "submitToCallDiagnosticsPreLogin", function (event, preLoginId) {
70
+ // build metrics-a event type
71
+ // @ts-ignore
72
+ var diagnosticEvent = (0, _callDiagnosticMetrics.prepareDiagnosticMetricItem)(_this.webex, {
73
+ eventPayload: event,
74
+ type: ['diagnostic-event']
75
+ });
76
+
77
+ // append sent timestamp
78
+ diagnosticEvent.eventPayload.originTime.sent = new Date().toISOString();
79
+ _this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, "CallDiagnosticMetrics: @submitToCallDiagnosticsPreLogin. Sending the request:", "diagnosticEvent: ".concat((0, _stringify.default)(diagnosticEvent)));
80
+
81
+ // @ts-ignore
82
+ return _this.webex.internal.newMetrics.postPreLoginMetric(diagnosticEvent, preLoginId);
83
+ });
84
+ _this.logger = _this.webex.logger;
85
+ // @ts-ignore
86
+ _this.callDiagnosticEventsBatcher = new _callDiagnosticMetricsBatcher.default({}, {
87
+ parent: _this.webex
88
+ });
89
+ return _this;
90
+ }
91
+
92
+ /**
93
+ * Returns the login type of the current user
94
+ * @returns one of 'login-ci','unverified-guest', null
95
+ */
96
+ (0, _createClass2.default)(CallDiagnosticMetrics, [{
97
+ key: "getCurLoginType",
98
+ value: function getCurLoginType() {
99
+ // @ts-ignore
100
+ if (this.webex.canAuthorize) {
101
+ // @ts-ignore
102
+ return this.webex.credentials.isUnverifiedGuest ? 'unverified-guest' : 'login-ci';
103
+ }
104
+ return null;
105
+ }
106
+
107
+ /**
108
+ * Returns if the meeting has converged architecture enabled
109
+ * @param options.meetingId
110
+ */
111
+ }, {
112
+ key: "getIsConvergedArchitectureEnabled",
113
+ value: function getIsConvergedArchitectureEnabled(_ref) {
114
+ var meetingId = _ref.meetingId;
115
+ if (meetingId) {
116
+ var _meeting$meetingInfo;
117
+ // @ts-ignore
118
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
119
+ return meeting === null || meeting === void 0 ? void 0 : (_meeting$meetingInfo = meeting.meetingInfo) === null || _meeting$meetingInfo === void 0 ? void 0 : _meeting$meetingInfo.enableConvergedArchitecture;
120
+ }
121
+ return undefined;
122
+ }
123
+
124
+ /**
125
+ * Get origin object for Call Diagnostic Event payload.
126
+ * @param options
127
+ * @param meetingId
128
+ * @returns
129
+ */
130
+ }, {
131
+ key: "getOrigin",
132
+ value: function getOrigin(options, meetingId) {
133
+ var _this$webex$meetings$, _this$webex$meetings$2, _this$webex$meetings$3, _this$webex$meetings$4, _this$webex$meetings$5, _this$webex$meetings$6;
134
+ var defaultClientType = // @ts-ignore
135
+ (_this$webex$meetings$ = this.webex.meetings.config) === null || _this$webex$meetings$ === void 0 ? void 0 : (_this$webex$meetings$2 = _this$webex$meetings$.metrics) === null || _this$webex$meetings$2 === void 0 ? void 0 : _this$webex$meetings$2.clientType;
136
+ var defaultSubClientType = // @ts-ignore
137
+ (_this$webex$meetings$3 = this.webex.meetings.config) === null || _this$webex$meetings$3 === void 0 ? void 0 : (_this$webex$meetings$4 = _this$webex$meetings$3.metrics) === null || _this$webex$meetings$4 === void 0 ? void 0 : _this$webex$meetings$4.subClientType;
138
+ // @ts-ignore
139
+ var providedClientVersion = (_this$webex$meetings$5 = this.webex.meetings.config) === null || _this$webex$meetings$5 === void 0 ? void 0 : (_this$webex$meetings$6 = _this$webex$meetings$5.metrics) === null || _this$webex$meetings$6 === void 0 ? void 0 : _this$webex$meetings$6.clientVersion;
140
+ // @ts-ignore
141
+ var defaultSDKClientVersion = "".concat(_config.CLIENT_NAME, "/").concat(this.webex.version);
142
+ var versionMetadata = {};
143
+
144
+ // sdk version split doesn't really make sense for now...
145
+ if (providedClientVersion) {
146
+ versionMetadata = (0, _callDiagnosticMetrics.extractVersionMetadata)(providedClientVersion);
147
+ }
148
+ if (defaultClientType && defaultSubClientType || options.clientType && options.subClientType) {
149
+ var _this$webex$meetings, _this$webex$meetings$7, _this$webex$meetings$8, _this$webex$meetings$9;
150
+ var origin = {
151
+ name: 'endpoint',
152
+ networkType: (options === null || options === void 0 ? void 0 : options.networkType) || 'unknown',
153
+ userAgent: (0, _callDiagnosticMetrics.userAgentToString)({
154
+ // @ts-ignore
155
+ clientName: (_this$webex$meetings = this.webex.meetings) === null || _this$webex$meetings === void 0 ? void 0 : (_this$webex$meetings$7 = _this$webex$meetings.config) === null || _this$webex$meetings$7 === void 0 ? void 0 : (_this$webex$meetings$8 = _this$webex$meetings$7.metrics) === null || _this$webex$meetings$8 === void 0 ? void 0 : _this$webex$meetings$8.clientName,
156
+ // @ts-ignore
157
+ webexVersion: this.webex.version
158
+ }),
159
+ clientInfo: _objectSpread(_objectSpread({
160
+ clientType: (options === null || options === void 0 ? void 0 : options.clientType) || defaultClientType,
161
+ clientVersion: providedClientVersion || defaultSDKClientVersion
162
+ }, versionMetadata), {}, {
163
+ localNetworkPrefix:
164
+ // @ts-ignore
165
+ (0, _callDiagnosticMetrics.anonymizeIPAddress)((_this$webex$meetings$9 = this.webex.meetings.geoHintInfo) === null || _this$webex$meetings$9 === void 0 ? void 0 : _this$webex$meetings$9.clientAddress) || undefined,
166
+ osVersion: getOSVersion() || 'unknown',
167
+ subClientType: (options === null || options === void 0 ? void 0 : options.subClientType) || defaultSubClientType,
168
+ os: (0, _internalPluginMetrics.getOSNameInternal)(),
169
+ browser: getBrowserName(),
170
+ browserVersion: getBrowserVersion()
171
+ })
172
+ };
173
+ if (meetingId) {
174
+ // @ts-ignore
175
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
176
+ if (meeting !== null && meeting !== void 0 && meeting.environment) {
177
+ origin.environment = meeting.environment;
178
+ }
179
+ }
180
+ if (options !== null && options !== void 0 && options.environment) {
181
+ origin.environment = options.environment;
182
+ }
183
+ if (options !== null && options !== void 0 && options.newEnvironment) {
184
+ origin.newEnvironment = options.newEnvironment;
185
+ }
186
+ if (options !== null && options !== void 0 && options.clientLaunchMethod) {
187
+ origin.clientInfo.clientLaunchMethod = options.clientLaunchMethod;
188
+ }
189
+ return origin;
190
+ }
191
+ throw new Error("ClientType and SubClientType can't be undefined");
192
+ }
193
+
194
+ /**
195
+ * Gather identifier details for call diagnostic payload.
196
+ * @throws Error if initialization fails.
197
+ * @param options
198
+ */
199
+ }, {
200
+ key: "getIdentifiers",
201
+ value: function getIdentifiers(options) {
202
+ var _meeting$locusInfo;
203
+ var meeting = options.meeting,
204
+ mediaConnections = options.mediaConnections,
205
+ correlationId = options.correlationId;
206
+ var identifiers = {
207
+ correlationId: 'unknown'
208
+ };
209
+ if (meeting) {
210
+ identifiers.correlationId = meeting.correlationId;
211
+ }
212
+ if (correlationId) {
213
+ identifiers.correlationId = correlationId;
214
+ }
215
+ // @ts-ignore
216
+ if (this.webex.internal) {
217
+ // @ts-ignore
218
+ var device = this.webex.internal.device;
219
+ identifiers.userId = device.userId;
220
+ identifiers.deviceId = device.url;
221
+ identifiers.orgId = device.orgId;
222
+ // @ts-ignore
223
+ identifiers.locusUrl = this.webex.internal.services.get('locus');
224
+ }
225
+ if (meeting !== null && meeting !== void 0 && (_meeting$locusInfo = meeting.locusInfo) !== null && _meeting$locusInfo !== void 0 && _meeting$locusInfo.fullState) {
226
+ identifiers.locusUrl = meeting.locusUrl;
227
+ identifiers.locusId = meeting.locusUrl && meeting.locusUrl.split('/').pop();
228
+ identifiers.locusStartTime = meeting.locusInfo.fullState && meeting.locusInfo.fullState.lastActive;
229
+ }
230
+ if (mediaConnections) {
231
+ var _mediaConnections$, _mediaConnections$2;
232
+ identifiers.mediaAgentAlias = mediaConnections === null || mediaConnections === void 0 ? void 0 : (_mediaConnections$ = mediaConnections[0]) === null || _mediaConnections$ === void 0 ? void 0 : _mediaConnections$.mediaAgentAlias;
233
+ identifiers.mediaAgentGroupId = mediaConnections === null || mediaConnections === void 0 ? void 0 : (_mediaConnections$2 = mediaConnections[0]) === null || _mediaConnections$2 === void 0 ? void 0 : _mediaConnections$2.mediaAgentGroupId;
234
+ }
235
+ if (identifiers.correlationId === undefined) {
236
+ throw new Error('Identifiers initialization failed.');
237
+ }
238
+ return identifiers;
239
+ }
240
+
241
+ /**
242
+ * Create diagnostic event, which can hold client event, feature event or MQE event data.
243
+ * This just initiates the shared properties that are required for all the 3 event categories.
244
+ * @param eventData
245
+ * @param options
246
+ * @returns
247
+ */
248
+ }, {
249
+ key: "prepareDiagnosticEvent",
250
+ value: function prepareDiagnosticEvent(eventData, options) {
251
+ var _this$webex$meetings$10;
252
+ var meetingId = options.meetingId;
253
+ var origin = this.getOrigin(options, meetingId);
254
+ var event = {
255
+ eventId: _uuid.default.v4(),
256
+ version: 1,
257
+ origin: origin,
258
+ originTime: {
259
+ triggered: new Date().toISOString(),
260
+ // is overridden in prepareRequest batcher
261
+ sent: 'not_defined_yet'
262
+ },
263
+ // @ts-ignore
264
+ senderCountryCode: (_this$webex$meetings$10 = this.webex.meetings.geoHintInfo) === null || _this$webex$meetings$10 === void 0 ? void 0 : _this$webex$meetings$10.countryCode,
265
+ event: eventData
266
+ };
267
+
268
+ // sanitize (remove empty properties, CA requires it)
269
+ // but we don't want to sanitize MQE as most of the times
270
+ // values will be 0, [] etc, and they are required.
271
+ if (eventData.name !== 'client.mediaquality.event') {
272
+ (0, _callDiagnosticMetrics.clearEmptyKeysRecursively)(event);
273
+ }
274
+ return event;
275
+ }
276
+
277
+ /**
278
+ * TODO: NOT IMPLEMENTED
279
+ * Submit Feature Event
280
+ * @returns
281
+ */
282
+ }, {
283
+ key: "submitFeatureEvent",
284
+ value: function submitFeatureEvent() {
285
+ throw Error('Not implemented');
286
+ }
287
+
288
+ /**
289
+ * Submit Media Quality Event
290
+ * @param args - submit params
291
+ * @param arg.name - event key
292
+ * @param arg.payload - additional payload to be merge with the default payload
293
+ * @param arg.options - options
294
+ */
295
+ }, {
296
+ key: "submitMQE",
297
+ value: function submitMQE(_ref2) {
298
+ var name = _ref2.name,
299
+ payload = _ref2.payload,
300
+ options = _ref2.options;
301
+ var meetingId = options.meetingId,
302
+ mediaConnections = options.mediaConnections;
303
+
304
+ // events that will most likely happen in join phase
305
+ if (meetingId) {
306
+ // @ts-ignore
307
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
308
+ if (!meeting) {
309
+ console.warn('Attempt to send MQE but no meeting was found...', "event: ".concat(name, ", meetingId: ").concat(meetingId));
310
+ // @ts-ignore
311
+ this.webex.internal.metrics.submitClientMetrics(_config2.CALL_DIAGNOSTIC_EVENT_FAILED_TO_SEND, {
312
+ fields: {
313
+ meetingId: meetingId,
314
+ name: name
315
+ }
316
+ });
317
+ return;
318
+ }
319
+
320
+ // merge identifiers
321
+ var identifiers = this.getIdentifiers({
322
+ meeting: meeting,
323
+ mediaConnections: meeting.mediaConnections || mediaConnections
324
+ });
325
+
326
+ // create media quality event object
327
+ var clientEventObject = {
328
+ name: name,
329
+ canProceed: true,
330
+ identifiers: identifiers,
331
+ eventData: {
332
+ webClientDomain: window.location.hostname
333
+ },
334
+ intervals: payload.intervals,
335
+ sourceMetadata: {
336
+ applicationSoftwareType: _config.CLIENT_NAME,
337
+ // @ts-ignore
338
+ applicationSoftwareVersion: this.webex.version,
339
+ mediaEngineSoftwareType: getBrowserName() || 'browser',
340
+ mediaEngineSoftwareVersion: getOSVersion() || 'unknown',
341
+ startTime: new Date().toISOString()
342
+ }
343
+ };
344
+
345
+ // merge any new properties, or override existing ones
346
+ clientEventObject = (0, _merge2.default)(clientEventObject, payload);
347
+
348
+ // append media quality event data to the call diagnostic event
349
+ var diagnosticEvent = this.prepareDiagnosticEvent(clientEventObject, options);
350
+ this.submitToCallDiagnostics(diagnosticEvent);
351
+ } else {
352
+ throw new Error('Media quality events cant be sent outside the context of a meeting. Meeting id is required.');
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Return Client Event payload by client error code
358
+ * @param arg - get error arg
359
+ * @param arg.clientErrorCode
360
+ * @param arg.serviceErrorCode
361
+ * @returns
362
+ */
363
+ }, {
364
+ key: "getErrorPayloadForClientErrorCode",
365
+ value: function getErrorPayloadForClientErrorCode(_ref3) {
366
+ var clientErrorCode = _ref3.clientErrorCode,
367
+ serviceErrorCode = _ref3.serviceErrorCode,
368
+ serviceErrorName = _ref3.serviceErrorName;
369
+ var error;
370
+ if (clientErrorCode) {
371
+ var partialParsedError = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
372
+ if (partialParsedError) {
373
+ error = (0, _merge2.default)({
374
+ fatal: true,
375
+ shownToUser: false,
376
+ name: 'other',
377
+ category: 'other'
378
+ },
379
+ // default values
380
+ {
381
+ errorCode: clientErrorCode
382
+ }, serviceErrorName ? {
383
+ errorData: {
384
+ errorName: serviceErrorName
385
+ }
386
+ } : {}, {
387
+ serviceErrorCode: serviceErrorCode
388
+ }, partialParsedError);
389
+ return error;
390
+ }
391
+ }
392
+ return undefined;
393
+ }
394
+
395
+ /**
396
+ * Generate error payload for Client Event
397
+ * @param rawError
398
+ */
399
+ }, {
400
+ key: "generateClientEventErrorPayload",
401
+ value: function generateClientEventErrorPayload(rawError) {
402
+ var _rawError$error, _rawError$error$body, _rawError$body, _rawError$body2, _rawError$body3, _rawError$body3$reaso;
403
+ if (rawError.name) {
404
+ if ((0, _callDiagnosticMetrics.isBrowserMediaErrorName)(rawError.name)) {
405
+ return this.getErrorPayloadForClientErrorCode({
406
+ serviceErrorCode: undefined,
407
+ clientErrorCode: _config2.BROWSER_MEDIA_ERROR_NAME_TO_CLIENT_ERROR_CODES_MAP[rawError.name],
408
+ serviceErrorName: rawError.name
409
+ });
410
+ }
411
+ }
412
+ var serviceErrorCode = (rawError === null || rawError === void 0 ? void 0 : (_rawError$error = rawError.error) === null || _rawError$error === void 0 ? void 0 : (_rawError$error$body = _rawError$error.body) === null || _rawError$error$body === void 0 ? void 0 : _rawError$error$body.errorCode) || (rawError === null || rawError === void 0 ? void 0 : (_rawError$body = rawError.body) === null || _rawError$body === void 0 ? void 0 : _rawError$body.errorCode) || (rawError === null || rawError === void 0 ? void 0 : (_rawError$body2 = rawError.body) === null || _rawError$body2 === void 0 ? void 0 : _rawError$body2.code) || (rawError === null || rawError === void 0 ? void 0 : (_rawError$body3 = rawError.body) === null || _rawError$body3 === void 0 ? void 0 : (_rawError$body3$reaso = _rawError$body3.reason) === null || _rawError$body3$reaso === void 0 ? void 0 : _rawError$body3$reaso.reasonCode);
413
+ if (serviceErrorCode) {
414
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
415
+ if (clientErrorCode) {
416
+ return this.getErrorPayloadForClientErrorCode({
417
+ clientErrorCode: clientErrorCode,
418
+ serviceErrorCode: serviceErrorCode
419
+ });
420
+ }
421
+
422
+ // by default, if it is locus error, return new locus err
423
+ if ((0, _callDiagnosticMetrics.isLocusServiceErrorCode)(serviceErrorCode)) {
424
+ return this.getErrorPayloadForClientErrorCode({
425
+ clientErrorCode: _config2.NEW_LOCUS_ERROR_CLIENT_CODE,
426
+ serviceErrorCode: serviceErrorCode
427
+ });
428
+ }
429
+ }
430
+ if ((0, _callDiagnosticMetrics.isMeetingInfoServiceError)(rawError)) {
431
+ return this.getErrorPayloadForClientErrorCode({
432
+ clientErrorCode: _config2.MEETING_INFO_LOOKUP_ERROR_CLIENT_CODE,
433
+ serviceErrorCode: serviceErrorCode
434
+ });
435
+ }
436
+ if ((0, _callDiagnosticMetrics.isNetworkError)(rawError)) {
437
+ var payload = this.getErrorPayloadForClientErrorCode({
438
+ clientErrorCode: _config2.NETWORK_ERROR,
439
+ serviceErrorCode: serviceErrorCode
440
+ });
441
+ payload.errorDescription = rawError.message;
442
+ return payload;
443
+ }
444
+ if ((0, _callDiagnosticMetrics.isUnauthorizedError)(rawError)) {
445
+ var _payload = this.getErrorPayloadForClientErrorCode({
446
+ clientErrorCode: _config2.AUTHENTICATION_FAILED_CODE,
447
+ serviceErrorCode: serviceErrorCode
448
+ });
449
+ _payload.errorDescription = rawError.message;
450
+ return _payload;
451
+ }
452
+
453
+ // otherwise return unkown error
454
+ return this.getErrorPayloadForClientErrorCode({
455
+ clientErrorCode: _config2.UNKNOWN_ERROR,
456
+ serviceErrorCode: _config2.UNKNOWN_ERROR
457
+ });
458
+ }
459
+
460
+ /**
461
+ * Create client event object for in meeting events
462
+ * @param arg - create args
463
+ * @param arg.event - event key
464
+ * @param arg.options - options
465
+ * @returns object
466
+ */
467
+ }, {
468
+ key: "createClientEventObjectInMeeting",
469
+ value: function createClientEventObjectInMeeting(_ref4) {
470
+ var _options$rawError;
471
+ var name = _ref4.name,
472
+ options = _ref4.options,
473
+ errors = _ref4.errors;
474
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @createClientEventObjectInMeeting. Creating in meeting event object.', "name: ".concat(name));
475
+ var meetingId = options.meetingId,
476
+ mediaConnections = options.mediaConnections;
477
+
478
+ // @ts-ignore
479
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
480
+ if (!meeting) {
481
+ console.warn('Attempt to send client event but no meeting was found...', "name: ".concat(name, ", meetingId: ").concat(meetingId));
482
+ // @ts-ignore
483
+ this.webex.internal.metrics.submitClientMetrics(_config2.CALL_DIAGNOSTIC_EVENT_FAILED_TO_SEND, {
484
+ fields: {
485
+ meetingId: meetingId,
486
+ name: name
487
+ }
488
+ });
489
+ return undefined;
490
+ }
491
+
492
+ // grab identifiers
493
+ var identifiers = this.getIdentifiers({
494
+ meeting: meeting,
495
+ mediaConnections: (meeting === null || meeting === void 0 ? void 0 : meeting.mediaConnections) || mediaConnections
496
+ });
497
+
498
+ // create client event object
499
+ var clientEventObject = {
500
+ name: name,
501
+ canProceed: true,
502
+ identifiers: identifiers,
503
+ errors: errors,
504
+ eventData: {
505
+ webClientDomain: window.location.hostname
506
+ },
507
+ userType: meeting.getCurUserType(),
508
+ loginType: this.getCurLoginType(),
509
+ isConvergedArchitectureEnabled: this.getIsConvergedArchitectureEnabled({
510
+ meetingId: meetingId
511
+ })
512
+ };
513
+ if (options !== null && options !== void 0 && (_options$rawError = options.rawError) !== null && _options$rawError !== void 0 && _options$rawError.message) {
514
+ var _options$rawError2;
515
+ // @ts-ignore
516
+ clientEventObject.eventData.rawErrorMessage = options === null || options === void 0 ? void 0 : (_options$rawError2 = options.rawError) === null || _options$rawError2 === void 0 ? void 0 : _options$rawError2.message;
517
+ }
518
+ return clientEventObject;
519
+ }
520
+
521
+ /**
522
+ * Create client event object for pre meeting events
523
+ * @param arg - create args
524
+ * @param arg.event - event key
525
+ * @param arg.options - payload
526
+ * @returns object
527
+ */
528
+ }, {
529
+ key: "createClientEventObjectPreMeeting",
530
+ value: function createClientEventObjectPreMeeting(_ref5) {
531
+ var _options$rawError3;
532
+ var name = _ref5.name,
533
+ options = _ref5.options,
534
+ errors = _ref5.errors;
535
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @createClientEventObjectPreMeeting. Creating pre meeting event object.', "name: ".concat(name));
536
+ var correlationId = options.correlationId;
537
+
538
+ // grab identifiers
539
+ var identifiers = this.getIdentifiers({
540
+ correlationId: correlationId
541
+ });
542
+
543
+ // create client event object
544
+ var clientEventObject = {
545
+ name: name,
546
+ errors: errors,
547
+ canProceed: true,
548
+ identifiers: identifiers,
549
+ eventData: {
550
+ webClientDomain: window.location.hostname
551
+ },
552
+ loginType: this.getCurLoginType()
553
+ };
554
+ if (options !== null && options !== void 0 && (_options$rawError3 = options.rawError) !== null && _options$rawError3 !== void 0 && _options$rawError3.message) {
555
+ var _options$rawError4;
556
+ // @ts-ignore
557
+ clientEventObject.eventData.rawErrorMessage = options === null || options === void 0 ? void 0 : (_options$rawError4 = options.rawError) === null || _options$rawError4 === void 0 ? void 0 : _options$rawError4.message;
558
+ }
559
+ return clientEventObject;
560
+ }
561
+
562
+ /**
563
+ * Prepare Client Event CA event.
564
+ * @param arg - submit params
565
+ * @param arg.event - event key
566
+ * @param arg.payload - additional payload to be merged with default payload
567
+ * @param arg.options - payload
568
+ * @returns {any} options to be with fetch
569
+ * @throws
570
+ */
571
+ }, {
572
+ key: "prepareClientEvent",
573
+ value: function prepareClientEvent(_ref6) {
574
+ var name = _ref6.name,
575
+ payload = _ref6.payload,
576
+ options = _ref6.options;
577
+ var meetingId = options.meetingId,
578
+ correlationId = options.correlationId,
579
+ rawError = options.rawError;
580
+ var clientEventObject;
581
+
582
+ // check if we need to generate errors
583
+ var errors = [];
584
+ if (rawError) {
585
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @prepareClientEvent. Error detected, attempting to map and attach it to the event...', "name: ".concat(name), "rawError: ".concat((0, _utils.generateCommonErrorMetadata)(rawError)));
586
+ var generatedError = this.generateClientEventErrorPayload(rawError);
587
+ if (generatedError) {
588
+ errors.push(generatedError);
589
+ }
590
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:', "generatedError: ".concat((0, _stringify.default)(generatedError)));
591
+ }
592
+
593
+ // events that will most likely happen in join phase
594
+ if (meetingId) {
595
+ clientEventObject = this.createClientEventObjectInMeeting({
596
+ name: name,
597
+ options: options,
598
+ errors: errors
599
+ });
600
+ } else if (correlationId) {
601
+ // any pre join events or events that are outside the meeting.
602
+ clientEventObject = this.createClientEventObjectPreMeeting({
603
+ name: name,
604
+ options: options,
605
+ errors: errors
606
+ });
607
+ } else {
608
+ throw new Error('Not implemented');
609
+ }
610
+
611
+ // merge any new properties, or override existing ones
612
+ clientEventObject = (0, _merge2.default)(clientEventObject, payload);
613
+
614
+ // append client event data to the call diagnostic event
615
+ var diagnosticEvent = this.prepareDiagnosticEvent(clientEventObject, options);
616
+ return diagnosticEvent;
617
+ }
618
+
619
+ /**
620
+ * Submit Client Event CA event.
621
+ * @param arg - submit params
622
+ * @param arg.event - event key
623
+ * @param arg.payload - additional payload to be merged with default payload
624
+ * @param arg.options - payload
625
+ * @throws
626
+ */
627
+ }, {
628
+ key: "submitClientEvent",
629
+ value: function submitClientEvent(_ref7) {
630
+ var name = _ref7.name,
631
+ payload = _ref7.payload,
632
+ options = _ref7.options;
633
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.', "name: ".concat(name), "payload: ".concat((0, _stringify.default)(payload)), "options: ".concat((0, _stringify.default)(options)));
634
+ var diagnosticEvent = this.prepareClientEvent({
635
+ name: name,
636
+ payload: payload,
637
+ options: options
638
+ });
639
+ if (options !== null && options !== void 0 && options.preLoginId) {
640
+ return this.submitToCallDiagnosticsPreLogin(diagnosticEvent, options === null || options === void 0 ? void 0 : options.preLoginId);
641
+ }
642
+ return this.submitToCallDiagnostics(diagnosticEvent);
643
+ }
644
+
645
+ /**
646
+ * Prepare the event and send the request to metrics-a service.
647
+ * @param event
648
+ * @returns promise
649
+ */
650
+ }, {
651
+ key: "submitToCallDiagnostics",
652
+ value: function submitToCallDiagnostics(event) {
653
+ // build metrics-a event type
654
+ var finalEvent = {
655
+ eventPayload: event,
656
+ type: ['diagnostic-event']
657
+ };
658
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @submitToCallDiagnostics. Preparing to send the request', "finalEvent: ".concat((0, _stringify.default)(finalEvent)));
659
+ return this.callDiagnosticEventsBatcher.request(finalEvent);
660
+ }
661
+
662
+ /**
663
+ * Pre login events are not batched. We make the request directly.
664
+ * @param event
665
+ * @param preLoginId
666
+ * @returns
667
+ */
668
+ }, {
669
+ key: "buildClientEventFetchRequestOptions",
670
+ value:
671
+ /**
672
+ * Builds a request options object to later be passed to fetch().
673
+ * @param arg - submit params
674
+ * @param arg.event - event key
675
+ * @param arg.payload - additional payload to be merged with default payload
676
+ * @param arg.options - client event options
677
+ * @returns {Promise<any>}
678
+ * @throws
679
+ */
680
+ function () {
681
+ var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref8) {
682
+ var name, payload, options, clientEvent, diagnosticEvent, request;
683
+ return _regenerator.default.wrap(function _callee$(_context) {
684
+ while (1) switch (_context.prev = _context.next) {
685
+ case 0:
686
+ name = _ref8.name, payload = _ref8.payload, options = _ref8.options;
687
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @buildClientEventFetchRequestOptions. Building request options object for fetch()...', "name: ".concat(name), "payload: ".concat((0, _stringify.default)(payload)), "options: ".concat((0, _stringify.default)(options)));
688
+ clientEvent = this.prepareClientEvent({
689
+ name: name,
690
+ payload: payload,
691
+ options: options
692
+ }); // build metrics-a event type
693
+ // @ts-ignore
694
+ diagnosticEvent = (0, _callDiagnosticMetrics.prepareDiagnosticMetricItem)(this.webex, {
695
+ eventPayload: clientEvent,
696
+ type: ['diagnostic-event']
697
+ });
698
+ request = {
699
+ method: 'POST',
700
+ service: 'metrics',
701
+ resource: 'clientmetrics',
702
+ body: {
703
+ metrics: [diagnosticEvent]
704
+ },
705
+ headers: {}
706
+ };
707
+ if (options.preLoginId) {
708
+ request.headers = {
709
+ authorization: false,
710
+ 'x-prelogin-userid': options.preLoginId
711
+ };
712
+ request.resource = 'clientmetrics-prelogin';
713
+ }
714
+
715
+ // @ts-ignore
716
+ return _context.abrupt("return", this.webex.prepareFetchOptions(request));
717
+ case 7:
718
+ case "end":
719
+ return _context.stop();
720
+ }
721
+ }, _callee, this);
722
+ }));
723
+ function buildClientEventFetchRequestOptions(_x) {
724
+ return _buildClientEventFetchRequestOptions.apply(this, arguments);
725
+ }
726
+ return buildClientEventFetchRequestOptions;
727
+ }()
728
+ /**
729
+ * Returns true if the specified serviceErrorCode maps to an expected error.
730
+ * @param {number} serviceErrorCode the service error code
731
+ * @returns {boolean}
732
+ */
733
+ }, {
734
+ key: "isServiceErrorExpected",
735
+ value: function isServiceErrorExpected(serviceErrorCode) {
736
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
737
+ var clientErrorPayload = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
738
+ return (clientErrorPayload === null || clientErrorPayload === void 0 ? void 0 : clientErrorPayload.category) === 'expected';
739
+ }
740
+ }]);
741
+ return CallDiagnosticMetrics;
742
+ }(_webexCore.StatelessWebexPlugin);
743
+ exports.default = CallDiagnosticMetrics;
744
+ //# sourceMappingURL=call-diagnostic-metrics.js.map