@webex/internal-plugin-metrics 3.0.0-beta.22 → 3.0.0-beta.220

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