@webex/internal-plugin-metrics 3.0.0-beta.31 → 3.0.0-beta.311

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