@webex/internal-plugin-metrics 3.9.0-webinar5k.1 → 3.10.0-next.1

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.
@@ -14,8 +14,11 @@ _Object$defineProperty(exports, "__esModule", {
14
14
  exports.default = void 0;
15
15
  var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
16
16
  var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/weak-map"));
17
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/map"));
18
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/set"));
17
19
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
18
20
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
21
+ var _from = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/from"));
19
22
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
20
23
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
21
24
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
@@ -75,6 +78,8 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
75
78
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "delayedClientFeatureEvents", []);
76
79
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "eventErrorCache", new _weakMap.default());
77
80
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isMercuryConnected", false);
81
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "eventLimitTracker", new _map.default());
82
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "eventLimitWarningsLogged", new _set.default());
78
83
  // the default validator before piping an event to the batcher
79
84
  // this function can be overridden by the user
80
85
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "validator", function (options) {
@@ -261,6 +266,9 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
261
266
  if (options !== null && options !== void 0 && options.browserLaunchMethod) {
262
267
  origin.clientInfo.browserLaunchMethod = options.browserLaunchMethod;
263
268
  }
269
+ if (options !== null && options !== void 0 && options.vendorId) {
270
+ origin.clientInfo.vendorId = options.vendorId;
271
+ }
264
272
  return origin;
265
273
  }
266
274
  throw new Error("ClientType and SubClientType can't be undefined");
@@ -613,6 +621,128 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
613
621
  this.eventErrorCache = new _weakMap.default();
614
622
  }
615
623
 
