@webex/internal-plugin-metrics 2.60.0 → 2.60.1-next.2

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