@webex/internal-plugin-metrics 3.0.0-beta.32 → 3.0.0-beta.320

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 +819 -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 +417 -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 +419 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics.ts +861 -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 +506 -0
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1973 -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,819 @@
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
+ rawErrorMessage = _ref3.rawErrorMessage,
434
+ payloadOverrides = _ref3.payloadOverrides;
435
+ var error;
436
+ if (clientErrorCode) {
437
+ var partialParsedError = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
438
+ if (partialParsedError) {
439
+ error = (0, _merge2.default)({
440
+ fatal: true,
441
+ shownToUser: false,
442
+ name: 'other',
443
+ category: 'other'
444
+ },
445
+ // default values
446
+ {
447
+ errorCode: clientErrorCode
448
+ }, serviceErrorName ? {
449
+ errorData: {
450
+ errorName: serviceErrorName
451
+ }
452
+ } : {}, {
453
+ serviceErrorCode: serviceErrorCode
454
+ }, {
455
+ rawErrorMessage: rawErrorMessage
456
+ }, partialParsedError, payloadOverrides || {});
457
+ return error;
458
+ }
459
+ }
460
+ return undefined;
461
+ }
462
+
463
+ /**
464
+ * Generate error payload for Client Event
465
+ * @param rawError
466
+ */
467
+ }, {
468
+ key: "generateClientEventErrorPayload",
469
+ value: function generateClientEventErrorPayload(rawError) {
470
+ var _rawError$error, _rawError$error$body, _rawError$body, _rawError$body2, _rawError$body3, _rawError$body3$reaso;
471
+ var rawErrorMessage = rawError.message;
472
+ if (rawError.name) {
473
+ if ((0, _callDiagnosticMetrics.isBrowserMediaErrorName)(rawError.name)) {
474
+ return this.getErrorPayloadForClientErrorCode({
475
+ serviceErrorCode: undefined,
476
+ clientErrorCode: _config2.BROWSER_MEDIA_ERROR_NAME_TO_CLIENT_ERROR_CODES_MAP[rawError.name],
477
+ serviceErrorName: rawError.name,
478
+ rawErrorMessage: rawErrorMessage
479
+ });
480
+ }
481
+ }
482
+ 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);
483
+ if (serviceErrorCode) {
484
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
485
+ if (clientErrorCode) {
486
+ return this.getErrorPayloadForClientErrorCode({
487
+ clientErrorCode: clientErrorCode,
488
+ serviceErrorCode: serviceErrorCode,
489
+ rawErrorMessage: rawErrorMessage
490
+ });
491
+ }
492
+
493
+ // by default, if it is locus error, return new locus err
494
+ if ((0, _callDiagnosticMetrics.isLocusServiceErrorCode)(serviceErrorCode)) {
495
+ return this.getErrorPayloadForClientErrorCode({
496
+ clientErrorCode: _config2.NEW_LOCUS_ERROR_CLIENT_CODE,
497
+ serviceErrorCode: serviceErrorCode,
498
+ rawErrorMessage: rawErrorMessage
499
+ });
500
+ }
501
+ }
502
+ if ((0, _callDiagnosticMetrics.isMeetingInfoServiceError)(rawError)) {
503
+ return this.getErrorPayloadForClientErrorCode({
504
+ clientErrorCode: _config2.MEETING_INFO_LOOKUP_ERROR_CLIENT_CODE,
505
+ serviceErrorCode: serviceErrorCode,
506
+ rawErrorMessage: rawErrorMessage
507
+ });
508
+ }
509
+ if ((0, _callDiagnosticMetrics.isNetworkError)(rawError)) {
510
+ return this.getErrorPayloadForClientErrorCode({
511
+ clientErrorCode: _config2.NETWORK_ERROR,
512
+ serviceErrorCode: serviceErrorCode,
513
+ payloadOverrides: rawError.payloadOverrides,
514
+ rawErrorMessage: rawErrorMessage
515
+ });
516
+ }
517
+ if ((0, _callDiagnosticMetrics.isUnauthorizedError)(rawError)) {
518
+ return this.getErrorPayloadForClientErrorCode({
519
+ clientErrorCode: _config2.AUTHENTICATION_FAILED_CODE,
520
+ serviceErrorCode: serviceErrorCode,
521
+ payloadOverrides: rawError.payloadOverrides,
522
+ rawErrorMessage: rawErrorMessage
523
+ });
524
+ }
525
+
526
+ // otherwise return unkown error
527
+ return this.getErrorPayloadForClientErrorCode({
528
+ clientErrorCode: _config2.UNKNOWN_ERROR,
529
+ serviceErrorCode: _config2.UNKNOWN_ERROR,
530
+ rawErrorMessage: rawErrorMessage
531
+ });
532
+ }
533
+
534
+ /**
535
+ * Create client event object for in meeting events
536
+ * @param arg - create args
537
+ * @param arg.event - event key
538
+ * @param arg.options - options
539
+ * @returns object
540
+ */
541
+ }, {
542
+ key: "createClientEventObjectInMeeting",
543
+ value: function createClientEventObjectInMeeting(_ref4) {
544
+ var name = _ref4.name,
545
+ options = _ref4.options,
546
+ errors = _ref4.errors;
547
+ var meetingId = options.meetingId,
548
+ mediaConnections = options.mediaConnections,
549
+ globalMeetingId = options.globalMeetingId,
550
+ webexConferenceIdStr = options.webexConferenceIdStr;
551
+
552
+ // @ts-ignore
553
+ var meeting = this.webex.meetings.meetingCollection.get(meetingId);
554
+ if (!meeting) {
555
+ console.warn('Attempt to send client event but no meeting was found...', "name: ".concat(name, ", meetingId: ").concat(meetingId));
556
+ // @ts-ignore
557
+ this.webex.internal.metrics.submitClientMetrics(_config2.CALL_DIAGNOSTIC_EVENT_FAILED_TO_SEND, {
558
+ fields: {
559
+ meetingId: meetingId,
560
+ name: name
561
+ }
562
+ });
563
+ return undefined;
564
+ }
565
+
566
+ // grab identifiers
567
+ var identifiers = this.getIdentifiers({
568
+ meeting: meeting,
569
+ mediaConnections: (meeting === null || meeting === void 0 ? void 0 : meeting.mediaConnections) || mediaConnections,
570
+ webexConferenceIdStr: webexConferenceIdStr,
571
+ globalMeetingId: globalMeetingId
572
+ });
573
+
574
+ // create client event object
575
+ var clientEventObject = {
576
+ name: name,
577
+ canProceed: true,
578
+ identifiers: identifiers,
579
+ errors: errors,
580
+ eventData: {
581
+ webClientDomain: window.location.hostname
582
+ },
583
+ userType: meeting.getCurUserType(),
584
+ loginType: this.getCurLoginType(),
585
+ isConvergedArchitectureEnabled: this.getIsConvergedArchitectureEnabled({
586
+ meetingId: meetingId
587
+ }),
588
+ webexSubServiceType: this.getSubServiceType(meeting)
589
+ };
590
+ return clientEventObject;
591
+ }
592
+
593
+ /**
594
+ * Create client event object for pre meeting events
595
+ * @param arg - create args
596
+ * @param arg.event - event key
597
+ * @param arg.options - payload
598
+ * @returns object
599
+ */
600
+ }, {
601
+ key: "createClientEventObjectPreMeeting",
602
+ value: function createClientEventObjectPreMeeting(_ref5) {
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
+ return clientEventObject;
631
+ }
632
+
633
+ /**
634
+ * Prepare Client Event CA event.
635
+ * @param arg - submit params
636
+ * @param arg.event - event key
637
+ * @param arg.payload - additional payload to be merged with default payload
638
+ * @param arg.options - payload
639
+ * @returns {any} options to be with fetch
640
+ * @throws
641
+ */
642
+ }, {
643
+ key: "prepareClientEvent",
644
+ value: function prepareClientEvent(_ref6) {
645
+ var name = _ref6.name,
646
+ payload = _ref6.payload,
647
+ options = _ref6.options;
648
+ var meetingId = options.meetingId,
649
+ correlationId = options.correlationId,
650
+ rawError = options.rawError;
651
+ var clientEventObject;
652
+
653
+ // check if we need to generate errors
654
+ var errors = [];
655
+ if (rawError) {
656
+ var generatedError = this.generateClientEventErrorPayload(rawError);
657
+ if (generatedError) {
658
+ errors.push(generatedError);
659
+ }
660
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @prepareClientEvent. Generated errors:', "generatedError: ".concat((0, _stringify.default)(generatedError)));
661
+ }
662
+
663
+ // events that will most likely happen in join phase
664
+ if (meetingId) {
665
+ clientEventObject = this.createClientEventObjectInMeeting({
666
+ name: name,
667
+ options: options,
668
+ errors: errors
669
+ });
670
+ } else if (correlationId) {
671
+ // any pre join events or events that are outside the meeting.
672
+ clientEventObject = this.createClientEventObjectPreMeeting({
673
+ name: name,
674
+ options: options,
675
+ errors: errors
676
+ });
677
+ } else {
678
+ throw new Error('Not implemented');
679
+ }
680
+
681
+ // merge any new properties, or override existing ones
682
+ clientEventObject = (0, _merge2.default)(clientEventObject, payload);
683
+
684
+ // append client event data to the call diagnostic event
685
+ var diagnosticEvent = this.prepareDiagnosticEvent(clientEventObject, options);
686
+ return diagnosticEvent;
687
+ }
688
+
689
+ /**
690
+ * Submit Client Event CA event.
691
+ * @param arg - submit params
692
+ * @param arg.event - event key
693
+ * @param arg.payload - additional payload to be merged with default payload
694
+ * @param arg.options - payload
695
+ * @throws
696
+ */
697
+ }, {
698
+ key: "submitClientEvent",
699
+ value: function submitClientEvent(_ref7) {
700
+ var name = _ref7.name,
701
+ payload = _ref7.payload,
702
+ options = _ref7.options;
703
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @submitClientEvent. Submit Client Event CA event.', "name: ".concat(name));
704
+ var diagnosticEvent = this.prepareClientEvent({
705
+ name: name,
706
+ payload: payload,
707
+ options: options
708
+ });
709
+ if (options !== null && options !== void 0 && options.preLoginId) {
710
+ return this.submitToCallDiagnosticsPreLogin(diagnosticEvent, options === null || options === void 0 ? void 0 : options.preLoginId);
711
+ }
712
+ this.validator({
713
+ type: 'ce',
714
+ event: diagnosticEvent
715
+ });
716
+ return this.submitToCallDiagnostics(diagnosticEvent);
717
+ }
718
+
719
+ /**
720
+ * Prepare the event and send the request to metrics-a service.
721
+ * @param event
722
+ * @returns promise
723
+ */
724
+ }, {
725
+ key: "submitToCallDiagnostics",
726
+ value: function submitToCallDiagnostics(event) {
727
+ // build metrics-a event type
728
+ var finalEvent = {
729
+ eventPayload: event,
730
+ type: ['diagnostic-event']
731
+ };
732
+ return this.callDiagnosticEventsBatcher.request(finalEvent);
733
+ }
734
+
735
+ /**
736
+ * Pre login events are not batched. We make the request directly.
737
+ * @param event
738
+ * @param preLoginId
739
+ * @returns
740
+ */
741
+ }, {
742
+ key: "buildClientEventFetchRequestOptions",
743
+ value:
744
+ /**
745
+ * Builds a request options object to later be passed to fetch().
746
+ * @param arg - submit params
747
+ * @param arg.event - event key
748
+ * @param arg.payload - additional payload to be merged with default payload
749
+ * @param arg.options - client event options
750
+ * @returns {Promise<any>}
751
+ * @throws
752
+ */
753
+ function () {
754
+ var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref8) {
755
+ var name, payload, options, clientEvent, diagnosticEvent, request;
756
+ return _regenerator.default.wrap(function _callee$(_context) {
757
+ while (1) switch (_context.prev = _context.next) {
758
+ case 0:
759
+ name = _ref8.name, payload = _ref8.payload, options = _ref8.options;
760
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @buildClientEventFetchRequestOptions. Building request options object for fetch()...', "name: ".concat(name));
761
+ clientEvent = this.prepareClientEvent({
762
+ name: name,
763
+ payload: payload,
764
+ options: options
765
+ }); // build metrics-a event type
766
+ // @ts-ignore
767
+ diagnosticEvent = (0, _callDiagnosticMetrics.prepareDiagnosticMetricItem)(this.webex, {
768
+ eventPayload: clientEvent,
769
+ type: ['diagnostic-event']
770
+ });
771
+ request = {
772
+ method: 'POST',
773
+ service: 'metrics',
774
+ resource: 'clientmetrics',
775
+ body: {
776
+ metrics: [diagnosticEvent]
777
+ },
778
+ headers: {},
779
+ // @ts-ignore
780
+ waitForServiceTimeout: this.webex.internal.metrics.config.waitForServiceTimeout
781
+ };
782
+ if (options.preLoginId) {
783
+ request.headers = {
784
+ authorization: false,
785
+ 'x-prelogin-userid': options.preLoginId
786
+ };
787
+ request.resource = 'clientmetrics-prelogin';
788
+ }
789
+
790
+ // @ts-ignore
791
+ return _context.abrupt("return", this.webex.prepareFetchOptions(request));
792
+ case 7:
793
+ case "end":
794
+ return _context.stop();
795
+ }
796
+ }, _callee, this);
797
+ }));
798
+ function buildClientEventFetchRequestOptions(_x) {
799
+ return _buildClientEventFetchRequestOptions.apply(this, arguments);
800
+ }
801
+ return buildClientEventFetchRequestOptions;
802
+ }()
803
+ /**
804
+ * Returns true if the specified serviceErrorCode maps to an expected error.
805
+ * @param {number} serviceErrorCode the service error code
806
+ * @returns {boolean}
807
+ */
808
+ }, {
809
+ key: "isServiceErrorExpected",
810
+ value: function isServiceErrorExpected(serviceErrorCode) {
811
+ var clientErrorCode = _config2.SERVICE_ERROR_CODES_TO_CLIENT_ERROR_CODES_MAP[serviceErrorCode];
812
+ var clientErrorPayload = _config2.CLIENT_ERROR_CODE_TO_ERROR_PAYLOAD[clientErrorCode];
813
+ return (clientErrorPayload === null || clientErrorPayload === void 0 ? void 0 : clientErrorPayload.category) === 'expected';
814
+ }
815
+ }]);
816
+ return CallDiagnosticMetrics;
817
+ }(_webexCore.StatelessWebexPlugin);
818
+ exports.default = CallDiagnosticMetrics;
819
+ //# sourceMappingURL=call-diagnostic-metrics.js.map