@webex/internal-plugin-metrics 3.0.0-beta.24 → 3.0.0-beta.241

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