@webex/internal-plugin-metrics 3.0.0-beta.28 → 3.0.0-beta.280

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 +456 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +775 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +337 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  9. package/dist/call-diagnostic/config.js +604 -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 +194 -0
  24. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +395 -0
  25. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +96 -0
  26. package/dist/types/call-diagnostic/config.d.ts +171 -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 +103 -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 +414 -0
  39. package/src/call-diagnostic/call-diagnostic-metrics.ts +843 -0
  40. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
  41. package/src/call-diagnostic/config.ts +660 -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 +159 -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 +477 -0
  50. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1787 -0
  51. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -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,775 @@
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, _meeting$meetingInfo2, _meeting$meetingInfo4;
203
+ var meeting = options.meeting,
204
+ mediaConnections = options.mediaConnections,
205
+ correlationId = options.correlationId,
206
+ webexConferenceIdStr = options.webexConferenceIdStr,
207
+ globalMeetingId = options.globalMeetingId,
208
+ preLoginId = options.preLoginId;
209
+ var identifiers = {
210
+ correlationId: 'unknown'
211
+ };
212
+ if (meeting) {
213
+ identifiers.correlationId = meeting.correlationId;
214
+ }
215
+ if (correlationId) {
216
+ identifiers.correlationId = correlationId;
217
+ }
218
+ // @ts-ignore
219
+ if (this.webex.internal) {
220
+ // @ts-ignore
221
+ var device = this.webex.internal.device;
222
+ identifiers.userId = device.userId || preLoginId;
223
+ identifiers.deviceId = device.url;
224
+ identifiers.orgId = device.orgId;
225
+ // @ts-ignore
226
+ identifiers.locusUrl = this.webex.internal.services.get('locus');
227
+ }
228
+ if (meeting !== null && meeting !== void 0 && (_meeting$locusInfo = meeting.locusInfo) !== null && _meeting$locusInfo !== void 0 && _meeting$locusInfo.fullState) {
229
+ identifiers.locusUrl = meeting.locusUrl;
230
+ identifiers.locusId = meeting.locusUrl && meeting.locusUrl.split('/').pop();
231
+ identifiers.locusStartTime = meeting.locusInfo.fullState && meeting.locusInfo.fullState.lastActive;
232
+ }
233
+ if (meeting !== null && meeting !== void 0 && (_meeting$meetingInfo2 = meeting.meetingInfo) !== null && _meeting$meetingInfo2 !== void 0 && _meeting$meetingInfo2.confID) {
234
+ var _meeting$meetingInfo3;
235
+ identifiers.webexConferenceIdStr = (_meeting$meetingInfo3 = meeting.meetingInfo) === null || _meeting$meetingInfo3 === void 0 ? void 0 : _meeting$meetingInfo3.confID;
236
+ }
237
+ if (meeting !== null && meeting !== void 0 && (_meeting$meetingInfo4 = meeting.meetingInfo) !== null && _meeting$meetingInfo4 !== void 0 && _meeting$meetingInfo4.meetingId) {
238
+ var _meeting$meetingInfo5;
239
+ identifiers.globalMeetingId = (_meeting$meetingInfo5 = meeting.meetingInfo) === null || _meeting$meetingInfo5 === void 0 ? void 0 : _meeting$meetingInfo5.meetingId;
240
+ }
241
+ if (mediaConnections) {
242
+ var _mediaConnections$, _mediaConnections$2;
243
+ identifiers.mediaAgentAlias = mediaConnections === null || mediaConnections === void 0 ? void 0 : (_mediaConnections$ = mediaConnections[0]) === null || _mediaConnections$ === void 0 ? void 0 : _mediaConnections$.mediaAgentAlias;
244
+ identifiers.mediaAgentGroupId = mediaConnections === null || mediaConnections === void 0 ? void 0 : (_mediaConnections$2 = mediaConnections[0]) === null || _mediaConnections$2 === void 0 ? void 0 : _mediaConnections$2.mediaAgentGroupId;
245
+ }
246
+ if (!(identifiers !== null && identifiers !== void 0 && identifiers.webexConferenceIdStr) && webexConferenceIdStr) {
247
+ identifiers.webexConferenceIdStr = webexConferenceIdStr;
248
+ }
249
+ if (!(identifiers !== null && identifiers !== void 0 && identifiers.globalMeetingId) && globalMeetingId) {
250
+ identifiers.globalMeetingId = globalMeetingId;
251
+ }
252
+ if (identifiers.correlationId === undefined) {
253
+ throw new Error('Identifiers initialization failed.');
254
+ }
255
+ return identifiers;
256
+ }
257
+
258
+ /**
259
+ * Create diagnostic event, which can hold client event, feature event or MQE event data.
260
+ * This just initiates the shared properties that are required for all the 3 event categories.
261
+ * @param eventData
262
+ * @param options
263
+ * @returns
264
+ */
265
+ }, {
266
+ key: "prepareDiagnosticEvent",
267
+ value: function prepareDiagnosticEvent(eventData, options) {
268
+ var _this$webex$meetings$10;
269
+ var meetingId = options.meetingId;
270
+ var origin = this.getOrigin(options, meetingId);
271
+ var event = {
272
+ eventId: _uuid.default.v4(),
273
+ version: 1,
274
+ origin: origin,
275
+ originTime: {
276
+ triggered: new Date().toISOString(),
277
+ // is overridden in prepareRequest batcher
278
+ sent: 'not_defined_yet'
279
+ },
280
+ // @ts-ignore
281
+ senderCountryCode: (_this$webex$meetings$10 = this.webex.meetings.geoHintInfo) === null || _this$webex$meetings$10 === void 0 ? void 0 : _this$webex$meetings$10.countryCode,
282
+ event: eventData
283
+ };
284
+
285
+ // sanitize (remove empty properties, CA requires it)
286
+ // but we don't want to sanitize MQE as most of the times
287
+ // values will be 0, [] etc, and they are required.
288
+ if (eventData.name !== 'client.mediaquality.event') {
289
+ (0, _callDiagnosticMetrics.clearEmptyKeysRecursively)(event);
290
+ }
291
+ return event;
292
+ }
293
+
294
+ /**
295
+ * TODO: NOT IMPLEMENTED
296
+ * Submit Feature Event
297
+ * @returns
298
+ */
299
+ }, {
300
+ key: "submitFeatureEvent",
301
+ value: function submitFeatureEvent() {
302
+ throw Error('Not implemented');
303
+ }
304
+
305
+ /**
306
+ * Submit Media Quality Event
307
+ * @param args - submit params
308
+ * @param arg.name - event key
309
+ * @param arg.payload - additional payload to be merge with the default payload
310
+ * @param arg.options - options
311
+ */
312
+ }, {
313
+ key: "submitMQE",
314
+ value: function submitMQE(_ref2) {
315
+ var name = _ref2.name,
316
+ payload = _ref2.payload,
317
+ options = _ref2.options;
318
+ var meetingId = options.meetingId,
319
+ mediaConnections = options.mediaConnections,
320
+ webexConferenceIdStr = options.webexConferenceIdStr,
321
+ globalMeetingId = options.globalMeetingId;
322
+
323
+ // events that will most likely happen in join phase
324
+ if (meetingId) {
325
+ // @ts-ignore
326
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
327
+ if (!meeting) {
328
+ console.warn('Attempt to send MQE but no meeting was found...', "event: ".concat(name, ", meetingId: ").concat(meetingId));
329
+ // @ts-ignore
330
+ this.webex.internal.metrics.submitClientMetrics(_config2.CALL_DIAGNOSTIC_EVENT_FAILED_TO_SEND, {
331
+ fields: {
332
+ meetingId: meetingId,
333
+ name: name
334
+ }
335
+ });
336
+ return;
337
+ }
338
+
339
+ // merge identifiers
340
+ var identifiers = this.getIdentifiers({
341
+ meeting: meeting,
342
+ mediaConnections: meeting.mediaConnections || mediaConnections,
343
+ webexConferenceIdStr: webexConferenceIdStr,
344
+ globalMeetingId: globalMeetingId
345
+ });
346
+
347
+ // create media quality event object
348
+ var clientEventObject = {
349
+ name: name,
350
+ canProceed: true,
351
+ identifiers: identifiers,
352
+ eventData: {
353
+ webClientDomain: window.location.hostname
354
+ },
355
+ intervals: payload.intervals,
356
+ sourceMetadata: {
357
+ applicationSoftwareType: _config.CLIENT_NAME,
358
+ // @ts-ignore
359
+ applicationSoftwareVersion: this.webex.version,
360
+ mediaEngineSoftwareType: getBrowserName() || 'browser',
361
+ mediaEngineSoftwareVersion: getOSVersion() || 'unknown',
362
+ startTime: new Date().toISOString()
363
+ }
364
+ };
365
+
366
+ // merge any new properties, or override existing ones
367
+ clientEventObject = (0, _merge2.default)(clientEventObject, payload);
368
+
369
+ // append media quality event data to the call diagnostic event
370
+ var diagnosticEvent = this.prepareDiagnosticEvent(clientEventObject, options);
371
+ this.submitToCallDiagnostics(diagnosticEvent);
372
+ } else {
373
+ throw new Error('Media quality events cant be sent outside the context of a meeting. Meeting id is required.');
374
+ }
375
+ }
376
+
377
+ /**
378
+ * Return Client Event payload by client error code
379
+ * @param arg - get error arg
380
+ * @param arg.clientErrorCode
381
+ * @param arg.serviceErrorCode
382
+ * @returns
383
+ */
384
+ }, {
385
+ key: "getErrorPayloadForClientErrorCode",
386
+ value: function getErrorPayloadForClientErrorCode(_ref3) {
387
+ var clientErrorCode = _ref3.clientErrorCode,
388
+ serviceErrorCode = _ref3.serviceErrorCode,
389
+ serviceErrorName = _ref3.serviceErrorName;
390
+ var error;
391
+ if (clientErrorCode) {
392
+ var partialParsedError = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
393
+ if (partialParsedError) {
394
+ error = (0, _merge2.default)({
395
+ fatal: true,
396
+ shownToUser: false,
397
+ name: 'other',
398
+ category: 'other'
399
+ },
400
+ // default values
401
+ {
402
+ errorCode: clientErrorCode
403
+ }, serviceErrorName ? {
404
+ errorData: {
405
+ errorName: serviceErrorName
406
+ }
407
+ } : {}, {
408
+ serviceErrorCode: serviceErrorCode
409
+ }, partialParsedError);
410
+ return error;
411
+ }
412
+ }
413
+ return undefined;
414
+ }
415
+
416
+ /**
417
+ * Generate error payload for Client Event
418
+ * @param rawError
419
+ */
420
+ }, {
421
+ key: "generateClientEventErrorPayload",
422
+ value: function generateClientEventErrorPayload(rawError) {
423
+ var _rawError$error, _rawError$error$body, _rawError$body, _rawError$body2, _rawError$body3, _rawError$body3$reaso;
424
+ if (rawError.name) {
425
+ if ((0, _callDiagnosticMetrics.isBrowserMediaErrorName)(rawError.name)) {
426
+ return this.getErrorPayloadForClientErrorCode({
427
+ serviceErrorCode: undefined,
428
+ clientErrorCode: _config2.BROWSER_MEDIA_ERROR_NAME_TO_CLIENT_ERROR_CODES_MAP[rawError.name],
429
+ serviceErrorName: rawError.name
430
+ });
431
+ }
432
+ }
433
+ 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);
434
+ if (serviceErrorCode) {
435
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
436
+ if (clientErrorCode) {
437
+ return this.getErrorPayloadForClientErrorCode({
438
+ clientErrorCode: clientErrorCode,
439
+ serviceErrorCode: serviceErrorCode
440
+ });
441
+ }
442
+
443
+ // by default, if it is locus error, return new locus err
444
+ if ((0, _callDiagnosticMetrics.isLocusServiceErrorCode)(serviceErrorCode)) {
445
+ return this.getErrorPayloadForClientErrorCode({
446
+ clientErrorCode: _config2.NEW_LOCUS_ERROR_CLIENT_CODE,
447
+ serviceErrorCode: serviceErrorCode
448
+ });
449
+ }
450
+ }
451
+ if ((0, _callDiagnosticMetrics.isMeetingInfoServiceError)(rawError)) {
452
+ return this.getErrorPayloadForClientErrorCode({
453
+ clientErrorCode: _config2.MEETING_INFO_LOOKUP_ERROR_CLIENT_CODE,
454
+ serviceErrorCode: serviceErrorCode
455
+ });
456
+ }
457
+ if ((0, _callDiagnosticMetrics.isNetworkError)(rawError)) {
458
+ var payload = this.getErrorPayloadForClientErrorCode({
459
+ clientErrorCode: _config2.NETWORK_ERROR,
460
+ serviceErrorCode: serviceErrorCode
461
+ });
462
+ payload.errorDescription = rawError.message;
463
+ return payload;
464
+ }
465
+ if ((0, _callDiagnosticMetrics.isUnauthorizedError)(rawError)) {
466
+ var _payload = this.getErrorPayloadForClientErrorCode({
467
+ clientErrorCode: _config2.AUTHENTICATION_FAILED_CODE,
468
+ serviceErrorCode: serviceErrorCode
469
+ });
470
+ _payload.errorDescription = rawError.message;
471
+ return _payload;
472
+ }
473
+
474
+ // otherwise return unkown error
475
+ return this.getErrorPayloadForClientErrorCode({
476
+ clientErrorCode: _config2.UNKNOWN_ERROR,
477
+ serviceErrorCode: _config2.UNKNOWN_ERROR
478
+ });
479
+ }
480
+
481
+ /**
482
+ * Create client event object for in meeting events
483
+ * @param arg - create args
484
+ * @param arg.event - event key
485
+ * @param arg.options - options
486
+ * @returns object
487
+ */
488
+ }, {
489
+ key: "createClientEventObjectInMeeting",
490
+ value: function createClientEventObjectInMeeting(_ref4) {
491
+ var _options$rawError;
492
+ var name = _ref4.name,
493
+ options = _ref4.options,
494
+ errors = _ref4.errors;
495
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @createClientEventObjectInMeeting. Creating in meeting event object.', "name: ".concat(name));
496
+ var meetingId = options.meetingId,
497
+ mediaConnections = options.mediaConnections,
498
+ globalMeetingId = options.globalMeetingId,
499
+ webexConferenceIdStr = options.webexConferenceIdStr;
500
+
501
+ // @ts-ignore
502
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
503
+ if (!meeting) {
504
+ console.warn('Attempt to send client event but no meeting was found...', "name: ".concat(name, ", meetingId: ").concat(meetingId));
505
+ // @ts-ignore
506
+ this.webex.internal.metrics.submitClientMetrics(_config2.CALL_DIAGNOSTIC_EVENT_FAILED_TO_SEND, {
507
+ fields: {
508
+ meetingId: meetingId,
509
+ name: name
510
+ }
511
+ });
512
+ return undefined;
513
+ }
514
+
515
+ // grab identifiers
516
+ var identifiers = this.getIdentifiers({
517
+ meeting: meeting,
518
+ mediaConnections: (meeting === null || meeting === void 0 ? void 0 : meeting.mediaConnections) || mediaConnections,
519
+ webexConferenceIdStr: webexConferenceIdStr,
520
+ globalMeetingId: globalMeetingId
521
+ });
522
+
523
+ // create client event object
524
+ var clientEventObject = {
525
+ name: name,
526
+ canProceed: true,
527
+ identifiers: identifiers,
528
+ errors: errors,
529
+ eventData: {
530
+ webClientDomain: window.location.hostname
531
+ },
532
+ userType: meeting.getCurUserType(),
533
+ loginType: this.getCurLoginType(),
534
+ isConvergedArchitectureEnabled: this.getIsConvergedArchitectureEnabled({
535
+ meetingId: meetingId
536
+ })
537
+ };
538
+ if (options !== null && options !== void 0 && (_options$rawError = options.rawError) !== null && _options$rawError !== void 0 && _options$rawError.message) {
539
+ var _options$rawError2;
540
+ // @ts-ignore
541
+ clientEventObject.eventData.rawErrorMessage = options === null || options === void 0 ? void 0 : (_options$rawError2 = options.rawError) === null || _options$rawError2 === void 0 ? void 0 : _options$rawError2.message;
542
+ }
543
+ return clientEventObject;
544
+ }
545
+
546
+ /**
547
+ * Create client event object for pre meeting events
548
+ * @param arg - create args
549
+ * @param arg.event - event key
550
+ * @param arg.options - payload
551
+ * @returns object
552
+ */
553
+ }, {
554
+ key: "createClientEventObjectPreMeeting",
555
+ value: function createClientEventObjectPreMeeting(_ref5) {
556
+ var _options$rawError3;
557
+ var name = _ref5.name,
558
+ options = _ref5.options,
559
+ errors = _ref5.errors;
560
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @createClientEventObjectPreMeeting. Creating pre meeting event object.', "name: ".concat(name));
561
+ var correlationId = options.correlationId,
562
+ globalMeetingId = options.globalMeetingId,
563
+ webexConferenceIdStr = options.webexConferenceIdStr,
564
+ preLoginId = options.preLoginId;
565
+
566
+ // grab identifiers
567
+ var identifiers = this.getIdentifiers({
568
+ correlationId: correlationId,
569
+ preLoginId: preLoginId,
570
+ globalMeetingId: globalMeetingId,
571
+ webexConferenceIdStr: webexConferenceIdStr
572
+ });
573
+
574
+ // create client event object
575
+ var clientEventObject = {
576
+ name: name,
577
+ errors: errors,
578
+ canProceed: true,
579
+ identifiers: identifiers,
580
+ eventData: {
581
+ webClientDomain: window.location.hostname
582
+ },
583
+ loginType: this.getCurLoginType()
584
+ };
585
+ if (options !== null && options !== void 0 && (_options$rawError3 = options.rawError) !== null && _options$rawError3 !== void 0 && _options$rawError3.message) {
586
+ var _options$rawError4;
587
+ // @ts-ignore
588
+ clientEventObject.eventData.rawErrorMessage = options === null || options === void 0 ? void 0 : (_options$rawError4 = options.rawError) === null || _options$rawError4 === void 0 ? void 0 : _options$rawError4.message;
589
+ }
590
+ return clientEventObject;
591
+ }
592
+
593
+ /**
594
+ * Prepare Client Event CA event.
595
+ * @param arg - submit params
596
+ * @param arg.event - event key
597
+ * @param arg.payload - additional payload to be merged with default payload
598
+ * @param arg.options - payload
599
+ * @returns {any} options to be with fetch
600
+ * @throws
601
+ */
602
+ }, {
603
+ key: "prepareClientEvent",
604
+ value: function prepareClientEvent(_ref6) {
605
+ var name = _ref6.name,
606
+ payload = _ref6.payload,
607
+ options = _ref6.options;
608
+ var meetingId = options.meetingId,
609
+ correlationId = options.correlationId,
610
+ rawError = options.rawError;
611
+ var clientEventObject;
612
+
613
+ // check if we need to generate errors
614
+ var errors = [];
615
+ if (rawError) {
616
+ 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)));
617
+ var generatedError = this.generateClientEventErrorPayload(rawError);
618
+ if (generatedError) {
619
+ errors.push(generatedError);
620
+ }
621
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:', "generatedError: ".concat((0, _stringify.default)(generatedError)));
622
+ }
623
+
624
+ // events that will most likely happen in join phase
625
+ if (meetingId) {
626
+ clientEventObject = this.createClientEventObjectInMeeting({
627
+ name: name,
628
+ options: options,
629
+ errors: errors
630
+ });
631
+ } else if (correlationId) {
632
+ // any pre join events or events that are outside the meeting.
633
+ clientEventObject = this.createClientEventObjectPreMeeting({
634
+ name: name,
635
+ options: options,
636
+ errors: errors
637
+ });
638
+ } else {
639
+ throw new Error('Not implemented');
640
+ }
641
+
642
+ // merge any new properties, or override existing ones
643
+ clientEventObject = (0, _merge2.default)(clientEventObject, payload);
644
+
645
+ // append client event data to the call diagnostic event
646
+ var diagnosticEvent = this.prepareDiagnosticEvent(clientEventObject, options);
647
+ return diagnosticEvent;
648
+ }
649
+
650
+ /**
651
+ * Submit Client Event CA event.
652
+ * @param arg - submit params
653
+ * @param arg.event - event key
654
+ * @param arg.payload - additional payload to be merged with default payload
655
+ * @param arg.options - payload
656
+ * @throws
657
+ */
658
+ }, {
659
+ key: "submitClientEvent",
660
+ value: function submitClientEvent(_ref7) {
661
+ var name = _ref7.name,
662
+ payload = _ref7.payload,
663
+ options = _ref7.options;
664
+ 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)));
665
+ var diagnosticEvent = this.prepareClientEvent({
666
+ name: name,
667
+ payload: payload,
668
+ options: options
669
+ });
670
+ if (options !== null && options !== void 0 && options.preLoginId) {
671
+ return this.submitToCallDiagnosticsPreLogin(diagnosticEvent, options === null || options === void 0 ? void 0 : options.preLoginId);
672
+ }
673
+ return this.submitToCallDiagnostics(diagnosticEvent);
674
+ }
675
+
676
+ /**
677
+ * Prepare the event and send the request to metrics-a service.
678
+ * @param event
679
+ * @returns promise
680
+ */
681
+ }, {
682
+ key: "submitToCallDiagnostics",
683
+ value: function submitToCallDiagnostics(event) {
684
+ // build metrics-a event type
685
+ var finalEvent = {
686
+ eventPayload: event,
687
+ type: ['diagnostic-event']
688
+ };
689
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @submitToCallDiagnostics. Preparing to send the request', "finalEvent: ".concat((0, _stringify.default)(finalEvent)));
690
+ return this.callDiagnosticEventsBatcher.request(finalEvent);
691
+ }
692
+
693
+ /**
694
+ * Pre login events are not batched. We make the request directly.
695
+ * @param event
696
+ * @param preLoginId
697
+ * @returns
698
+ */
699
+ }, {
700
+ key: "buildClientEventFetchRequestOptions",
701
+ value:
702
+ /**
703
+ * Builds a request options object to later be passed to fetch().
704
+ * @param arg - submit params
705
+ * @param arg.event - event key
706
+ * @param arg.payload - additional payload to be merged with default payload
707
+ * @param arg.options - client event options
708
+ * @returns {Promise<any>}
709
+ * @throws
710
+ */
711
+ function () {
712
+ var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref8) {
713
+ var name, payload, options, clientEvent, diagnosticEvent, request;
714
+ return _regenerator.default.wrap(function _callee$(_context) {
715
+ while (1) switch (_context.prev = _context.next) {
716
+ case 0:
717
+ name = _ref8.name, payload = _ref8.payload, options = _ref8.options;
718
+ 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)));
719
+ clientEvent = this.prepareClientEvent({
720
+ name: name,
721
+ payload: payload,
722
+ options: options
723
+ }); // build metrics-a event type
724
+ // @ts-ignore
725
+ diagnosticEvent = (0, _callDiagnosticMetrics.prepareDiagnosticMetricItem)(this.webex, {
726
+ eventPayload: clientEvent,
727
+ type: ['diagnostic-event']
728
+ });
729
+ request = {
730
+ method: 'POST',
731
+ service: 'metrics',
732
+ resource: 'clientmetrics',
733
+ body: {
734
+ metrics: [diagnosticEvent]
735
+ },
736
+ headers: {}
737
+ };
738
+ if (options.preLoginId) {
739
+ request.headers = {
740
+ authorization: false,
741
+ 'x-prelogin-userid': options.preLoginId
742
+ };
743
+ request.resource = 'clientmetrics-prelogin';
744
+ }
745
+
746
+ // @ts-ignore
747
+ return _context.abrupt("return", this.webex.prepareFetchOptions(request));
748
+ case 7:
749
+ case "end":
750
+ return _context.stop();
751
+ }
752
+ }, _callee, this);
753
+ }));
754
+ function buildClientEventFetchRequestOptions(_x) {
755
+ return _buildClientEventFetchRequestOptions.apply(this, arguments);
756
+ }
757
+ return buildClientEventFetchRequestOptions;
758
+ }()
759
+ /**
760
+ * Returns true if the specified serviceErrorCode maps to an expected error.
761
+ * @param {number} serviceErrorCode the service error code
762
+ * @returns {boolean}
763
+ */
764
+ }, {
765
+ key: "isServiceErrorExpected",
766
+ value: function isServiceErrorExpected(serviceErrorCode) {
767
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
768
+ var clientErrorPayload = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
769
+ return (clientErrorPayload === null || clientErrorPayload === void 0 ? void 0 : clientErrorPayload.category) === 'expected';
770
+ }
771
+ }]);
772
+ return CallDiagnosticMetrics;
773
+ }(_webexCore.StatelessWebexPlugin);
774
+ exports.default = CallDiagnosticMetrics;
775
+ //# sourceMappingURL=call-diagnostic-metrics.js.map