@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,728 @@
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
+
437
+ // otherwise return unkown error
438
+ return this.getErrorPayloadForClientErrorCode({
439
+ clientErrorCode: _config2.UNKNOWN_ERROR,
440
+ serviceErrorCode: _config2.UNKNOWN_ERROR
441
+ });
442
+ }
443
+
444
+ /**
445
+ * Create client event object for in meeting events
446
+ * @param arg - create args
447
+ * @param arg.event - event key
448
+ * @param arg.options - options
449
+ * @returns object
450
+ */
451
+ }, {
452
+ key: "createClientEventObjectInMeeting",
453
+ value: function createClientEventObjectInMeeting(_ref4) {
454
+ var _options$rawError;
455
+ var name = _ref4.name,
456
+ options = _ref4.options,
457
+ errors = _ref4.errors;
458
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @createClientEventObjectInMeeting. Creating in meeting event object.', "name: ".concat(name));
459
+ var meetingId = options.meetingId,
460
+ mediaConnections = options.mediaConnections;
461
+
462
+ // @ts-ignore
463
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
464
+ if (!meeting) {
465
+ console.warn('Attempt to send client event but no meeting was found...', "name: ".concat(name, ", meetingId: ").concat(meetingId));
466
+ // @ts-ignore
467
+ this.webex.internal.metrics.submitClientMetrics(_config2.CALL_DIAGNOSTIC_EVENT_FAILED_TO_SEND, {
468
+ fields: {
469
+ meetingId: meetingId,
470
+ name: name
471
+ }
472
+ });
473
+ return undefined;
474
+ }
475
+
476
+ // grab identifiers
477
+ var identifiers = this.getIdentifiers({
478
+ meeting: meeting,
479
+ mediaConnections: (meeting === null || meeting === void 0 ? void 0 : meeting.mediaConnections) || mediaConnections
480
+ });
481
+
482
+ // create client event object
483
+ var clientEventObject = {
484
+ name: name,
485
+ canProceed: true,
486
+ identifiers: identifiers,
487
+ errors: errors,
488
+ eventData: {
489
+ webClientDomain: window.location.hostname
490
+ },
491
+ userType: meeting.getCurUserType(),
492
+ loginType: this.getCurLoginType(),
493
+ isConvergedArchitectureEnabled: this.getIsConvergedArchitectureEnabled({
494
+ meetingId: meetingId
495
+ })
496
+ };
497
+ if (options !== null && options !== void 0 && (_options$rawError = options.rawError) !== null && _options$rawError !== void 0 && _options$rawError.message) {
498
+ var _options$rawError2;
499
+ // @ts-ignore
500
+ clientEventObject.eventData.rawErrorMessage = options === null || options === void 0 ? void 0 : (_options$rawError2 = options.rawError) === null || _options$rawError2 === void 0 ? void 0 : _options$rawError2.message;
501
+ }
502
+ return clientEventObject;
503
+ }
504
+
505
+ /**
506
+ * Create client event object for pre meeting events
507
+ * @param arg - create args
508
+ * @param arg.event - event key
509
+ * @param arg.options - payload
510
+ * @returns object
511
+ */
512
+ }, {
513
+ key: "createClientEventObjectPreMeeting",
514
+ value: function createClientEventObjectPreMeeting(_ref5) {
515
+ var _options$rawError3;
516
+ var name = _ref5.name,
517
+ options = _ref5.options,
518
+ errors = _ref5.errors;
519
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @createClientEventObjectPreMeeting. Creating pre meeting event object.', "name: ".concat(name));
520
+ var correlationId = options.correlationId;
521
+
522
+ // grab identifiers
523
+ var identifiers = this.getIdentifiers({
524
+ correlationId: correlationId
525
+ });
526
+
527
+ // create client event object
528
+ var clientEventObject = {
529
+ name: name,
530
+ errors: errors,
531
+ canProceed: true,
532
+ identifiers: identifiers,
533
+ eventData: {
534
+ webClientDomain: window.location.hostname
535
+ },
536
+ loginType: this.getCurLoginType()
537
+ };
538
+ if (options !== null && options !== void 0 && (_options$rawError3 = options.rawError) !== null && _options$rawError3 !== void 0 && _options$rawError3.message) {
539
+ var _options$rawError4;
540
+ // @ts-ignore
541
+ clientEventObject.eventData.rawErrorMessage = options === null || options === void 0 ? void 0 : (_options$rawError4 = options.rawError) === null || _options$rawError4 === void 0 ? void 0 : _options$rawError4.message;
542
+ }
543
+ return clientEventObject;
544
+ }
545
+
546
+ /**
547
+ * Prepare Client Event CA event.
548
+ * @param arg - submit params
549
+ * @param arg.event - event key
550
+ * @param arg.payload - additional payload to be merged with default payload
551
+ * @param arg.options - payload
552
+ * @returns {any} options to be with fetch
553
+ * @throws
554
+ */
555
+ }, {
556
+ key: "prepareClientEvent",
557
+ value: function prepareClientEvent(_ref6) {
558
+ var name = _ref6.name,
559
+ payload = _ref6.payload,
560
+ options = _ref6.options;
561
+ var meetingId = options.meetingId,
562
+ correlationId = options.correlationId,
563
+ rawError = options.rawError;
564
+ var clientEventObject;
565
+
566
+ // check if we need to generate errors
567
+ var errors = [];
568
+ if (rawError) {
569
+ 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)));
570
+ var generatedError = this.generateClientEventErrorPayload(rawError);
571
+ if (generatedError) {
572
+ errors.push(generatedError);
573
+ }
574
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:', "generatedError: ".concat((0, _stringify.default)(generatedError)));
575
+ }
576
+
577
+ // events that will most likely happen in join phase
578
+ if (meetingId) {
579
+ clientEventObject = this.createClientEventObjectInMeeting({
580
+ name: name,
581
+ options: options,
582
+ errors: errors
583
+ });
584
+ } else if (correlationId) {
585
+ // any pre join events or events that are outside the meeting.
586
+ clientEventObject = this.createClientEventObjectPreMeeting({
587
+ name: name,
588
+ options: options,
589
+ errors: errors
590
+ });
591
+ } else {
592
+ throw new Error('Not implemented');
593
+ }
594
+
595
+ // merge any new properties, or override existing ones
596
+ clientEventObject = (0, _merge2.default)(clientEventObject, payload);
597
+
598
+ // append client event data to the call diagnostic event
599
+ var diagnosticEvent = this.prepareDiagnosticEvent(clientEventObject, options);
600
+ return diagnosticEvent;
601
+ }
602
+
603
+ /**
604
+ * Submit Client Event CA event.
605
+ * @param arg - submit params
606
+ * @param arg.event - event key
607
+ * @param arg.payload - additional payload to be merged with default payload
608
+ * @param arg.options - payload
609
+ * @throws
610
+ */
611
+ }, {
612
+ key: "submitClientEvent",
613
+ value: function submitClientEvent(_ref7) {
614
+ var name = _ref7.name,
615
+ payload = _ref7.payload,
616
+ options = _ref7.options;
617
+ 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)));
618
+ var diagnosticEvent = this.prepareClientEvent({
619
+ name: name,
620
+ payload: payload,
621
+ options: options
622
+ });
623
+ if (options !== null && options !== void 0 && options.preLoginId) {
624
+ return this.submitToCallDiagnosticsPreLogin(diagnosticEvent, options === null || options === void 0 ? void 0 : options.preLoginId);
625
+ }
626
+ return this.submitToCallDiagnostics(diagnosticEvent);
627
+ }
628
+
629
+ /**
630
+ * Prepare the event and send the request to metrics-a service.
631
+ * @param event
632
+ * @returns promise
633
+ */
634
+ }, {
635
+ key: "submitToCallDiagnostics",
636
+ value: function submitToCallDiagnostics(event) {
637
+ // build metrics-a event type
638
+ var finalEvent = {
639
+ eventPayload: event,
640
+ type: ['diagnostic-event']
641
+ };
642
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @submitToCallDiagnostics. Preparing to send the request', "finalEvent: ".concat((0, _stringify.default)(finalEvent)));
643
+ return this.callDiagnosticEventsBatcher.request(finalEvent);
644
+ }
645
+
646
+ /**
647
+ * Pre login events are not batched. We make the request directly.
648
+ * @param event
649
+ * @param preLoginId
650
+ * @returns
651
+ */
652
+ }, {
653
+ key: "buildClientEventFetchRequestOptions",
654
+ value:
655
+ /**
656
+ * Builds a request options object to later be passed to fetch().
657
+ * @param arg - submit params
658
+ * @param arg.event - event key
659
+ * @param arg.payload - additional payload to be merged with default payload
660
+ * @param arg.options - client event options
661
+ * @returns {Promise<any>}
662
+ * @throws
663
+ */
664
+ function () {
665
+ var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref8) {
666
+ var name, payload, options, clientEvent, diagnosticEvent, request;
667
+ return _regenerator.default.wrap(function _callee$(_context) {
668
+ while (1) switch (_context.prev = _context.next) {
669
+ case 0:
670
+ name = _ref8.name, payload = _ref8.payload, options = _ref8.options;
671
+ 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)));
672
+ clientEvent = this.prepareClientEvent({
673
+ name: name,
674
+ payload: payload,
675
+ options: options
676
+ }); // build metrics-a event type
677
+ // @ts-ignore
678
+ diagnosticEvent = (0, _callDiagnosticMetrics.prepareDiagnosticMetricItem)(this.webex, {
679
+ eventPayload: clientEvent,
680
+ type: ['diagnostic-event']
681
+ });
682
+ request = {
683
+ method: 'POST',
684
+ service: 'metrics',
685
+ resource: 'clientmetrics',
686
+ body: {
687
+ metrics: [diagnosticEvent]
688
+ },
689
+ headers: {}
690
+ };
691
+ if (options.preLoginId) {
692
+ request.headers = {
693
+ authorization: false,
694
+ 'x-prelogin-userid': options.preLoginId
695
+ };
696
+ request.resource = 'clientmetrics-prelogin';
697
+ }
698
+
699
+ // @ts-ignore
700
+ return _context.abrupt("return", this.webex.prepareFetchOptions(request));
701
+ case 7:
702
+ case "end":
703
+ return _context.stop();
704
+ }
705
+ }, _callee, this);
706
+ }));
707
+ function buildClientEventFetchRequestOptions(_x) {
708
+ return _buildClientEventFetchRequestOptions.apply(this, arguments);
709
+ }
710
+ return buildClientEventFetchRequestOptions;
711
+ }()
712
+ /**
713
+ * Returns true if the specified serviceErrorCode maps to an expected error.
714
+ * @param {number} serviceErrorCode the service error code
715
+ * @returns {boolean}
716
+ */
717
+ }, {
718
+ key: "isServiceErrorExpected",
719
+ value: function isServiceErrorExpected(serviceErrorCode) {
720
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
721
+ var clientErrorPayload = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
722
+ return (clientErrorPayload === null || clientErrorPayload === void 0 ? void 0 : clientErrorPayload.category) === 'expected';
723
+ }
724
+ }]);
725
+ return CallDiagnosticMetrics;
726
+ }(_webexCore.StatelessWebexPlugin);
727
+ exports.default = CallDiagnosticMetrics;
728
+ //# sourceMappingURL=call-diagnostic-metrics.js.map