@webex/internal-plugin-metrics 3.0.0-beta.30 → 3.0.0-beta.301

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