624
+ /**
625
+ * Checks if an event should be limited based on criteria defined in the event dictionary.
626
+ * Returns true if the event should be sent, false if it has reached its limit.
627
+ * @param event - The diagnostic event object
628
+ * @returns boolean indicating whether the event should be sent
629
+ */
630
+ }, {
631
+ key: "shouldSendEvent",
632
+ value: function shouldSendEvent(_ref7) {
633
+ var _event$identifiers;
634
+ var event = _ref7.event;
635
+ var eventName = event === null || event === void 0 ? void 0 : event.name;
636
+ var correlationId = event === null || event === void 0 ? void 0 : (_event$identifiers = event.identifiers) === null || _event$identifiers === void 0 ? void 0 : _event$identifiers.correlationId;
637
+ if (!correlationId || correlationId === 'unknown') {
638
+ return true;
639
+ }
640
+ var limitKeyPrefix = "".concat(eventName, ":").concat(correlationId);
641
+ switch (eventName) {
642
+ case 'client.media.render.start':
643
+ case 'client.media.render.stop':
644
+ case 'client.media.rx.start':
645
+ case 'client.media.rx.stop':
646
+ case 'client.media.tx.start':
647
+ case 'client.media.tx.stop':
648
+ {
649
+ // Send only once per mediaType-correlationId pair (or mediaType-correlationId-shareInstanceId for share/share_audio)
650
+ var mediaType = event === null || event === void 0 ? void 0 : event.mediaType;
651
+ if (mediaType) {
652
+ if (mediaType === 'share' || mediaType === 'share_audio') {
653
+ var shareInstanceId = event === null || event === void 0 ? void 0 : event.shareInstanceId;
654
+ if (shareInstanceId) {
655
+ var limitKey = "".concat(limitKeyPrefix, ":").concat(mediaType, ":").concat(shareInstanceId);
656
+ return this.checkAndIncrementEventCount(limitKey, 1, "".concat(eventName, " for ").concat(mediaType, " instance ").concat(shareInstanceId));
657
+ }
658
+ } else {
659
+ var _limitKey = "".concat(limitKeyPrefix, ":").concat(mediaType);
660
+ return this.checkAndIncrementEventCount(_limitKey, 1, "".concat(eventName, " for mediaType ").concat(mediaType));
661
+ }
662
+ }
663
+ break;
664
+ }
665
+ case 'client.roap-message.received':
666
+ case 'client.roap-message.sent':
667
+ {
668
+ var _event$roap, _event$roap2;
669
+ // Send only once per correlationId and roap.messageType/roap.type
670
+ var roapMessageType = (event === null || event === void 0 ? void 0 : (_event$roap = event.roap) === null || _event$roap === void 0 ? void 0 : _event$roap.messageType) || (event === null || event === void 0 ? void 0 : (_event$roap2 = event.roap) === null || _event$roap2 === void 0 ? void 0 : _event$roap2.type);
671
+ if (roapMessageType) {
672
+ var _limitKey2 = "".concat(limitKeyPrefix, ":").concat(roapMessageType);
673
+ return this.checkAndIncrementEventCount(_limitKey2, 1, "".concat(eventName, " for ROAP type ").concat(roapMessageType));
674
+ }
675
+ break;
676
+ }
677
+ default:
678
+ return true;
679
+ }
680
+ return true;
681
+ }
682
+
683
+ /**
684
+ * Checks the current count for a limit key and increments if under limit.
685
+ * @param limitKey - The unique key for this limit combination
686
+ * @param maxCount - Maximum allowed count
687
+ * @param eventDescription - Description for logging
688
+ * @returns true if under limit and incremented, false if at/over limit
689
+ */
690
+ }, {
691
+ key: "checkAndIncrementEventCount",
692
+ value: function checkAndIncrementEventCount(limitKey, maxCount, eventDescription) {
693
+ var currentCount = this.eventLimitTracker.get(limitKey) || 0;
694
+ if (currentCount >= maxCount) {
695
+ // Log warning only once per limit key
696
+ if (!this.eventLimitWarningsLogged.has(limitKey)) {
697
+ this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, "CallDiagnosticMetrics: Event limit reached for ".concat(eventDescription, ". ") + "Max count ".concat(maxCount, " exceeded. Event will not be sent."), "limitKey: ".concat(limitKey));
698
+ this.eventLimitWarningsLogged.add(limitKey);
699
+ }
700
+ return false;
701
+ }
702
+
703
+ // Increment count and allow event
704
+ this.eventLimitTracker.set(limitKey, currentCount + 1);
705
+ return true;
706
+ }
707
+
708
+ /**
709
+ * Clears event limit tracking
710
+ */
711
+ }, {
712
+ key: "clearEventLimits",
713
+ value: function clearEventLimits() {
714
+ this.eventLimitTracker.clear();
715
+ this.eventLimitWarningsLogged.clear();
716
+ }
717
+
718
+ /**
719
+ * Clears event limit tracking for a specific correlationId only.
720
+ * Keeps limits for other meetings intact.
721
+ */
722
+ }, {
723
+ key: "clearEventLimitsForCorrelationId",
724
+ value: function clearEventLimitsForCorrelationId(correlationId) {
725
+ if (!correlationId) {
726
+ return;
727
+ }
728
+ // Keys are formatted as "eventName:correlationId:..." across all limiters.
729
+ var hasCorrIdAtSecondToken = function hasCorrIdAtSecondToken(key) {
730
+ return key.split(':')[1] === correlationId;
731
+ };
732
+ for (var _i = 0, _Array$from = (0, _from.default)(this.eventLimitTracker.keys()); _i < _Array$from.length; _i++) {
733
+ var key = _Array$from[_i];
734
+ if (hasCorrIdAtSecondToken(key)) {
735
+ this.eventLimitTracker.delete(key);
736
+ }
737
+ }
738
+ for (var _i2 = 0, _Array$from3 = (0, _from.default)(this.eventLimitWarningsLogged.values()); _i2 < _Array$from3.length; _i2++) {
739
+ var _key2 = _Array$from3[_i2];
740
+ if (hasCorrIdAtSecondToken(_key2)) {
741
+ this.eventLimitWarningsLogged.delete(_key2);
742
+ }
743
+ }
744
+ }
745
+
616
746
  /**
617
747
  * Generate error payload for Client Event
618
748
  * @param rawError
@@ -725,12 +855,12 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
725
855
  */
726
856
  }, {
727
857
  key: "createCommonEventObjectInMeeting",
728
- value: function createCommonEventObjectInMeeting(_ref7) {
858
+ value: function createCommonEventObjectInMeeting(_ref8) {
729
859
  var _this$webex$meetings2, _this$webex$meetings3, _this$webex$meetings4, _options$joinFlowVers, _meeting$callStateFor;
730
- var name = _ref7.name,
731
- options = _ref7.options,
732
- _ref7$eventType = _ref7.eventType,
733
- eventType = _ref7$eventType === void 0 ? 'client' : _ref7$eventType;
860
+ var name = _ref8.name,
861
+ options = _ref8.options,
862
+ _ref8$eventType = _ref8.eventType,
863
+ eventType = _ref8$eventType === void 0 ? 'client' : _ref8$eventType;
734
864
  var meetingId = options.meetingId,
735
865
  mediaConnections = options.mediaConnections,
736
866
  globalMeetingId = options.globalMeetingId,
@@ -808,10 +938,10 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
808
938
  */
809
939
  }, {
810
940
  key: "createClientEventObjectInMeeting",
811
- value: function createClientEventObjectInMeeting(_ref8) {
812
- var name = _ref8.name,
813
- options = _ref8.options,
814
- errors = _ref8.errors;
941
+ value: function createClientEventObjectInMeeting(_ref9) {
942
+ var name = _ref9.name,
943
+ options = _ref9.options,
944
+ errors = _ref9.errors;
815
945
  var commonObject = this.createCommonEventObjectInMeeting({
816
946
  name: name,
817
947
  options: options,
@@ -834,9 +964,9 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
834
964
  */
835
965
  }, {
836
966
  key: "createFeatureEventObjectInMeeting",
837
- value: function createFeatureEventObjectInMeeting(_ref9) {
838
- var name = _ref9.name,
839
- options = _ref9.options;
967
+ value: function createFeatureEventObjectInMeeting(_ref10) {
968
+ var name = _ref10.name,
969
+ options = _ref10.options;
840
970
  var commonObject = this.createCommonEventObjectInMeeting({
841
971
  name: name,
842
972
  options: options,
@@ -857,11 +987,11 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
857
987
  */
858
988
  }, {
859
989
  key: "createClientEventObjectPreMeeting",
860
- value: function createClientEventObjectPreMeeting(_ref10) {
990
+ value: function createClientEventObjectPreMeeting(_ref11) {
861
991
  var _this$webex$meetings5, _this$webex$meetings6, _this$webex$meetings7;
862
- var name = _ref10.name,
863
- options = _ref10.options,
864
- errors = _ref10.errors;
992
+ var name = _ref11.name,
993
+ options = _ref11.options,
994
+ errors = _ref11.errors;
865
995
  var correlationId = options.correlationId,
866
996
  globalMeetingId = options.globalMeetingId,
867
997
  webexConferenceIdStr = options.webexConferenceIdStr,
@@ -917,10 +1047,10 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
917
1047
  */
918
1048
  }, {
919
1049
  key: "prepareClientEvent",
920
- value: function prepareClientEvent(_ref11) {
921
- var name = _ref11.name,
922
- payload = _ref11.payload,
923
- options = _ref11.options;
1050
+ value: function prepareClientEvent(_ref12) {
1051
+ var name = _ref12.name,
1052
+ payload = _ref12.payload,
1053
+ options = _ref12.options;
924
1054
  var meetingId = options.meetingId,
925
1055
  correlationId = options.correlationId,
926
1056
  rawError = options.rawError;
@@ -976,11 +1106,11 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
976
1106
  */
977
1107
  }, {
978
1108
  key: "submitClientEvent",
979
- value: function submitClientEvent(_ref12) {
980
- var name = _ref12.name,
981
- payload = _ref12.payload,
982
- options = _ref12.options,
983
- delaySubmitEvent = _ref12.delaySubmitEvent;
1109
+ value: function submitClientEvent(_ref13) {
1110
+ var name = _ref13.name,
1111
+ payload = _ref13.payload,
1112
+ options = _ref13.options,
1113
+ delaySubmitEvent = _ref13.delaySubmitEvent;
984
1114
  if (delaySubmitEvent) {
985
1115
  // Preserve the time when the event was triggered if delaying the submission to Call Diagnostics
986
1116
  var delayedOptions = _objectSpread(_objectSpread({}, options), {}, {
@@ -999,6 +1129,9 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
999
1129
  payload: payload,
1000
1130
  options: options
1001
1131
  });
1132
+ if (!this.shouldSendEvent(diagnosticEvent)) {
1133
+ return _promise.default.resolve();
1134
+ }
1002
1135
  if (options !== null && options !== void 0 && options.preLoginId) {
1003
1136
  return this.submitToCallDiagnosticsPreLogin(diagnosticEvent, options === null || options === void 0 ? void 0 : options.preLoginId);
1004
1137
  }
@@ -1089,12 +1222,12 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
1089
1222
  * @throws
1090
1223
  */
1091
1224
  function () {
1092
- var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref13) {
1225
+ var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref14) {
1093
1226
  var name, payload, options, clientEvent, diagnosticEvent, request;
1094
1227
  return _regenerator.default.wrap(function _callee$(_context) {
1095
1228
  while (1) switch (_context.prev = _context.next) {
1096
1229
  case 0:
1097
- name = _ref13.name, payload = _ref13.payload, options = _ref13.options;
1230
+ name = _ref14.name, payload = _ref14.payload, options = _ref14.options;
1098
1231
  this.logger.log(_config2.CALL_DIAGNOSTIC_LOG_IDENTIFIER, 'CallDiagnosticMetrics: @buildClientEventFetchRequestOptions. Building request options object for fetch()...', "name: ".concat(name));
1099
1232
  clientEvent = this.prepareClientEvent({
1100
1233
  name: name,
@@ -1161,7 +1294,11 @@ var CallDiagnosticMetrics = exports.default = /*#__PURE__*/function (_StatelessW
1161
1294
  key: "setDeviceInfo",
1162
1295
  value: function setDeviceInfo(device) {
1163
1296
  // This was created to fix the circular dependency between internal-plugin-device and internal-plugin-metrics
1164
- this.logger.log('CallDiagnosticMetrics: @setDeviceInfo called', device);
1297
+ this.logger.log('CallDiagnosticMetrics: @setDeviceInfo called', {
1298
+ userId: device === null || device === void 0 ? void 0 : device.userId,
1299
+ deviceId: device === null || device === void 0 ? void 0 : device.url,
1300
+ orgId: device === null || device === void 0 ? void 0 : device.orgId
1301
+ });
1165
1302
  this.device = device;
1166
1303
  }
1167
1304
  }]);