@webex/plugin-meetings 3.11.0 → 3.12.0-mobius-socket.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.
Files changed (175) hide show
  1. package/dist/aiEnableRequest/index.js +184 -0
  2. package/dist/aiEnableRequest/index.js.map +1 -0
  3. package/dist/aiEnableRequest/utils.js +36 -0
  4. package/dist/aiEnableRequest/utils.js.map +1 -0
  5. package/dist/annotation/index.js +14 -5
  6. package/dist/annotation/index.js.map +1 -1
  7. package/dist/breakouts/breakout.js +1 -1
  8. package/dist/breakouts/index.js +1 -1
  9. package/dist/config.js +7 -2
  10. package/dist/config.js.map +1 -1
  11. package/dist/constants.js +28 -6
  12. package/dist/constants.js.map +1 -1
  13. package/dist/hashTree/constants.js +3 -1
  14. package/dist/hashTree/constants.js.map +1 -1
  15. package/dist/hashTree/hashTree.js +18 -0
  16. package/dist/hashTree/hashTree.js.map +1 -1
  17. package/dist/hashTree/hashTreeParser.js +868 -419
  18. package/dist/hashTree/hashTreeParser.js.map +1 -1
  19. package/dist/hashTree/types.js +4 -2
  20. package/dist/hashTree/types.js.map +1 -1
  21. package/dist/hashTree/utils.js +10 -0
  22. package/dist/hashTree/utils.js.map +1 -1
  23. package/dist/index.js +11 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/interceptors/constant.js +12 -0
  26. package/dist/interceptors/constant.js.map +1 -0
  27. package/dist/interceptors/dataChannelAuthToken.js +290 -0
  28. package/dist/interceptors/dataChannelAuthToken.js.map +1 -0
  29. package/dist/interceptors/index.js +7 -0
  30. package/dist/interceptors/index.js.map +1 -1
  31. package/dist/interceptors/utils.js +27 -0
  32. package/dist/interceptors/utils.js.map +1 -0
  33. package/dist/interpretation/index.js +2 -2
  34. package/dist/interpretation/index.js.map +1 -1
  35. package/dist/interpretation/siLanguage.js +1 -1
  36. package/dist/locus-info/controlsUtils.js +5 -3
  37. package/dist/locus-info/controlsUtils.js.map +1 -1
  38. package/dist/locus-info/index.js +522 -131
  39. package/dist/locus-info/index.js.map +1 -1
  40. package/dist/locus-info/selfUtils.js +1 -0
  41. package/dist/locus-info/selfUtils.js.map +1 -1
  42. package/dist/locus-info/types.js.map +1 -1
  43. package/dist/media/MediaConnectionAwaiter.js +57 -1
  44. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  45. package/dist/media/properties.js +4 -2
  46. package/dist/media/properties.js.map +1 -1
  47. package/dist/meeting/in-meeting-actions.js +7 -1
  48. package/dist/meeting/in-meeting-actions.js.map +1 -1
  49. package/dist/meeting/index.js +1304 -928
  50. package/dist/meeting/index.js.map +1 -1
  51. package/dist/meeting/request.js +50 -0
  52. package/dist/meeting/request.js.map +1 -1
  53. package/dist/meeting/request.type.js.map +1 -1
  54. package/dist/meeting/util.js +133 -3
  55. package/dist/meeting/util.js.map +1 -1
  56. package/dist/meetings/index.js +117 -48
  57. package/dist/meetings/index.js.map +1 -1
  58. package/dist/member/index.js +10 -0
  59. package/dist/member/index.js.map +1 -1
  60. package/dist/member/util.js +10 -0
  61. package/dist/member/util.js.map +1 -1
  62. package/dist/metrics/constants.js +6 -1
  63. package/dist/metrics/constants.js.map +1 -1
  64. package/dist/multistream/mediaRequestManager.js +9 -60
  65. package/dist/multistream/mediaRequestManager.js.map +1 -1
  66. package/dist/multistream/remoteMediaManager.js +11 -0
  67. package/dist/multistream/remoteMediaManager.js.map +1 -1
  68. package/dist/multistream/sendSlotManager.js +116 -2
  69. package/dist/multistream/sendSlotManager.js.map +1 -1
  70. package/dist/reachability/index.js +18 -10
  71. package/dist/reachability/index.js.map +1 -1
  72. package/dist/reactions/reactions.type.js.map +1 -1
  73. package/dist/reconnection-manager/index.js +0 -1
  74. package/dist/reconnection-manager/index.js.map +1 -1
  75. package/dist/types/aiEnableRequest/index.d.ts +5 -0
  76. package/dist/types/aiEnableRequest/utils.d.ts +2 -0
  77. package/dist/types/config.d.ts +4 -0
  78. package/dist/types/constants.d.ts +23 -1
  79. package/dist/types/hashTree/constants.d.ts +1 -0
  80. package/dist/types/hashTree/hashTree.d.ts +7 -0
  81. package/dist/types/hashTree/hashTreeParser.d.ts +122 -14
  82. package/dist/types/hashTree/types.d.ts +3 -0
  83. package/dist/types/hashTree/utils.d.ts +6 -0
  84. package/dist/types/index.d.ts +1 -0
  85. package/dist/types/interceptors/constant.d.ts +5 -0
  86. package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
  87. package/dist/types/interceptors/index.d.ts +2 -1
  88. package/dist/types/interceptors/utils.d.ts +1 -0
  89. package/dist/types/locus-info/index.d.ts +60 -8
  90. package/dist/types/locus-info/types.d.ts +7 -0
  91. package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
  92. package/dist/types/media/properties.d.ts +2 -1
  93. package/dist/types/meeting/in-meeting-actions.d.ts +6 -0
  94. package/dist/types/meeting/index.d.ts +72 -7
  95. package/dist/types/meeting/request.d.ts +16 -1
  96. package/dist/types/meeting/request.type.d.ts +5 -0
  97. package/dist/types/meeting/util.d.ts +31 -0
  98. package/dist/types/meetings/index.d.ts +4 -2
  99. package/dist/types/member/index.d.ts +1 -0
  100. package/dist/types/member/util.d.ts +5 -0
  101. package/dist/types/metrics/constants.d.ts +5 -0
  102. package/dist/types/multistream/mediaRequestManager.d.ts +0 -23
  103. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  104. package/dist/types/reactions/reactions.type.d.ts +1 -0
  105. package/dist/types/webinar/utils.d.ts +6 -0
  106. package/dist/webinar/index.js +438 -163
  107. package/dist/webinar/index.js.map +1 -1
  108. package/dist/webinar/utils.js +25 -0
  109. package/dist/webinar/utils.js.map +1 -0
  110. package/package.json +24 -23
  111. package/src/aiEnableRequest/README.md +84 -0
  112. package/src/aiEnableRequest/index.ts +170 -0
  113. package/src/aiEnableRequest/utils.ts +25 -0
  114. package/src/annotation/index.ts +27 -7
  115. package/src/config.ts +4 -0
  116. package/src/constants.ts +29 -1
  117. package/src/hashTree/constants.ts +1 -0
  118. package/src/hashTree/hashTree.ts +17 -0
  119. package/src/hashTree/hashTreeParser.ts +761 -260
  120. package/src/hashTree/types.ts +4 -0
  121. package/src/hashTree/utils.ts +9 -0
  122. package/src/index.ts +8 -1
  123. package/src/interceptors/constant.ts +6 -0
  124. package/src/interceptors/dataChannelAuthToken.ts +170 -0
  125. package/src/interceptors/index.ts +2 -1
  126. package/src/interceptors/utils.ts +16 -0
  127. package/src/interpretation/index.ts +2 -2
  128. package/src/locus-info/controlsUtils.ts +11 -0
  129. package/src/locus-info/index.ts +579 -113
  130. package/src/locus-info/selfUtils.ts +1 -0
  131. package/src/locus-info/types.ts +8 -0
  132. package/src/media/MediaConnectionAwaiter.ts +41 -1
  133. package/src/media/properties.ts +3 -1
  134. package/src/meeting/in-meeting-actions.ts +12 -0
  135. package/src/meeting/index.ts +389 -87
  136. package/src/meeting/request.ts +42 -0
  137. package/src/meeting/request.type.ts +6 -0
  138. package/src/meeting/util.ts +160 -2
  139. package/src/meetings/index.ts +157 -44
  140. package/src/member/index.ts +10 -0
  141. package/src/member/util.ts +12 -0
  142. package/src/metrics/constants.ts +6 -0
  143. package/src/multistream/mediaRequestManager.ts +4 -54
  144. package/src/multistream/remoteMediaManager.ts +13 -0
  145. package/src/multistream/sendSlotManager.ts +97 -3
  146. package/src/reachability/index.ts +9 -0
  147. package/src/reactions/reactions.type.ts +1 -0
  148. package/src/reconnection-manager/index.ts +0 -1
  149. package/src/webinar/index.ts +265 -6
  150. package/src/webinar/utils.ts +16 -0
  151. package/test/unit/spec/aiEnableRequest/index.ts +981 -0
  152. package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
  153. package/test/unit/spec/annotation/index.ts +69 -7
  154. package/test/unit/spec/hashTree/hashTree.ts +66 -0
  155. package/test/unit/spec/hashTree/hashTreeParser.ts +2321 -175
  156. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +210 -0
  157. package/test/unit/spec/interceptors/utils.ts +75 -0
  158. package/test/unit/spec/locus-info/controlsUtils.js +29 -0
  159. package/test/unit/spec/locus-info/index.js +1134 -55
  160. package/test/unit/spec/media/MediaConnectionAwaiter.ts +41 -1
  161. package/test/unit/spec/media/properties.ts +12 -3
  162. package/test/unit/spec/meeting/in-meeting-actions.ts +8 -2
  163. package/test/unit/spec/meeting/index.js +884 -152
  164. package/test/unit/spec/meeting/request.js +70 -0
  165. package/test/unit/spec/meeting/utils.js +438 -26
  166. package/test/unit/spec/meetings/index.js +653 -32
  167. package/test/unit/spec/member/index.js +28 -4
  168. package/test/unit/spec/member/util.js +65 -27
  169. package/test/unit/spec/multistream/mediaRequestManager.ts +2 -85
  170. package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
  171. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  172. package/test/unit/spec/reachability/index.ts +23 -0
  173. package/test/unit/spec/reconnection-manager/index.js +4 -8
  174. package/test/unit/spec/webinar/index.ts +534 -37
  175. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -5,7 +5,7 @@ var _Array$from = require("@babel/runtime-corejs2/core-js/array/from");
5
5
  var _Symbol = require("@babel/runtime-corejs2/core-js/symbol");
6
6
  var _Symbol$iterator = require("@babel/runtime-corejs2/core-js/symbol/iterator");
7
7
  var _Array$isArray2 = require("@babel/runtime-corejs2/core-js/array/is-array");
8
- var _Object$keys3 = require("@babel/runtime-corejs2/core-js/object/keys");
8
+ var _Object$keys4 = require("@babel/runtime-corejs2/core-js/object/keys");
9
9
  var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
10
10
  var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
11
11
  var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
@@ -15,7 +15,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequ
15
15
  _Object$defineProperty(exports, "__esModule", {
16
16
  value: true
17
17
  });
18
- exports.default = exports.LocusInfoUpdateType = void 0;
18
+ exports.default = exports.MeetingEndedError = exports.LocusInfoUpdateType = void 0;
19
19
  var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
20
20
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
21
21
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
@@ -39,8 +39,9 @@ var _hashTree = _interopRequireDefault(require("./hashTree"));
39
39
  var _loggerProxy = _interopRequireDefault(require("../common/logs/logger-proxy"));
40
40
  var _constants = require("../constants");
41
41
  var _constants2 = require("./constants");
42
+ var _types = require("./types");
42
43
  var _utils = require("./utils");
43
- function ownKeys(e, r) { var t = _Object$keys3(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
44
+ function ownKeys(e, r) { var t = _Object$keys4(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
44
45
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
45
46
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof _Symbol && r[_Symbol$iterator] || r["@@iterator"]; if (!t) { if (_Array$isArray2(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
46
47
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? _Array$from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -55,7 +56,7 @@ var LocusInfoUpdateType = exports.LocusInfoUpdateType = {
55
56
  * This error is thrown if we receive information that the meeting has ended while we're processing some hash messages.
56
57
  * It's handled internally by HashTreeParser and results in MEETING_ENDED being sent up.
57
58
  */
58
- var MeetingEndedError = /*#__PURE__*/function (_Error) {
59
+ var MeetingEndedError = exports.MeetingEndedError = /*#__PURE__*/function (_Error) {
59
60
  function MeetingEndedError() {
60
61
  (0, _classCallCheck2.default)(this, MeetingEndedError);
61
62
  return _callSuper(this, MeetingEndedError, arguments);
@@ -63,6 +64,12 @@ var MeetingEndedError = /*#__PURE__*/function (_Error) {
63
64
  (0, _inherits2.default)(MeetingEndedError, _Error);
64
65
  return (0, _createClass2.default)(MeetingEndedError);
65
66
  }(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
67
+ /* Currently Locus always sends Metadata objects only in the "self" dataset.
68
+ * If this ever changes, update all the code that relies on this constant.
69
+ */
70
+ var MetadataDataSetName = _constants2.DataSetNames.SELF;
71
+ var PossibleSentinelMessageDataSetNames = [_constants2.DataSetNames.MAIN, _constants2.DataSetNames.SELF, _constants2.DataSetNames.UNJOINED];
72
+
66
73
  /**
67
74
  * Parses hash tree eventing locus data
68
75
  */
@@ -73,7 +80,7 @@ var HashTreeParser = /*#__PURE__*/function () {
73
80
  * @param {Object} options.initialLocus The initial locus data containing the hash tree information
74
81
  */
75
82
  function HashTreeParser(options) {
76
- var _locus$self;
83
+ var _locus$links, _locus$links$resource, _locus$links$resource2, _options$metadata, _options$metadata2, _options$metadata2$vi;
77
84
  (0, _classCallCheck2.default)(this, HashTreeParser);
78
85
  (0, _defineProperty2.default)(this, "dataSets", {});
79
86
  (0, _defineProperty2.default)(this, "visibleDataSetsUrl", void 0);
@@ -82,6 +89,9 @@ var HashTreeParser = /*#__PURE__*/function () {
82
89
  (0, _defineProperty2.default)(this, "locusInfoUpdateCallback", void 0);
83
90
  (0, _defineProperty2.default)(this, "visibleDataSets", void 0);
84
91
  (0, _defineProperty2.default)(this, "debugId", void 0);
92
+ (0, _defineProperty2.default)(this, "heartbeatIntervalMs", void 0);
93
+ (0, _defineProperty2.default)(this, "excludedDataSets", void 0);
94
+ (0, _defineProperty2.default)(this, "state", void 0);
85
95
  var _options$initialLocus = options.initialLocus,
86
96
  dataSets = _options$initialLocus.dataSets,
87
97
  locus = _options$initialLocus.locus; // extract dataSets from initialLocus
@@ -89,14 +99,23 @@ var HashTreeParser = /*#__PURE__*/function () {
89
99
  this.debugId = options.debugId;
90
100
  this.webexRequest = options.webexRequest;
91
101
  this.locusInfoUpdateCallback = options.locusInfoUpdateCallback;
92
- this.visibleDataSets = (locus === null || locus === void 0 ? void 0 : (_locus$self = locus.self) === null || _locus$self === void 0 ? void 0 : _locus$self.visibleDataSets) || [];
93
- if (this.visibleDataSets.length === 0) {
94
- _loggerProxy.default.logger.warn("HashTreeParser#constructor --> ".concat(this.debugId, " No visibleDataSets found in locus.self"));
102
+ this.excludedDataSets = options.excludedDataSets || [];
103
+ this.visibleDataSetsUrl = locus === null || locus === void 0 ? void 0 : (_locus$links = locus.links) === null || _locus$links === void 0 ? void 0 : (_locus$links$resource = _locus$links.resources) === null || _locus$links$resource === void 0 ? void 0 : (_locus$links$resource2 = _locus$links$resource.visibleDataSets) === null || _locus$links$resource2 === void 0 ? void 0 : _locus$links$resource2.url;
104
+ this.setVisibleDataSets(((_options$metadata = options.metadata) === null || _options$metadata === void 0 ? void 0 : _options$metadata.visibleDataSets) || [], dataSets);
105
+ this.state = 'active';
106
+ if (((_options$metadata2 = options.metadata) === null || _options$metadata2 === void 0 ? void 0 : (_options$metadata2$vi = _options$metadata2.visibleDataSets) === null || _options$metadata2$vi === void 0 ? void 0 : _options$metadata2$vi.length) === 0) {
107
+ _loggerProxy.default.logger.warn("HashTreeParser#constructor --> ".concat(this.debugId, " No visibleDataSets found in Metadata"));
95
108
  }
96
109
  // object mapping dataset names to arrays of leaf data
97
110
  var leafData = this.analyzeLocusHtMeta(locus);
98
- _loggerProxy.default.logger.info("HashTreeParser#constructor --> creating HashTreeParser for datasets: ".concat((0, _stringify.default)(dataSets.map(function (ds) {
111
+ if (options.metadata) {
112
+ // add also the metadata that's outside of locus object itself
113
+ this.analyzeMetadata(leafData, options.metadata);
114
+ }
115
+ _loggerProxy.default.logger.info("HashTreeParser#constructor --> ".concat(this.debugId, " creating HashTreeParser for datasets: ").concat((0, _stringify.default)(dataSets.map(function (ds) {
99
116
  return ds.name;
117
+ })), " with visible datasets: ").concat((0, _stringify.default)(this.visibleDataSets.map(function (vds) {
118
+ return vds.name;
100
119
  }))));
101
120
  var _iterator = _createForOfIteratorHelper(dataSets),
102
121
  _step;
@@ -106,7 +125,7 @@ var HashTreeParser = /*#__PURE__*/function () {
106
125
  var name = dataSet.name,
107
126
  leafCount = dataSet.leafCount;
108
127
  this.dataSets[name] = _objectSpread(_objectSpread({}, dataSet), {}, {
109
- hashTree: this.visibleDataSets.includes(name) ? new _hashTree.default(leafData[name] || [], leafCount) : undefined
128
+ hashTree: this.isVisibleDataSet(name) ? new _hashTree.default(leafData[name] || [], leafCount) : undefined
110
129
  });
111
130
  }
112
131
  } catch (err) {
@@ -117,30 +136,102 @@ var HashTreeParser = /*#__PURE__*/function () {
117
136
  }
118
137
 
119
138
  /**
120
- * Initializes a new visible data set by creating a hash tree for it, adding it to all the internal structures,
121
- * and sending an initial sync request to Locus with empty leaf data - that will trigger Locus to gives us all the data
122
- * from that dataset (in the response or via messages).
139
+ * Sets the visible data sets list for the HashTreeParser. This method should be called only at the start, to initialize
140
+ * the visible data sets, before any message processsing, so for example from the constructor or when resuming the parser.
123
141
  *
124
- * @param {DataSet} dataSet The new data set to be added
125
- * @returns {Promise}
142
+ * @param {Array<VisibleDataSetInfo>} visibleDataSets - The visible data sets to set
143
+ * @param {Array<DataSet>} dataSets - The "dataSets" list from Locus (yes, Locus sends visibleDataSets and dataSets as separate lists and they can differ)
144
+ * @returns {void}
126
145
  */
127
146
  return (0, _createClass2.default)(HashTreeParser, [{
147
+ key: "setVisibleDataSets",
148
+ value: function setVisibleDataSets(visibleDataSets, dataSets) {
149
+ var _this = this;
150
+ this.visibleDataSets = (0, _lodash.cloneDeep)(visibleDataSets).filter(function (vds) {
151
+ return (
152
+ // exclude data sets we will never care about
153
+ !_this.isExcludedDataSet(vds.name) &&
154
+ // and make sure that visibleDataSets list is consistent with dataSets list
155
+ dataSets.some(function (ds) {
156
+ return ds.name === vds.name;
157
+ })
158
+ );
159
+ });
160
+ }
161
+
162
+ /**
163
+ * Checks if the given data set name is in the list of visible data sets
164
+ * @param {string} dataSetName data set name to check
165
+ * @returns {Boolean} True if the data set is visible, false otherwise
166
+ */
167
+ }, {
168
+ key: "isVisibleDataSet",
169
+ value: function isVisibleDataSet(dataSetName) {
170
+ return this.visibleDataSets.some(function (vds) {
171
+ return vds.name === dataSetName;
172
+ });
173
+ }
174
+
175
+ /**
176
+ * Checks if the given data set name is in the excluded list
177
+ * @param {string} dataSetName data set name to check
178
+ * @returns {boolean} True if the data set is excluded, false otherwise
179
+ */
180
+ }, {
181
+ key: "isExcludedDataSet",
182
+ value: function isExcludedDataSet(dataSetName) {
183
+ return this.excludedDataSets.some(function (name) {
184
+ return name === dataSetName;
185
+ });
186
+ }
187
+
188
+ /**
189
+ * Adds a data set to the visible data sets list, unless it is in the excluded list.
190
+ * @param {VisibleDataSetInfo} dataSetInfo data set info to add
191
+ * @returns {boolean} True if the data set was added, false if it was excluded
192
+ */
193
+ }, {
194
+ key: "addToVisibleDataSetsList",
195
+ value: function addToVisibleDataSetsList(dataSetInfo) {
196
+ if (this.isExcludedDataSet(dataSetInfo.name)) {
197
+ _loggerProxy.default.logger.info("HashTreeParser#addToVisibleDataSetsList --> ".concat(this.debugId, " Data set \"").concat(dataSetInfo.name, "\" is in the excluded list, ignoring"));
198
+ return false;
199
+ }
200
+ this.visibleDataSets.push(dataSetInfo);
201
+ return true;
202
+ }
203
+
204
+ /**
205
+ * Initializes a new visible data set by creating a hash tree for it, adding it to all the internal structures,
206
+ * and sending an initial sync request to Locus with empty leaf data - that will trigger Locus to gives us all the data
207
+ * from that dataset (in the response or via messages).
208
+ *
209
+ * @param {VisibleDataSetInfo} visibleDataSetInfo Information about the new visible data set
210
+ * @param {DataSet} dataSetInfo The new data set to be added
211
+ * @returns {Promise}
212
+ */
213
+ }, {
128
214
  key: "initializeNewVisibleDataSet",
129
- value: function initializeNewVisibleDataSet(dataSet) {
130
- if (this.visibleDataSets.includes(dataSet.name)) {
131
- _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Data set \"").concat(dataSet.name, "\" already exists, skipping init"));
215
+ value: function initializeNewVisibleDataSet(visibleDataSetInfo, dataSetInfo) {
216
+ if (this.isVisibleDataSet(dataSetInfo.name)) {
217
+ _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Data set \"").concat(dataSetInfo.name, "\" already exists, skipping init"));
218
+ return _promise.default.resolve({
219
+ updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
220
+ updatedObjects: []
221
+ });
222
+ }
223
+ _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Adding visible data set \"").concat(dataSetInfo.name, "\""));
224
+ if (!this.addToVisibleDataSetsList(visibleDataSetInfo)) {
132
225
  return _promise.default.resolve({
133
226
  updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
134
227
  updatedObjects: []
135
228
  });
136
229
  }
137
- _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSet --> ".concat(this.debugId, " Adding visible data set \"").concat(dataSet.name, "\""));
138
- this.visibleDataSets.push(dataSet.name);
139
- var hashTree = new _hashTree.default([], dataSet.leafCount);
140
- this.dataSets[dataSet.name] = _objectSpread(_objectSpread({}, dataSet), {}, {
230
+ var hashTree = new _hashTree.default([], dataSetInfo.leafCount);
231
+ this.dataSets[dataSetInfo.name] = _objectSpread(_objectSpread({}, dataSetInfo), {}, {
141
232
  hashTree: hashTree
142
233
  });
143
- return this.sendInitializationSyncRequestToLocus(dataSet.name, 'new visible data set');
234
+ return this.sendInitializationSyncRequestToLocus(dataSetInfo.name, 'new visible data set');
144
235
  }
145
236
 
146
237
  /**
@@ -153,7 +244,7 @@ var HashTreeParser = /*#__PURE__*/function () {
153
244
  }, {
154
245
  key: "sendInitializationSyncRequestToLocus",
155
246
  value: function sendInitializationSyncRequestToLocus(datasetName, debugText) {
156
- var _this = this;
247
+ var _this2 = this;
157
248
  var dataset = this.dataSets[datasetName];
158
249
  if (!dataset) {
159
250
  _loggerProxy.default.logger.warn("HashTreeParser#sendInitializationSyncRequestToLocus --> ".concat(this.debugId, " No data set found for ").concat(datasetName, ", cannot send the request for leaf data"));
@@ -163,7 +254,10 @@ var HashTreeParser = /*#__PURE__*/function () {
163
254
  _loggerProxy.default.logger.info("HashTreeParser#sendInitializationSyncRequestToLocus --> ".concat(this.debugId, " Sending initial sync request to Locus for data set \"").concat(datasetName, "\" with empty leaf data"));
164
255
  return this.sendSyncRequestToLocus(this.dataSets[datasetName], emptyLeavesData).then(function (syncResponse) {
165
256
  if (syncResponse) {
166
- return _this.parseMessage(syncResponse, "via empty leaves /sync API call for ".concat(debugText));
257
+ return {
258
+ updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
259
+ updatedObjects: _this2.parseMessage(syncResponse, "via empty leaves /sync API call for ".concat(debugText))
260
+ };
167
261
  }
168
262
  return {
169
263
  updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
@@ -173,19 +267,26 @@ var HashTreeParser = /*#__PURE__*/function () {
173
267
  }
174
268
 
175
269
  /**
176
- * Queries Locus for information about all the data sets
270
+ * Queries Locus for all up-to-date information about all visible data sets
177
271
  *
178
- * @param {string} url - url from which we can get info about all data sets
179
272
  * @returns {Promise}
180
273
  */
181
274
  }, {
182
- key: "getAllDataSetsMetadata",
183
- value: function getAllDataSetsMetadata(url) {
275
+ key: "getAllVisibleDataSetsFromLocus",
276
+ value: function getAllVisibleDataSetsFromLocus() {
277
+ var _this3 = this;
278
+ if (!this.visibleDataSetsUrl) {
279
+ _loggerProxy.default.logger.warn("HashTreeParser#getAllVisibleDataSetsFromLocus --> ".concat(this.debugId, " No visibleDataSetsUrl, cannot get data sets information"));
280
+ return _promise.default.resolve([]);
281
+ }
184
282
  return this.webexRequest({
185
283
  method: _constants.HTTP_VERBS.GET,
186
- uri: url
284
+ uri: this.visibleDataSetsUrl
187
285
  }).then(function (response) {
188
286
  return response.body.dataSets;
287
+ }).catch(function (error) {
288
+ _this3.checkForSentinelHttpResponse(error);
289
+ throw error;
189
290
  });
190
291
  }
191
292
 
@@ -199,17 +300,18 @@ var HashTreeParser = /*#__PURE__*/function () {
199
300
  key: "initializeFromMessage",
200
301
  value: (function () {
201
302
  var _initializeFromMessage = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(message) {
202
- var dataSets;
303
+ var visibleDataSets;
203
304
  return _regenerator.default.wrap(function (_context) {
204
305
  while (1) switch (_context.prev = _context.next) {
205
306
  case 0:
206
- _loggerProxy.default.logger.info("HashTreeParser#initializeFromMessage --> ".concat(this.debugId, " visibleDataSetsUrl=").concat(message.visibleDataSetsUrl));
307
+ this.visibleDataSetsUrl = message.visibleDataSetsUrl;
308
+ _loggerProxy.default.logger.info("HashTreeParser#initializeFromMessage --> ".concat(this.debugId, " visibleDataSetsUrl=").concat(this.visibleDataSetsUrl));
207
309
  _context.next = 1;
208
- return this.getAllDataSetsMetadata(message.visibleDataSetsUrl);
310
+ return this.getAllVisibleDataSetsFromLocus();
209
311
  case 1:
210
- dataSets = _context.sent;
312
+ visibleDataSets = _context.sent;
211
313
  _context.next = 2;
212
- return this.initializeDataSets(dataSets, 'initialization from message');
314
+ return this.initializeDataSets(visibleDataSets, 'initialization from message');
213
315
  case 2:
214
316
  case "end":
215
317
  return _context.stop();
@@ -235,25 +337,26 @@ var HashTreeParser = /*#__PURE__*/function () {
235
337
  key: "initializeFromGetLociResponse",
236
338
  value: (function () {
237
339
  var _initializeFromGetLociResponse = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(locus) {
238
- var _locus$links, _locus$links$resource, _locus$links$resource2;
239
- var dataSets;
340
+ var _locus$links2, _locus$links2$resourc, _locus$links2$resourc2;
341
+ var visibleDataSets;
240
342
  return _regenerator.default.wrap(function (_context2) {
241
343
  while (1) switch (_context2.prev = _context2.next) {
242
344
  case 0:
243
- if (locus !== null && locus !== void 0 && (_locus$links = locus.links) !== null && _locus$links !== void 0 && (_locus$links$resource = _locus$links.resources) !== null && _locus$links$resource !== void 0 && (_locus$links$resource2 = _locus$links$resource.visibleDataSets) !== null && _locus$links$resource2 !== void 0 && _locus$links$resource2.url) {
345
+ if (locus !== null && locus !== void 0 && (_locus$links2 = locus.links) !== null && _locus$links2 !== void 0 && (_locus$links2$resourc = _locus$links2.resources) !== null && _locus$links2$resourc !== void 0 && (_locus$links2$resourc2 = _locus$links2$resourc.visibleDataSets) !== null && _locus$links2$resourc2 !== void 0 && _locus$links2$resourc2.url) {
244
346
  _context2.next = 1;
245
347
  break;
246
348
  }
247
349
  _loggerProxy.default.logger.warn("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " missing visibleDataSets url in GET Loci response, cannot initialize hash trees"));
248
350
  return _context2.abrupt("return");
249
351
  case 1:
250
- _loggerProxy.default.logger.info("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " visibleDataSets url: ").concat(locus.links.resources.visibleDataSets.url));
352
+ this.visibleDataSetsUrl = locus.links.resources.visibleDataSets.url;
353
+ _loggerProxy.default.logger.info("HashTreeParser#initializeFromGetLociResponse --> ".concat(this.debugId, " visibleDataSets url: ").concat(this.visibleDataSetsUrl));
251
354
  _context2.next = 2;
252
- return this.getAllDataSetsMetadata(locus.links.resources.visibleDataSets.url);
355
+ return this.getAllVisibleDataSetsFromLocus();
253
356
  case 2:
254
- dataSets = _context2.sent;
357
+ visibleDataSets = _context2.sent;
255
358
  _context2.next = 3;
256
- return this.initializeDataSets(dataSets, 'initialization from GET /loci response');
359
+ return this.initializeDataSets(visibleDataSets, 'initialization from GET /loci response');
257
360
  case 3:
258
361
  case "end":
259
362
  return _context2.stop();
@@ -268,7 +371,7 @@ var HashTreeParser = /*#__PURE__*/function () {
268
371
  /**
269
372
  * Initializes data sets by doing an initialization sync on each visible data set that doesn't have a hash tree yet.
270
373
  *
271
- * @param {DataSet[]} dataSets Array of DataSet objects to initialize
374
+ * @param {DataSet[]} visibleDataSets Array of visible DataSet objects to initialize
272
375
  * @param {string} debugText Text to include in logs for debugging purposes
273
376
  * @returns {Promise}
274
377
  */
@@ -276,76 +379,86 @@ var HashTreeParser = /*#__PURE__*/function () {
276
379
  }, {
277
380
  key: "initializeDataSets",
278
381
  value: (function () {
279
- var _initializeDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(dataSets, debugText) {
280
- var updatedObjects, _iterator2, _step2, dataSet, name, leafCount, _data, _t;
382
+ var _initializeDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(visibleDataSets, debugText) {
383
+ var updatedObjects, _iterator2, _step2, dataSet, name, leafCount, url, _data, _t;
281
384
  return _regenerator.default.wrap(function (_context3) {
282
385
  while (1) switch (_context3.prev = _context3.next) {
283
386
  case 0:
387
+ if (!(this.state === 'stopped')) {
388
+ _context3.next = 1;
389
+ break;
390
+ }
391
+ return _context3.abrupt("return");
392
+ case 1:
284
393
  updatedObjects = [];
285
- _iterator2 = _createForOfIteratorHelper(dataSets);
286
- _context3.prev = 1;
394
+ _iterator2 = _createForOfIteratorHelper(visibleDataSets);
395
+ _context3.prev = 2;
287
396
  _iterator2.s();
288
- case 2:
397
+ case 3:
289
398
  if ((_step2 = _iterator2.n()).done) {
290
- _context3.next = 6;
399
+ _context3.next = 7;
291
400
  break;
292
401
  }
293
402
  dataSet = _step2.value;
294
- name = dataSet.name, leafCount = dataSet.leafCount;
403
+ name = dataSet.name, leafCount = dataSet.leafCount, url = dataSet.url;
295
404
  if (!this.dataSets[name]) {
296
405
  _loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " initializing dataset \"").concat(name, "\" (").concat(debugText, ")"));
297
406
  this.dataSets[name] = _objectSpread({}, dataSet);
298
407
  } else {
299
408
  _loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " dataset \"").concat(name, "\" already exists (").concat(debugText, ")"));
300
409
  }
301
- if (!(this.visibleDataSets.includes(name) && !this.dataSets[name].hashTree)) {
302
- _context3.next = 5;
410
+ if (this.isVisibleDataSet(name)) {
411
+ _context3.next = 4;
412
+ break;
413
+ }
414
+ if (this.addToVisibleDataSetsList({
415
+ name: name,
416
+ url: url
417
+ })) {
418
+ _context3.next = 4;
419
+ break;
420
+ }
421
+ return _context3.abrupt("continue", 6);
422
+ case 4:
423
+ if (this.dataSets[name].hashTree) {
424
+ _context3.next = 6;
303
425
  break;
304
426
  }
305
427
  _loggerProxy.default.logger.info("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " creating hash tree for visible dataset \"").concat(name, "\" (").concat(debugText, ")"));
306
428
  this.dataSets[name].hashTree = new _hashTree.default([], leafCount);
307
429
 
308
430
  // eslint-disable-next-line no-await-in-loop
309
- _context3.next = 3;
431
+ _context3.next = 5;
310
432
  return this.sendInitializationSyncRequestToLocus(name, debugText);
311
- case 3:
433
+ case 5:
312
434
  _data = _context3.sent;
313
- if (!(_data.updateType === LocusInfoUpdateType.MEETING_ENDED)) {
314
- _context3.next = 4;
315
- break;
316
- }
317
- _loggerProxy.default.logger.warn("HashTreeParser#initializeDataSets --> ".concat(this.debugId, " meeting ended while initializing new visible data set \"").concat(name, "\""));
318
-
319
- // throw an error, it will be caught higher up and the meeting will be destroyed
320
- throw new MeetingEndedError();
321
- case 4:
322
435
  if (_data.updateType === LocusInfoUpdateType.OBJECTS_UPDATED) {
323
436
  updatedObjects.push.apply(updatedObjects, (0, _toConsumableArray2.default)(_data.updatedObjects || []));
324
437
  }
325
- case 5:
326
- _context3.next = 2;
327
- break;
328
438
  case 6:
329
- _context3.next = 8;
439
+ _context3.next = 3;
330
440
  break;
331
441
  case 7:
332
- _context3.prev = 7;
333
- _t = _context3["catch"](1);
334
- _iterator2.e(_t);
442
+ _context3.next = 9;
443
+ break;
335
444
  case 8:
336
445
  _context3.prev = 8;
337
- _iterator2.f();
338
- return _context3.finish(8);
446
+ _t = _context3["catch"](2);
447
+ _iterator2.e(_t);
339
448
  case 9:
449
+ _context3.prev = 9;
450
+ _iterator2.f();
451
+ return _context3.finish(9);
452
+ case 10:
340
453
  this.callLocusInfoUpdateCallback({
341
454
  updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
342
455
  updatedObjects: updatedObjects
343
456
  });
344
- case 10:
457
+ case 11:
345
458
  case "end":
346
459
  return _context3.stop();
347
460
  }
348
- }, _callee3, this, [[1, 7, 8, 9]]);
461
+ }, _callee3, this, [[2, 8, 9, 10]]);
349
462
  }));
350
463
  function initializeDataSets(_x3, _x4) {
351
464
  return _initializeDataSets.apply(this, arguments);
@@ -371,7 +484,7 @@ var HashTreeParser = /*#__PURE__*/function () {
371
484
  copyData = _ref$copyData === void 0 ? false : _ref$copyData;
372
485
  // object mapping dataset names to arrays of leaf data
373
486
  var leafInfo = {};
374
- var _findAndStoreMetaData = function findAndStoreMetaData(currentLocusPart) {
487
+ var _findAndStoreMetaData = function findAndStoreMetaData(currentLocusPart, currentLocusPartName) {
375
488
  if ((0, _typeof2.default)(currentLocusPart) !== 'object' || currentLocusPart === null) {
376
489
  return;
377
490
  }
@@ -387,10 +500,16 @@ var HashTreeParser = /*#__PURE__*/function () {
387
500
  version: version
388
501
  };
389
502
  if (copyData) {
390
- newLeafInfo.data = (0, _lodash.cloneDeep)(currentLocusPart);
503
+ if (type.toLowerCase() === _types.ObjectType.control) {
504
+ // control entries require special handling, because they are signalled by Locus
505
+ // differently when coming in messages vs API responses
506
+ newLeafInfo.data = (0, _defineProperty2.default)({}, currentLocusPartName, (0, _lodash.cloneDeep)(currentLocusPart));
507
+ } else {
508
+ newLeafInfo.data = (0, _lodash.cloneDeep)(currentLocusPart);
391
509
 
392
- // remove any nested other objects that have their own htMeta
393
- (0, _utils.deleteNestedObjectsWithHtMeta)(newLeafInfo.data);
510
+ // remove any nested other objects that have their own htMeta
511
+ (0, _utils.deleteNestedObjectsWithHtMeta)(newLeafInfo.data);
512
+ }
394
513
  }
395
514
  var _iterator3 = _createForOfIteratorHelper(dataSetNames),
396
515
  _step3;
@@ -409,12 +528,14 @@ var HashTreeParser = /*#__PURE__*/function () {
409
528
  }
410
529
  }
411
530
  if ((0, _isArray.default)(currentLocusPart)) {
412
- var _iterator4 = _createForOfIteratorHelper(currentLocusPart),
531
+ var _iterator4 = _createForOfIteratorHelper(currentLocusPart.entries()),
413
532
  _step4;
414
533
  try {
415
534
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
416
- var item = _step4.value;
417
- _findAndStoreMetaData(item);
535
+ var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
536
+ index = _step4$value[0],
537
+ item = _step4$value[1];
538
+ _findAndStoreMetaData(item, index.toString());
418
539
  }
419
540
  } catch (err) {
420
541
  _iterator4.e(err);
@@ -425,15 +546,47 @@ var HashTreeParser = /*#__PURE__*/function () {
425
546
  for (var _i = 0, _Object$keys = (0, _keys.default)(currentLocusPart); _i < _Object$keys.length; _i++) {
426
547
  var key = _Object$keys[_i];
427
548
  if (Object.prototype.hasOwnProperty.call(currentLocusPart, key)) {
428
- _findAndStoreMetaData(currentLocusPart[key]);
549
+ _findAndStoreMetaData(currentLocusPart[key], key);
429
550
  }
430
551
  }
431
552
  }
432
553
  };
433
- _findAndStoreMetaData(locus);
554
+ _findAndStoreMetaData(locus, 'locus');
434
555
  return leafInfo;
435
556
  }
436
557
 
558
+ /**
559
+ * Analyzes the Metadata object that is sent outside of Locus object, and appends its data to passed in leafInfo
560
+ * structure.
561
+ *
562
+ * @param {Record<string, LeafInfo[]>} leafInfo the structure to which the Metadata info will be appended
563
+ * @param {Metadata} metadata Metadata object
564
+ * @returns {void}
565
+ */
566
+ }, {
567
+ key: "analyzeMetadata",
568
+ value: function analyzeMetadata(leafInfo, metadata) {
569
+ var _htMeta$dataSetNames;
570
+ var htMeta = metadata.htMeta;
571
+ if ((htMeta === null || htMeta === void 0 ? void 0 : (_htMeta$dataSetNames = htMeta.dataSetNames) === null || _htMeta$dataSetNames === void 0 ? void 0 : _htMeta$dataSetNames.length) === 1 && htMeta.dataSetNames[0].toLowerCase() === MetadataDataSetName) {
572
+ var _metadata$htMeta$elem = metadata.htMeta.elementId,
573
+ type = _metadata$htMeta$elem.type,
574
+ id = _metadata$htMeta$elem.id,
575
+ version = _metadata$htMeta$elem.version;
576
+ var dataSetName = htMeta.dataSetNames[0];
577
+ if (!leafInfo[dataSetName]) {
578
+ leafInfo[dataSetName] = [];
579
+ }
580
+ leafInfo[dataSetName].push({
581
+ type: type,
582
+ id: id,
583
+ version: version
584
+ });
585
+ } else {
586
+ throw new Error("".concat(this.debugId, " Metadata htMeta has unexpected dataSetNames: ").concat(htMeta && htMeta.dataSetNames.join(',')));
587
+ }
588
+ }
589
+
437
590
  /**
438
591
  * Checks if the provided hash tree message indicates the end of the meeting and that there won't be any more updates.
439
592
  *
@@ -443,14 +596,14 @@ var HashTreeParser = /*#__PURE__*/function () {
443
596
  }, {
444
597
  key: "isEndMessage",
445
598
  value: function isEndMessage(message) {
446
- var mainDataSet = message.dataSets.find(function (dataSet) {
447
- return dataSet.name.toLowerCase() === _constants2.DataSetNames.MAIN;
599
+ var _this4 = this;
600
+ return message.dataSets.some(function (dataSet) {
601
+ if (dataSet.leafCount === 1 && dataSet.root === _constants2.EMPTY_HASH && (!_this4.dataSets[dataSet.name] || _this4.dataSets[dataSet.name].version < dataSet.version) && PossibleSentinelMessageDataSetNames.includes(dataSet.name.toLowerCase())) {
602
+ // this is a special way for Locus to indicate that this meeting has ended
603
+ return true;
604
+ }
605
+ return false;
448
606
  });
449
- if (mainDataSet && mainDataSet.leafCount === 1 && mainDataSet.root === _constants2.EMPTY_HASH && this.dataSets[_constants2.DataSetNames.MAIN].version < mainDataSet.version) {
450
- // this is a special way for Locus to indicate that this meeting has ended
451
- return true;
452
- }
453
- return false;
454
607
  }
455
608
 
456
609
  /**
@@ -462,7 +615,7 @@ var HashTreeParser = /*#__PURE__*/function () {
462
615
  }, {
463
616
  key: "handleRootHashHeartBeatMessage",
464
617
  value: function handleRootHashHeartBeatMessage(message) {
465
- var _this2 = this;
618
+ var _this5 = this;
466
619
  var dataSets = message.dataSets;
467
620
  _loggerProxy.default.logger.info("HashTreeParser#handleRootHashMessage --> ".concat(this.debugId, " Received heartbeat root hash message with data sets: ").concat((0, _stringify.default)(dataSets.map(function (_ref2) {
468
621
  var name = _ref2.name,
@@ -477,11 +630,81 @@ var HashTreeParser = /*#__PURE__*/function () {
477
630
  };
478
631
  }))));
479
632
  dataSets.forEach(function (dataSet) {
480
- _this2.updateDataSetInfo(dataSet);
481
- _this2.runSyncAlgorithm(dataSet);
633
+ _this5.updateDataSetInfo(dataSet);
634
+ _this5.runSyncAlgorithm(dataSet);
482
635
  });
483
636
  }
484
637
 
638
+ /**
639
+ * Asynchronously initializes new visible data sets
640
+ *
641
+ * @param {VisibleDataSetInfo[]} dataSetsRequiringInitialization list of datasets to initialize
642
+ * @returns {void}
643
+ */
644
+ }, {
645
+ key: "queueInitForNewVisibleDataSets",
646
+ value: function queueInitForNewVisibleDataSets(dataSetsRequiringInitialization) {
647
+ var _this6 = this;
648
+ _loggerProxy.default.logger.info("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(this.debugId, " queuing initialization of new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
649
+ return ds.name;
650
+ }).join(', ')));
651
+ queueMicrotask(function () {
652
+ _this6.initializeNewVisibleDataSets(dataSetsRequiringInitialization).catch(function (error) {
653
+ if (error instanceof MeetingEndedError) {
654
+ _this6.callLocusInfoUpdateCallback({
655
+ updateType: LocusInfoUpdateType.MEETING_ENDED
656
+ });
657
+ } else {
658
+ _loggerProxy.default.logger.warn("HashTreeParser#queueInitForNewVisibleDataSets --> ".concat(_this6.debugId, " error while initializing new visible datasets: ").concat(dataSetsRequiringInitialization.map(function (ds) {
659
+ return ds.name;
660
+ }).join(', '), ": "), error);
661
+ }
662
+ });
663
+ });
664
+ }
665
+
666
+ /**
667
+ * Handles updates to Metadata object that we receive from Locus via other means than messages. Right now
668
+ * that means only in the API response alongside locus object.
669
+ *
670
+ * @param {Metadata} metadata received in Locus update other than a message (for example in an API response)
671
+ * @param {HashTreeObject[]} updatedObjects a list of updated hash tree objects to which any updates resulting from new Metadata will be added
672
+ * @returns {void}
673
+ */
674
+ }, {
675
+ key: "handleMetadataUpdate",
676
+ value: function handleMetadataUpdate(metadata, updatedObjects) {
677
+ var _this$dataSets$Metada;
678
+ var dataSetsRequiringInitialization = [];
679
+
680
+ // current assumption based on Locus docs is that Metadata object lives always in "self" data set
681
+ var hashTree = (_this$dataSets$Metada = this.dataSets[MetadataDataSetName]) === null || _this$dataSets$Metada === void 0 ? void 0 : _this$dataSets$Metada.hashTree;
682
+ if (!hashTree) {
683
+ _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received Metadata object but no hash tree for \"").concat(MetadataDataSetName, "\" data set exists"));
684
+ } else {
685
+ var metadataUpdated = hashTree.putItem(metadata.htMeta.elementId);
686
+ if (metadataUpdated) {
687
+ // metadata in Locus API response is in a slightly different format than the objects in messages, so need to adapt it
688
+ var metadataObject = {
689
+ htMeta: metadata.htMeta,
690
+ data: metadata
691
+ };
692
+ updatedObjects.push(metadataObject);
693
+ var _this$checkForVisible = this.checkForVisibleDataSetChanges([metadataObject]),
694
+ changeDetected = _this$checkForVisible.changeDetected,
695
+ removedDataSets = _this$checkForVisible.removedDataSets,
696
+ addedDataSets = _this$checkForVisible.addedDataSets;
697
+ if (changeDetected) {
698
+ dataSetsRequiringInitialization = this.processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects);
699
+ }
700
+ if (dataSetsRequiringInitialization.length > 0) {
701
+ // there are some data sets that we need to initialize asynchronously
702
+ this.queueInitForNewVisibleDataSets(dataSetsRequiringInitialization);
703
+ }
704
+ }
705
+ }
706
+ }
707
+
485
708
  /**
486
709
  * This method should be called when we receive a partial locus DTO that contains dataSets and htMeta information
487
710
  * It updates the hash trees with the new leaf data based on the received Locus
@@ -492,23 +715,28 @@ var HashTreeParser = /*#__PURE__*/function () {
492
715
  }, {
493
716
  key: "handleLocusUpdate",
494
717
  value: function handleLocusUpdate(update) {
495
- var _this3 = this;
718
+ var _this7 = this;
719
+ if (this.state === 'stopped') {
720
+ return;
721
+ }
496
722
  var dataSets = update.dataSets,
497
- locus = update.locus;
723
+ locus = update.locus,
724
+ metadata = update.metadata;
498
725
  if (!dataSets) {
499
- _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received hash tree update without dataSets"));
500
- }
501
- var _iterator5 = _createForOfIteratorHelper(dataSets),
502
- _step5;
503
- try {
504
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
505
- var dataSet = _step5.value;
506
- this.updateDataSetInfo(dataSet);
726
+ _loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(this.debugId, " received hash tree update without dataSets"));
727
+ } else {
728
+ var _iterator5 = _createForOfIteratorHelper(dataSets),
729
+ _step5;
730
+ try {
731
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
732
+ var dataSet = _step5.value;
733
+ this.updateDataSetInfo(dataSet);
734
+ }
735
+ } catch (err) {
736
+ _iterator5.e(err);
737
+ } finally {
738
+ _iterator5.f();
507
739
  }
508
- } catch (err) {
509
- _iterator5.e(err);
510
- } finally {
511
- _iterator5.f();
512
740
  }
513
741
  var updatedObjects = [];
514
742
 
@@ -517,11 +745,16 @@ var HashTreeParser = /*#__PURE__*/function () {
517
745
  copyData: true
518
746
  });
519
747
 
748
+ // if we got metadata, process it (currently that means only potential visible data set list changes)
749
+ if (metadata) {
750
+ this.handleMetadataUpdate(metadata, updatedObjects);
751
+ }
752
+
520
753
  // then process the data in hash trees, if it is a new version, then add it to updatedObjects
521
754
  (0, _keys.default)(leafInfo).forEach(function (dataSetName) {
522
- if (_this3.dataSets[dataSetName]) {
523
- if (_this3.dataSets[dataSetName].hashTree) {
524
- var appliedChangesList = _this3.dataSets[dataSetName].hashTree.putItems(leafInfo[dataSetName].map(function (leaf) {
755
+ if (_this7.dataSets[dataSetName]) {
756
+ if (_this7.dataSets[dataSetName].hashTree) {
757
+ var appliedChangesList = _this7.dataSets[dataSetName].hashTree.putItems(leafInfo[dataSetName].map(function (leaf) {
525
758
  return {
526
759
  id: leaf.id,
527
760
  type: leaf.type,
@@ -548,10 +781,10 @@ var HashTreeParser = /*#__PURE__*/function () {
548
781
  });
549
782
  } else {
550
783
  // no hash tree means that the data set is not visible
551
- _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(_this3.debugId, " received leaf data for data set \"").concat(dataSetName, "\" that has no hash tree created, ignoring"));
784
+ _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(_this7.debugId, " received leaf data for data set \"").concat(dataSetName, "\" that has no hash tree created, ignoring"));
552
785
  }
553
786
  } else {
554
- _loggerProxy.default.logger.warn("HashTreeParser#handleLocusUpdate --> ".concat(_this3.debugId, " received leaf data for unknown data set \"").concat(dataSetName, "\", ignoring"));
787
+ _loggerProxy.default.logger.info("HashTreeParser#handleLocusUpdate --> ".concat(_this7.debugId, " received leaf data for unknown data set \"").concat(dataSetName, "\", ignoring"));
555
788
  }
556
789
  });
557
790
  if (updatedObjects.length === 0) {
@@ -562,9 +795,6 @@ var HashTreeParser = /*#__PURE__*/function () {
562
795
  updatedObjects: updatedObjects
563
796
  });
564
797
  }
565
-
566
- // todo: once Locus design on how visible data sets will be communicated in subsequent API responses is confirmed,
567
- // we'll need to check here if visible data sets have changed and update this.visibleDataSets, remove/create hash trees etc
568
798
  }
569
799
 
570
800
  /**
@@ -578,7 +808,7 @@ var HashTreeParser = /*#__PURE__*/function () {
578
808
  value: function updateDataSetInfo(receivedDataSet) {
579
809
  if (!this.dataSets[receivedDataSet.name]) {
580
810
  this.dataSets[receivedDataSet.name] = _objectSpread({}, receivedDataSet);
581
- _loggerProxy.default.logger.info("HashTreeParser#handleMessage --> ".concat(this.debugId, " created entry for \"").concat(receivedDataSet.name, "\" dataset: version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
811
+ _loggerProxy.default.logger.info("HashTreeParser#updateDataSetInfo --> ".concat(this.debugId, " created entry for \"").concat(receivedDataSet.name, "\" dataset: version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
582
812
  return;
583
813
  }
584
814
  // update our version of the dataSet
@@ -590,7 +820,7 @@ var HashTreeParser = /*#__PURE__*/function () {
590
820
  maxMs: receivedDataSet.backoff.maxMs,
591
821
  exponent: receivedDataSet.backoff.exponent
592
822
  };
593
- _loggerProxy.default.logger.info("HashTreeParser#handleMessage --> ".concat(this.debugId, " updated \"").concat(receivedDataSet.name, "\" to version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
823
+ _loggerProxy.default.logger.info("HashTreeParser#updateDataSetInfo --> ".concat(this.debugId, " updated \"").concat(receivedDataSet.name, "\" dataset to version=").concat(receivedDataSet.version, ", root=").concat(receivedDataSet.root));
594
824
  }
595
825
  }
596
826
 
@@ -602,24 +832,33 @@ var HashTreeParser = /*#__PURE__*/function () {
602
832
  }, {
603
833
  key: "checkForVisibleDataSetChanges",
604
834
  value: function checkForVisibleDataSetChanges(updatedObjects) {
605
- var _this4 = this;
835
+ var _this8 = this;
606
836
  var removedDataSets = [];
607
837
  var addedDataSets = [];
608
838
 
609
- // visibleDataSets can only be changed by self object updates
839
+ // visibleDataSets can only be changed by Metadata object updates
610
840
  updatedObjects.forEach(function (object) {
611
841
  var _object$data;
612
- // todo: in the future visibleDataSets will be in "Metadata" object, not in "self"
613
- if ((0, _utils.isSelf)(object) && (_object$data = object.data) !== null && _object$data !== void 0 && _object$data.visibleDataSets) {
614
- var newVisibleDataSets = object.data.visibleDataSets;
615
- removedDataSets = _this4.visibleDataSets.filter(function (ds) {
616
- return !newVisibleDataSets.includes(ds);
842
+ if ((0, _utils.isMetadata)(object) && (_object$data = object.data) !== null && _object$data !== void 0 && _object$data.visibleDataSets) {
843
+ var newVisibleDataSets = object.data.visibleDataSets.filter(function (vds) {
844
+ return !_this8.isExcludedDataSet(vds.name);
845
+ });
846
+ removedDataSets = _this8.visibleDataSets.filter(function (ds) {
847
+ return !newVisibleDataSets.some(function (nvs) {
848
+ return nvs.name === ds.name;
849
+ });
617
850
  });
618
- addedDataSets = newVisibleDataSets.filter(function (ds) {
619
- return !_this4.visibleDataSets.includes(ds);
851
+ addedDataSets = newVisibleDataSets.filter(function (nvs) {
852
+ return _this8.visibleDataSets.every(function (ds) {
853
+ return ds.name !== nvs.name;
854
+ });
620
855
  });
621
856
  if (removedDataSets.length > 0 || addedDataSets.length > 0) {
622
- _loggerProxy.default.logger.info("HashTreeParser#checkForVisibleDataSetChanges --> ".concat(_this4.debugId, " visible data sets change: removed: ").concat(removedDataSets.join(', '), ", added: ").concat(addedDataSets.join(', ')));
857
+ _loggerProxy.default.logger.info("HashTreeParser#checkForVisibleDataSetChanges --> ".concat(_this8.debugId, " visible data sets change: removed: ").concat(removedDataSets.map(function (ds) {
858
+ return ds.name;
859
+ }).join(', '), ", added: ").concat(addedDataSets.map(function (ds) {
860
+ return ds.name;
861
+ }).join(', ')));
623
862
  }
624
863
  }
625
864
  });
@@ -641,11 +880,15 @@ var HashTreeParser = /*#__PURE__*/function () {
641
880
  value: function deleteHashTree(dataSetName) {
642
881
  this.dataSets[dataSetName].hashTree = undefined;
643
882
 
644
- // we also need to stop the timer as there is no hash tree anymore to sync
883
+ // we also need to stop the timers as there is no hash tree anymore to sync
645
884
  if (this.dataSets[dataSetName].timer) {
646
885
  clearTimeout(this.dataSets[dataSetName].timer);
647
886
  this.dataSets[dataSetName].timer = undefined;
648
887
  }
888
+ if (this.dataSets[dataSetName].heartbeatWatchdogTimer) {
889
+ clearTimeout(this.dataSets[dataSetName].heartbeatWatchdogTimer);
890
+ this.dataSets[dataSetName].heartbeatWatchdogTimer = undefined;
891
+ }
649
892
  }
650
893
 
651
894
  /**
@@ -657,38 +900,40 @@ var HashTreeParser = /*#__PURE__*/function () {
657
900
  * visible data sets and they require async initialization, the names of these data sets
658
901
  * are returned in an array.
659
902
  *
660
- * @param {string[]} removedDataSets - The list of removed data sets.
661
- * @param {string[]} addedDataSets - The list of added data sets.
903
+ * @param {VisibleDataSetInfo[]} removedDataSets - The list of removed data sets.
904
+ * @param {VisibleDataSetInfo[]} addedDataSets - The list of added data sets.
662
905
  * @param {HashTreeObject[]} updatedObjects - The list of updated hash tree objects to which changes will be added.
663
- * @returns {string[]} names of data sets that couldn't be initialized synchronously
906
+ * @returns {VisibleDataSetInfo[]} list of data sets that couldn't be initialized synchronously
664
907
  */
665
908
  }, {
666
909
  key: "processVisibleDataSetChanges",
667
910
  value: function processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects) {
668
- var _this5 = this;
911
+ var _this9 = this;
669
912
  var dataSetsRequiringInitialization = [];
670
913
 
671
914
  // if a visible data set was removed, we need to tell our client that all objects from it are removed
672
915
  var removedObjects = [];
673
916
  removedDataSets.forEach(function (ds) {
674
- var _this5$dataSets$ds;
675
- if ((_this5$dataSets$ds = _this5.dataSets[ds]) !== null && _this5$dataSets$ds !== void 0 && _this5$dataSets$ds.hashTree) {
676
- for (var i = 0; i < _this5.dataSets[ds].hashTree.numLeaves; i += 1) {
677
- removedObjects.push.apply(removedObjects, (0, _toConsumableArray2.default)(_this5.dataSets[ds].hashTree.getLeafData(i).map(function (elementId) {
917
+ var _this9$dataSets$ds$na;
918
+ if ((_this9$dataSets$ds$na = _this9.dataSets[ds.name]) !== null && _this9$dataSets$ds$na !== void 0 && _this9$dataSets$ds$na.hashTree) {
919
+ for (var i = 0; i < _this9.dataSets[ds.name].hashTree.numLeaves; i += 1) {
920
+ removedObjects.push.apply(removedObjects, (0, _toConsumableArray2.default)(_this9.dataSets[ds.name].hashTree.getLeafData(i).map(function (elementId) {
678
921
  return {
679
922
  htMeta: {
680
923
  elementId: elementId,
681
- dataSetNames: [ds]
924
+ dataSetNames: [ds.name]
682
925
  },
683
926
  data: null
684
927
  };
685
928
  })));
686
929
  }
687
- _this5.deleteHashTree(ds);
930
+ _this9.deleteHashTree(ds.name);
688
931
  }
689
932
  });
690
933
  this.visibleDataSets = this.visibleDataSets.filter(function (vds) {
691
- return !removedDataSets.includes(vds);
934
+ return !removedDataSets.some(function (rds) {
935
+ return rds.name === vds.name;
936
+ });
692
937
  });
693
938
  updatedObjects.push.apply(updatedObjects, removedObjects);
694
939
 
@@ -698,22 +943,29 @@ var HashTreeParser = /*#__PURE__*/function () {
698
943
  try {
699
944
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
700
945
  var ds = _step6.value;
701
- var dataSetInfo = this.dataSets[ds];
946
+ var dataSetInfo = this.dataSets[ds.name];
702
947
  if (dataSetInfo) {
703
- if (this.visibleDataSets.includes(dataSetInfo.name)) {
704
- _loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " Data set \"").concat(ds, "\" is already visible, skipping"));
948
+ if (this.isVisibleDataSet(dataSetInfo.name)) {
949
+ _loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " Data set \"").concat(ds.name, "\" is already visible, skipping"));
705
950
 
706
951
  // eslint-disable-next-line no-continue
707
952
  continue;
708
953
  }
709
- _loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " Adding visible data set \"").concat(ds, "\""));
710
- this.visibleDataSets.push(ds);
954
+ _loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " Adding visible data set \"").concat(ds.name, "\""));
955
+ if (!this.addToVisibleDataSetsList(ds)) {
956
+ // eslint-disable-next-line no-continue
957
+ continue;
958
+ }
711
959
  var hashTree = new _hashTree.default([], dataSetInfo.leafCount);
712
960
  this.dataSets[dataSetInfo.name] = _objectSpread(_objectSpread({}, dataSetInfo), {}, {
713
961
  hashTree: hashTree
714
962
  });
963
+
964
+ // this call is needed here for the edge case where we receive a message with new visible data sets
965
+ // and there are no objects belonging to these data sets in the message but we already have the info about them in this.dataSets
966
+ this.runSyncAlgorithm(this.dataSets[dataSetInfo.name]);
715
967
  } else {
716
- _loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " visible data set \"").concat(ds, "\" added but no info about it in our dataSets structures"));
968
+ _loggerProxy.default.logger.info("HashTreeParser#processVisibleDataSetChanges --> ".concat(this.debugId, " visible data set \"").concat(ds.name, "\" added but no info about it in our dataSets structures"));
717
969
  // todo: add a metric here
718
970
  dataSetsRequiringInitialization.push(ds);
719
971
  }
@@ -730,25 +982,30 @@ var HashTreeParser = /*#__PURE__*/function () {
730
982
  * Adds entries to the passed in updateObjects array
731
983
  * for the changes that result from adding and removing visible data sets.
732
984
  *
733
- * @param {HashTreeMessage} message - The hash tree message that triggered the visible data set changes.
734
- * @param {string[]} addedDataSets - The list of added data sets.
985
+ * @param {VisibleDataSetInfo[]} addedDataSets - The list of added data sets.
735
986
  * @returns {Promise<void>}
736
987
  */
737
988
  }, {
738
989
  key: "initializeNewVisibleDataSets",
739
990
  value: (function () {
740
- var _initializeNewVisibleDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(message, addedDataSets) {
741
- var _this6 = this;
991
+ var _initializeNewVisibleDataSets = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(addedDataSets) {
992
+ var _this0 = this;
742
993
  var allDataSets, _iterator7, _step7, _loop, _t2;
743
994
  return _regenerator.default.wrap(function (_context5) {
744
995
  while (1) switch (_context5.prev = _context5.next) {
745
996
  case 0:
746
- _context5.next = 1;
747
- return this.getAllDataSetsMetadata(message.visibleDataSetsUrl);
997
+ if (!(this.state === 'stopped')) {
998
+ _context5.next = 1;
999
+ break;
1000
+ }
1001
+ return _context5.abrupt("return");
748
1002
  case 1:
1003
+ _context5.next = 2;
1004
+ return this.getAllVisibleDataSetsFromLocus();
1005
+ case 2:
749
1006
  allDataSets = _context5.sent;
750
1007
  _iterator7 = _createForOfIteratorHelper(addedDataSets);
751
- _context5.prev = 2;
1008
+ _context5.prev = 3;
752
1009
  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
753
1010
  var ds, dataSetInfo, updates;
754
1011
  return _regenerator.default.wrap(function (_context4) {
@@ -756,22 +1013,22 @@ var HashTreeParser = /*#__PURE__*/function () {
756
1013
  case 0:
757
1014
  ds = _step7.value;
758
1015
  dataSetInfo = allDataSets.find(function (d) {
759
- return d.name === ds;
1016
+ return d.name === ds.name;
760
1017
  });
761
- _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this6.debugId, " initializing data set \"").concat(ds, "\""));
1018
+ _loggerProxy.default.logger.info("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this0.debugId, " initializing data set \"").concat(ds.name, "\""));
762
1019
  if (dataSetInfo) {
763
1020
  _context4.next = 1;
764
1021
  break;
765
1022
  }
766
- _loggerProxy.default.logger.warn("HashTreeParser#handleHashTreeMessage --> ".concat(_this6.debugId, " missing info about data set \"").concat(ds, "\" in Locus response from visibleDataSetsUrl"));
1023
+ _loggerProxy.default.logger.warn("HashTreeParser#initializeNewVisibleDataSets --> ".concat(_this0.debugId, " missing info about data set \"").concat(ds.name, "\" in Locus response from visibleDataSetsUrl"));
767
1024
  _context4.next = 3;
768
1025
  break;
769
1026
  case 1:
770
1027
  _context4.next = 2;
771
- return _this6.initializeNewVisibleDataSet(dataSetInfo);
1028
+ return _this0.initializeNewVisibleDataSet(ds, dataSetInfo);
772
1029
  case 2:
773
1030
  updates = _context4.sent;
774
- _this6.callLocusInfoUpdateCallback(updates);
1031
+ _this0.callLocusInfoUpdateCallback(updates);
775
1032
  case 3:
776
1033
  case "end":
777
1034
  return _context4.stop();
@@ -779,33 +1036,33 @@ var HashTreeParser = /*#__PURE__*/function () {
779
1036
  }, _loop);
780
1037
  });
781
1038
  _iterator7.s();
782
- case 3:
1039
+ case 4:
783
1040
  if ((_step7 = _iterator7.n()).done) {
784
- _context5.next = 5;
1041
+ _context5.next = 6;
785
1042
  break;
786
1043
  }
787
- return _context5.delegateYield(_loop(), "t0", 4);
788
- case 4:
789
- _context5.next = 3;
790
- break;
1044
+ return _context5.delegateYield(_loop(), "t0", 5);
791
1045
  case 5:
792
- _context5.next = 7;
1046
+ _context5.next = 4;
793
1047
  break;
794
1048
  case 6:
795
- _context5.prev = 6;
796
- _t2 = _context5["catch"](2);
797
- _iterator7.e(_t2);
1049
+ _context5.next = 8;
1050
+ break;
798
1051
  case 7:
799
1052
  _context5.prev = 7;
800
- _iterator7.f();
801
- return _context5.finish(7);
1053
+ _t2 = _context5["catch"](3);
1054
+ _iterator7.e(_t2);
802
1055
  case 8:
1056
+ _context5.prev = 8;
1057
+ _iterator7.f();
1058
+ return _context5.finish(8);
1059
+ case 9:
803
1060
  case "end":
804
1061
  return _context5.stop();
805
1062
  }
806
- }, _callee4, this, [[2, 6, 7, 8]]);
1063
+ }, _callee4, this, [[3, 7, 8, 9]]);
807
1064
  }));
808
- function initializeNewVisibleDataSets(_x5, _x6) {
1065
+ function initializeNewVisibleDataSets(_x5) {
809
1066
  return _initializeNewVisibleDataSets.apply(this, arguments);
810
1067
  }
811
1068
  return initializeNewVisibleDataSets;
@@ -815,156 +1072,119 @@ var HashTreeParser = /*#__PURE__*/function () {
815
1072
  *
816
1073
  * @param {HashTreeMessage} message - The hash tree message containing data sets and objects to be processed
817
1074
  * @param {string} [debugText] - Optional debug text to include in logs
818
- * @returns {Promise}
1075
+ * @returns {HashTreeObject[]} list of hash tree objects that were updated as a result of processing the message
819
1076
  */
820
1077
  )
821
1078
  }, {
822
1079
  key: "parseMessage",
823
- value: (function () {
824
- var _parseMessage = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(message, debugText) {
825
- var _message$locusStateEl,
826
- _this7 = this;
827
- var dataSets, visibleDataSetsUrl, isRosterDropped, updatedObjects, dataSetsRequiringInitialization, selfUpdates, updatedSelfObjects, _this$checkForVisible, changeDetected, removedDataSets, addedDataSets;
828
- return _regenerator.default.wrap(function (_context6) {
829
- while (1) switch (_context6.prev = _context6.next) {
830
- case 0:
831
- dataSets = message.dataSets, visibleDataSetsUrl = message.visibleDataSetsUrl;
832
- _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " received message ").concat(debugText || '', ":"), message);
833
- if (((_message$locusStateEl = message.locusStateElements) === null || _message$locusStateEl === void 0 ? void 0 : _message$locusStateEl.length) === 0) {
834
- _loggerProxy.default.logger.warn("HashTreeParser#parseMessage --> ".concat(this.debugId, " got empty locusStateElements!!!"));
835
- // todo: send a metric
836
- }
1080
+ value: function parseMessage(message, debugText) {
1081
+ var _message$locusStateEl,
1082
+ _this1 = this,
1083
+ _message$locusStateEl2;
1084
+ if (this.state === 'stopped') {
1085
+ return [];
1086
+ }
1087
+ var dataSets = message.dataSets,
1088
+ visibleDataSetsUrl = message.visibleDataSetsUrl;
1089
+ _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " received message ").concat(debugText || '', ":"), message);
1090
+ if (((_message$locusStateEl = message.locusStateElements) === null || _message$locusStateEl === void 0 ? void 0 : _message$locusStateEl.length) === 0) {
1091
+ _loggerProxy.default.logger.warn("HashTreeParser#parseMessage --> ".concat(this.debugId, " got empty locusStateElements!!!"));
1092
+ // todo: send a metric
1093
+ }
837
1094
 
838
- // first, update our metadata about the datasets with info from the message
839
- this.visibleDataSetsUrl = visibleDataSetsUrl;
840
- dataSets.forEach(function (dataSet) {
841
- return _this7.updateDataSetInfo(dataSet);
842
- });
843
- if (!this.isEndMessage(message)) {
844
- _context6.next = 1;
845
- break;
846
- }
847
- _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " received END message"));
848
- this.stopAllTimers();
849
- return _context6.abrupt("return", {
850
- updateType: LocusInfoUpdateType.MEETING_ENDED
851
- });
852
- case 1:
853
- isRosterDropped = false;
854
- updatedObjects = []; // when we detect new visible datasets, it may be that the metadata about them is not
855
- // available in the message, they will require separate async initialization
856
- dataSetsRequiringInitialization = []; // first find out if there are any visible data set changes - they're signalled in SELF object updates
857
- selfUpdates = (message.locusStateElements || []).filter(function (object) {
858
- return (
859
- // todo: SPARK-744859 once Locus supports it, we will filter for "Metadata" type here instead of "self"
860
- (0, _utils.isSelf)(object)
861
- );
862
- });
863
- if (selfUpdates.length > 0) {
864
- updatedSelfObjects = [];
865
- selfUpdates.forEach(function (object) {
866
- // todo: once Locus supports it, we will use the "view" field here instead of dataSetNames
867
- var _iterator8 = _createForOfIteratorHelper(object.htMeta.dataSetNames),
868
- _step8;
869
- try {
870
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
871
- var _this7$dataSets$dataS;
872
- var dataSetName = _step8.value;
873
- var hashTree = (_this7$dataSets$dataS = _this7.dataSets[dataSetName]) === null || _this7$dataSets$dataS === void 0 ? void 0 : _this7$dataSets$dataS.hashTree;
874
- if (hashTree && object.data) {
875
- if (hashTree.putItem(object.htMeta.elementId)) {
876
- updatedSelfObjects.push(object);
877
- }
878
- }
879
- }
880
- } catch (err) {
881
- _iterator8.e(err);
882
- } finally {
883
- _iterator8.f();
884
- }
885
- });
886
- updatedObjects.push.apply(updatedObjects, updatedSelfObjects);
887
- _this$checkForVisible = this.checkForVisibleDataSetChanges(updatedSelfObjects), changeDetected = _this$checkForVisible.changeDetected, removedDataSets = _this$checkForVisible.removedDataSets, addedDataSets = _this$checkForVisible.addedDataSets;
888
- if (changeDetected) {
889
- dataSetsRequiringInitialization = this.processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects);
890
- }
891
- }
1095
+ // first, update our metadata about the datasets with info from the message
1096
+ this.visibleDataSetsUrl = visibleDataSetsUrl;
1097
+ dataSets.forEach(function (dataSet) {
1098
+ return _this1.updateDataSetInfo(dataSet);
1099
+ });
1100
+ var updatedObjects = [];
892
1101
 
893
- // by this point we now have this.dataSets setup for data sets from this message
894
- // and hash trees created for the new visible data sets,
895
- // so we can now process all the updates from the message
896
- dataSets.forEach(function (dataSet) {
897
- if (_this7.dataSets[dataSet.name]) {
898
- var hashTree = _this7.dataSets[dataSet.name].hashTree;
899
- if (hashTree) {
900
- var locusStateElementsForThisSet = message.locusStateElements.filter(function (object) {
901
- return object.htMeta.dataSetNames.includes(dataSet.name);
902
- });
903
- var appliedChangesList = hashTree.updateItems(locusStateElementsForThisSet.map(function (object) {
904
- return object.data ? {
905
- operation: 'update',
906
- item: object.htMeta.elementId
907
- } : {
908
- operation: 'remove',
909
- item: object.htMeta.elementId
910
- };
911
- }));
912
- (0, _lodash.zip)(appliedChangesList, locusStateElementsForThisSet).forEach(function (_ref5) {
913
- var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
914
- changeApplied = _ref6[0],
915
- object = _ref6[1];
916
- if (changeApplied) {
917
- if ((0, _utils.isSelf)(object) && !object.data) {
918
- isRosterDropped = true;
919
- }
920
- // add to updatedObjects so that our locus DTO will get updated with the new object
921
- updatedObjects.push(object);
922
- }
923
- });
924
- } else {
925
- _loggerProxy.default.logger.info("Locus-info:index#parseMessage --> ".concat(_this7.debugId, " unexpected (not visible) dataSet ").concat(dataSet.name, " received in hash tree message"));
926
- }
927
- }
928
- if (!isRosterDropped) {
929
- _this7.runSyncAlgorithm(dataSet);
1102
+ // when we detect new visible datasets, it may be that the metadata about them is not
1103
+ // available in the message, they will require separate async initialization
1104
+ var dataSetsRequiringInitialization = [];
1105
+
1106
+ // first find out if there are any visible data set changes - they're signalled in Metadata object updates
1107
+ var metadataUpdates = (message.locusStateElements || []).filter(function (object) {
1108
+ return (0, _utils.isMetadata)(object);
1109
+ });
1110
+ if (metadataUpdates.length > 0) {
1111
+ var updatedMetadataObjects = [];
1112
+ metadataUpdates.forEach(function (object) {
1113
+ // todo: once Locus supports it, we will use the "view" field here instead of dataSetNames
1114
+ var _iterator8 = _createForOfIteratorHelper(object.htMeta.dataSetNames),
1115
+ _step8;
1116
+ try {
1117
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1118
+ var _this1$dataSets$dataS;
1119
+ var dataSetName = _step8.value;
1120
+ var hashTree = (_this1$dataSets$dataS = _this1.dataSets[dataSetName]) === null || _this1$dataSets$dataS === void 0 ? void 0 : _this1$dataSets$dataS.hashTree;
1121
+ if (hashTree && object.data) {
1122
+ if (hashTree.putItem(object.htMeta.elementId)) {
1123
+ updatedMetadataObjects.push(object);
930
1124
  }
931
- });
932
- if (!isRosterDropped) {
933
- _context6.next = 2;
934
- break;
935
1125
  }
936
- _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " detected roster drop"));
937
- this.stopAllTimers();
938
-
939
- // in case of roster drop we don't care about other updates
940
- return _context6.abrupt("return", {
941
- updateType: LocusInfoUpdateType.MEETING_ENDED
1126
+ }
1127
+ } catch (err) {
1128
+ _iterator8.e(err);
1129
+ } finally {
1130
+ _iterator8.f();
1131
+ }
1132
+ });
1133
+ updatedObjects.push.apply(updatedObjects, updatedMetadataObjects);
1134
+ var _this$checkForVisible2 = this.checkForVisibleDataSetChanges(updatedMetadataObjects),
1135
+ changeDetected = _this$checkForVisible2.changeDetected,
1136
+ removedDataSets = _this$checkForVisible2.removedDataSets,
1137
+ addedDataSets = _this$checkForVisible2.addedDataSets;
1138
+ if (changeDetected) {
1139
+ dataSetsRequiringInitialization = this.processVisibleDataSetChanges(removedDataSets, addedDataSets, updatedObjects);
1140
+ }
1141
+ }
1142
+ if (((_message$locusStateEl2 = message.locusStateElements) === null || _message$locusStateEl2 === void 0 ? void 0 : _message$locusStateEl2.length) > 0) {
1143
+ // by this point we now have this.dataSets setup for data sets from this message
1144
+ // and hash trees created for the new visible data sets,
1145
+ // so we can now process all the updates from the message
1146
+ dataSets.forEach(function (dataSet) {
1147
+ if (_this1.dataSets[dataSet.name]) {
1148
+ var hashTree = _this1.dataSets[dataSet.name].hashTree;
1149
+ if (hashTree) {
1150
+ var locusStateElementsForThisSet = message.locusStateElements.filter(function (object) {
1151
+ return object.htMeta.dataSetNames.includes(dataSet.name);
942
1152
  });
943
- case 2:
944
- if (dataSetsRequiringInitialization.length > 0) {
945
- // there are some data sets that we need to initialize asynchronously
946
- queueMicrotask(function () {
947
- _this7.initializeNewVisibleDataSets(message, dataSetsRequiringInitialization);
948
- });
949
- }
950
- if (updatedObjects.length === 0) {
951
- _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " No objects updated as a result of received message"));
952
- }
953
- return _context6.abrupt("return", {
954
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
955
- updatedObjects: updatedObjects
1153
+ var appliedChangesList = hashTree.updateItems(locusStateElementsForThisSet.map(function (object) {
1154
+ return object.data ? {
1155
+ operation: 'update',
1156
+ item: object.htMeta.elementId
1157
+ } : {
1158
+ operation: 'remove',
1159
+ item: object.htMeta.elementId
1160
+ };
1161
+ }));
1162
+ (0, _lodash.zip)(appliedChangesList, locusStateElementsForThisSet).forEach(function (_ref5) {
1163
+ var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
1164
+ changeApplied = _ref6[0],
1165
+ object = _ref6[1];
1166
+ if (changeApplied) {
1167
+ // add to updatedObjects so that our locus DTO will get updated with the new object
1168
+ updatedObjects.push(object);
1169
+ }
956
1170
  });
957
- case 3:
958
- case "end":
959
- return _context6.stop();
1171
+ } else {
1172
+ _loggerProxy.default.logger.info("Locus-info:index#parseMessage --> ".concat(_this1.debugId, " unexpected (not visible) dataSet ").concat(dataSet.name, " received in hash tree message"));
1173
+ }
960
1174
  }
961
- }, _callee5, this);
962
- }));
963
- function parseMessage(_x7, _x8) {
964
- return _parseMessage.apply(this, arguments);
1175
+ _this1.runSyncAlgorithm(dataSet);
1176
+ });
965
1177
  }
966
- return parseMessage;
967
- }()
1178
+ if (dataSetsRequiringInitialization.length > 0) {
1179
+ // there are some data sets that we need to initialize asynchronously
1180
+ this.queueInitForNewVisibleDataSets(dataSetsRequiringInitialization);
1181
+ }
1182
+ if (updatedObjects.length === 0) {
1183
+ _loggerProxy.default.logger.info("HashTreeParser#parseMessage --> ".concat(this.debugId, " No objects updated as a result of received message"));
1184
+ }
1185
+ return updatedObjects;
1186
+ }
1187
+
968
1188
  /**
969
1189
  * Handles incoming hash tree messages, updates the hash trees and calls locusInfoUpdateCallback
970
1190
  *
@@ -972,52 +1192,89 @@ var HashTreeParser = /*#__PURE__*/function () {
972
1192
  * @param {string} [debugText] - Optional debug text to include in logs
973
1193
  * @returns {void}
974
1194
  */
975
- )
976
1195
  }, {
977
1196
  key: "handleMessage",
978
- value: (function () {
979
- var _handleMessage = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6(message, debugText) {
980
- var updates;
981
- return _regenerator.default.wrap(function (_context7) {
982
- while (1) switch (_context7.prev = _context7.next) {
983
- case 0:
984
- if (!(message.locusStateElements === undefined)) {
985
- _context7.next = 1;
986
- break;
987
- }
988
- this.handleRootHashHeartBeatMessage(message);
989
- _context7.next = 3;
990
- break;
991
- case 1:
992
- _context7.next = 2;
993
- return this.parseMessage(message, debugText);
994
- case 2:
995
- updates = _context7.sent;
996
- this.callLocusInfoUpdateCallback(updates);
997
- case 3:
998
- case "end":
999
- return _context7.stop();
1000
- }
1001
- }, _callee6, this);
1002
- }));
1003
- function handleMessage(_x9, _x0) {
1004
- return _handleMessage.apply(this, arguments);
1197
+ value: function handleMessage(message, debugText) {
1198
+ if (this.state === 'stopped') {
1199
+ return;
1005
1200
  }
1006
- return handleMessage;
1007
- }()
1201
+ if (message.heartbeatIntervalMs) {
1202
+ this.heartbeatIntervalMs = message.heartbeatIntervalMs;
1203
+ }
1204
+ if (this.isEndMessage(message)) {
1205
+ _loggerProxy.default.logger.info("HashTreeParser#handleMessage --> ".concat(this.debugId, " received sentinel END MEETING message"));
1206
+ this.stopAllTimers();
1207
+ this.callLocusInfoUpdateCallback({
1208
+ updateType: LocusInfoUpdateType.MEETING_ENDED
1209
+ });
1210
+ } else if (message.locusStateElements === undefined) {
1211
+ this.handleRootHashHeartBeatMessage(message);
1212
+ this.resetHeartbeatWatchdogs(message.dataSets);
1213
+ } else {
1214
+ var updatedObjects = this.parseMessage(message, debugText);
1215
+ this.resetHeartbeatWatchdogs(message.dataSets);
1216
+ this.callLocusInfoUpdateCallback({
1217
+ updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
1218
+ updatedObjects: updatedObjects
1219
+ });
1220
+ }
1221
+ }
1222
+
1008
1223
  /**
1009
1224
  * Calls the updateInfo callback if there are any updates to report
1010
1225
  *
1011
1226
  * @param {Object} updates parsed from a Locus message
1012
1227
  * @returns {void}
1013
1228
  */
1014
- )
1015
1229
  }, {
1016
1230
  key: "callLocusInfoUpdateCallback",
1017
1231
  value: function callLocusInfoUpdateCallback(updates) {
1232
+ var _this10 = this;
1233
+ if (this.state === 'stopped') {
1234
+ return;
1235
+ }
1018
1236
  var updateType = updates.updateType,
1019
1237
  updatedObjects = updates.updatedObjects;
1020
- if (updateType !== LocusInfoUpdateType.OBJECTS_UPDATED || (updatedObjects === null || updatedObjects === void 0 ? void 0 : updatedObjects.length) > 0) {
1238
+ if (updateType === LocusInfoUpdateType.OBJECTS_UPDATED && (updatedObjects === null || updatedObjects === void 0 ? void 0 : updatedObjects.length) > 0) {
1239
+ // Filter out updates for objects that already have a higher version in their datasets,
1240
+ // or removals for objects that still exist in any of their datasets
1241
+ var filteredUpdates = updatedObjects.filter(function (object) {
1242
+ var elementId = object.htMeta.elementId;
1243
+ var type = elementId.type,
1244
+ id = elementId.id,
1245
+ version = elementId.version;
1246
+
1247
+ // Check all datasets
1248
+ for (var _i2 = 0, _Object$keys3 = (0, _keys.default)(_this10.dataSets); _i2 < _Object$keys3.length; _i2++) {
1249
+ var dataSetName = _Object$keys3[_i2];
1250
+ var dataSet = _this10.dataSets[dataSetName];
1251
+
1252
+ // only visible datasets have hash trees set
1253
+ if (dataSet !== null && dataSet !== void 0 && dataSet.hashTree) {
1254
+ var existingVersion = dataSet.hashTree.getItemVersion(id, type);
1255
+ if (existingVersion !== undefined) {
1256
+ if (object.data) {
1257
+ // For updates: filter out if any dataset has a higher version
1258
+ if (existingVersion > version) {
1259
+ _loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this10.debugId, " Filtering out update for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" has v").concat(existingVersion));
1260
+ return false;
1261
+ }
1262
+ } else if (existingVersion >= version) {
1263
+ // For removals: filter out if the object still exists in any dataset
1264
+ _loggerProxy.default.logger.info("HashTreeParser#callLocusInfoUpdateCallback --> ".concat(_this10.debugId, " Filtering out removal for ").concat(type, ":").concat(id, " v").concat(version, " because dataset \"").concat(dataSetName, "\" still has v").concat(existingVersion));
1265
+ return false;
1266
+ }
1267
+ }
1268
+ }
1269
+ }
1270
+ return true;
1271
+ });
1272
+ if (filteredUpdates.length > 0) {
1273
+ this.locusInfoUpdateCallback(updateType, {
1274
+ updatedObjects: filteredUpdates
1275
+ });
1276
+ }
1277
+ } else if (updateType !== LocusInfoUpdateType.OBJECTS_UPDATED) {
1021
1278
  this.locusInfoUpdateCallback(updateType, {
1022
1279
  updatedObjects: updatedObjects
1023
1280
  });
@@ -1039,16 +1296,117 @@ var HashTreeParser = /*#__PURE__*/function () {
1039
1296
  return Math.round(Math.pow(randomValue, exponent) * maxMs);
1040
1297
  }
1041
1298
 
1299
+ /**
1300
+ * Performs a sync for the given data set.
1301
+ *
1302
+ * @param {InternalDataSet} dataSet - The data set to sync
1303
+ * @param {string} rootHash - Our current root hash for this data set
1304
+ * @param {string} reason - The reason for the sync (used for logging)
1305
+ * @returns {Promise<void>}
1306
+ */
1307
+ }, {
1308
+ key: "performSync",
1309
+ value: (function () {
1310
+ var _performSync = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(dataSet, rootHash, reason) {
1311
+ var mismatchedLeavesData, receivedHashes, _yield$this$getHashes, hashes, latestDataSetInfo, mismatchedLeaveIndexes, syncResponse, _t3, _t4;
1312
+ return _regenerator.default.wrap(function (_context6) {
1313
+ while (1) switch (_context6.prev = _context6.next) {
1314
+ case 0:
1315
+ if (dataSet.hashTree) {
1316
+ _context6.next = 1;
1317
+ break;
1318
+ }
1319
+ return _context6.abrupt("return");
1320
+ case 1:
1321
+ _context6.prev = 1;
1322
+ _loggerProxy.default.logger.info("HashTreeParser#performSync --> ".concat(this.debugId, " ").concat(reason, ", syncing data set \"").concat(dataSet.name, "\""));
1323
+ mismatchedLeavesData = {};
1324
+ if (!(dataSet.leafCount !== 1)) {
1325
+ _context6.next = 7;
1326
+ break;
1327
+ }
1328
+ _context6.prev = 2;
1329
+ _context6.next = 3;
1330
+ return this.getHashesFromLocus(dataSet.name, rootHash);
1331
+ case 3:
1332
+ _yield$this$getHashes = _context6.sent;
1333
+ hashes = _yield$this$getHashes.hashes;
1334
+ latestDataSetInfo = _yield$this$getHashes.dataSet;
1335
+ receivedHashes = hashes;
1336
+ dataSet.hashTree.resize(latestDataSetInfo.leafCount);
1337
+ _context6.next = 6;
1338
+ break;
1339
+ case 4:
1340
+ _context6.prev = 4;
1341
+ _t3 = _context6["catch"](2);
1342
+ if (!(_t3.statusCode === 409)) {
1343
+ _context6.next = 5;
1344
+ break;
1345
+ }
1346
+ // this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
1347
+ _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(this.debugId, " Got 409 when fetching hashes for data set \"").concat(dataSet.name, "\": ").concat(_t3.message));
1348
+ return _context6.abrupt("return");
1349
+ case 5:
1350
+ throw _t3;
1351
+ case 6:
1352
+ // identify mismatched leaves
1353
+ mismatchedLeaveIndexes = dataSet.hashTree.diffHashes(receivedHashes);
1354
+ mismatchedLeaveIndexes.forEach(function (index) {
1355
+ mismatchedLeavesData[index] = dataSet.hashTree.getLeafData(index);
1356
+ });
1357
+ _context6.next = 8;
1358
+ break;
1359
+ case 7:
1360
+ mismatchedLeavesData[0] = dataSet.hashTree.getLeafData(0);
1361
+ case 8:
1362
+ if (!((0, _keys.default)(mismatchedLeavesData).length > 0)) {
1363
+ _context6.next = 10;
1364
+ break;
1365
+ }
1366
+ _context6.next = 9;
1367
+ return this.sendSyncRequestToLocus(dataSet, mismatchedLeavesData);
1368
+ case 9:
1369
+ syncResponse = _context6.sent;
1370
+ // sync API may return nothing (in that case data will arrive via messages)
1371
+ // or it may return a response in the same format as messages
1372
+ if (syncResponse) {
1373
+ this.handleMessage(syncResponse, 'via sync API');
1374
+ }
1375
+ case 10:
1376
+ _context6.next = 12;
1377
+ break;
1378
+ case 11:
1379
+ _context6.prev = 11;
1380
+ _t4 = _context6["catch"](1);
1381
+ if (_t4 instanceof MeetingEndedError) {
1382
+ this.callLocusInfoUpdateCallback({
1383
+ updateType: LocusInfoUpdateType.MEETING_ENDED
1384
+ });
1385
+ } else {
1386
+ _loggerProxy.default.logger.warn("HashTreeParser#performSync --> ".concat(this.debugId, " error during sync for data set \"").concat(dataSet.name, "\":"), _t4);
1387
+ }
1388
+ case 12:
1389
+ case "end":
1390
+ return _context6.stop();
1391
+ }
1392
+ }, _callee5, this, [[1, 11], [2, 4]]);
1393
+ }));
1394
+ function performSync(_x6, _x7, _x8) {
1395
+ return _performSync.apply(this, arguments);
1396
+ }
1397
+ return performSync;
1398
+ }()
1042
1399
  /**
1043
1400
  * Runs the sync algorithm for the given data set.
1044
1401
  *
1045
1402
  * @param {DataSet} receivedDataSet - The data set to run the sync algorithm for.
1046
1403
  * @returns {void}
1047
1404
  */
1405
+ )
1048
1406
  }, {
1049
1407
  key: "runSyncAlgorithm",
1050
1408
  value: function runSyncAlgorithm(receivedDataSet) {
1051
- var _this8 = this;
1409
+ var _this11 = this;
1052
1410
  var dataSet = this.dataSets[receivedDataSet.name];
1053
1411
  if (!dataSet) {
1054
1412
  _loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " No data set found for ").concat(receivedDataSet.name, ", skipping sync algorithm"));
@@ -1069,93 +1427,99 @@ var HashTreeParser = /*#__PURE__*/function () {
1069
1427
  clearTimeout(dataSet.timer);
1070
1428
  }
1071
1429
  _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " setting \"").concat(dataSet.name, "\" sync timer for ").concat(delay));
1072
- dataSet.timer = setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
1073
- var rootHash, mismatchedLeavesData, receivedHashes, _yield$_this8$getHash, hashes, latestDataSetInfo, mismatchedLeaveIndexes, syncResponse, _t3;
1074
- return _regenerator.default.wrap(function (_context8) {
1075
- while (1) switch (_context8.prev = _context8.next) {
1430
+ dataSet.timer = setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
1431
+ var rootHash;
1432
+ return _regenerator.default.wrap(function (_context7) {
1433
+ while (1) switch (_context7.prev = _context7.next) {
1076
1434
  case 0:
1077
1435
  dataSet.timer = undefined;
1078
1436
  if (dataSet.hashTree) {
1079
- _context8.next = 1;
1437
+ _context7.next = 1;
1080
1438
  break;
1081
1439
  }
1082
- _loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(_this8.debugId, " Data set \"").concat(dataSet.name, "\" no longer has a hash tree, cannot run sync algorithm"));
1083
- return _context8.abrupt("return");
1440
+ _loggerProxy.default.logger.warn("HashTreeParser#runSyncAlgorithm --> ".concat(_this11.debugId, " Data set \"").concat(dataSet.name, "\" no longer has a hash tree, cannot run sync algorithm"));
1441
+ return _context7.abrupt("return");
1084
1442
  case 1:
1085
1443
  rootHash = dataSet.hashTree.getRootHash();
1086
1444
  if (!(dataSet.root !== rootHash)) {
1087
- _context8.next = 11;
1445
+ _context7.next = 3;
1088
1446
  break;
1089
1447
  }
1090
- _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(_this8.debugId, " Root hash mismatch: received=").concat(dataSet.root, ", ours=").concat(rootHash, ", syncing data set \"").concat(dataSet.name, "\""));
1091
- mismatchedLeavesData = {};
1092
- if (!(dataSet.leafCount !== 1)) {
1093
- _context8.next = 7;
1094
- break;
1095
- }
1096
- _context8.prev = 2;
1097
- _context8.next = 3;
1098
- return _this8.getHashesFromLocus(dataSet.name);
1099
- case 3:
1100
- _yield$_this8$getHash = _context8.sent;
1101
- hashes = _yield$_this8$getHash.hashes;
1102
- latestDataSetInfo = _yield$_this8$getHash.dataSet;
1103
- receivedHashes = hashes;
1104
- dataSet.hashTree.resize(latestDataSetInfo.leafCount);
1105
- _context8.next = 6;
1448
+ _context7.next = 2;
1449
+ return _this11.performSync(dataSet, rootHash, "Root hash mismatch: received=".concat(dataSet.root, ", ours=").concat(rootHash));
1450
+ case 2:
1451
+ _context7.next = 4;
1106
1452
  break;
1453
+ case 3:
1454
+ _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(_this11.debugId, " \"").concat(dataSet.name, "\" root hash matching: ").concat(rootHash, ", version=").concat(dataSet.version));
1107
1455
  case 4:
1108
- _context8.prev = 4;
1109
- _t3 = _context8["catch"](2);
1110
- if (!(_t3.statusCode === 409)) {
1111
- _context8.next = 5;
1112
- break;
1113
- }
1114
- // this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
1115
- _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this8.debugId, " Got 409 when fetching hashes for data set \"").concat(dataSet.name, "\": ").concat(_t3.message));
1116
- return _context8.abrupt("return");
1117
- case 5:
1118
- throw _t3;
1119
- case 6:
1120
- // identify mismatched leaves
1121
- mismatchedLeaveIndexes = dataSet.hashTree.diffHashes(receivedHashes);
1122
- mismatchedLeaveIndexes.forEach(function (index) {
1123
- mismatchedLeavesData[index] = dataSet.hashTree.getLeafData(index);
1124
- });
1125
- _context8.next = 8;
1126
- break;
1127
- case 7:
1128
- mismatchedLeavesData[0] = dataSet.hashTree.getLeafData(0);
1129
- case 8:
1130
- if (!((0, _keys.default)(mismatchedLeavesData).length > 0)) {
1131
- _context8.next = 10;
1132
- break;
1133
- }
1134
- _context8.next = 9;
1135
- return _this8.sendSyncRequestToLocus(dataSet, mismatchedLeavesData);
1136
- case 9:
1137
- syncResponse = _context8.sent;
1138
- // sync API may return nothing (in that case data will arrive via messages)
1139
- // or it may return a response in the same format as messages
1140
- if (syncResponse) {
1141
- _this8.handleMessage(syncResponse, 'via sync API');
1142
- }
1143
- case 10:
1144
- _context8.next = 12;
1145
- break;
1146
- case 11:
1147
- _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(_this8.debugId, " \"").concat(dataSet.name, "\" root hash matching: ").concat(rootHash, ", version=").concat(dataSet.version));
1148
- case 12:
1149
1456
  case "end":
1150
- return _context8.stop();
1457
+ return _context7.stop();
1151
1458
  }
1152
- }, _callee7, null, [[2, 4]]);
1459
+ }, _callee6);
1153
1460
  })), delay);
1154
1461
  } else {
1155
1462
  _loggerProxy.default.logger.info("HashTreeParser#runSyncAlgorithm --> ".concat(this.debugId, " No delay for \"").concat(dataSet.name, "\" data set, skipping sync timer reset/setup"));
1156
1463
  }
1157
1464
  }
1158
1465
 
1466
+ /**
1467
+ * Resets the heartbeat watchdog timers for the specified data sets. Each data set has its own
1468
+ * watchdog timer that monitors whether heartbeats are being received within the expected interval.
1469
+ * If a heartbeat is not received for a specific data set within heartbeatIntervalMs plus
1470
+ * a backoff-calculated time, the sync algorithm is initiated for that data set
1471
+ *
1472
+ * @param {Array<DataSet>} receivedDataSets - The data sets from the received message for which watchdog timers should be reset
1473
+ * @returns {void}
1474
+ */
1475
+ }, {
1476
+ key: "resetHeartbeatWatchdogs",
1477
+ value: function resetHeartbeatWatchdogs(receivedDataSets) {
1478
+ var _this12 = this;
1479
+ if (!this.heartbeatIntervalMs) {
1480
+ return;
1481
+ }
1482
+ var _iterator9 = _createForOfIteratorHelper(receivedDataSets),
1483
+ _step9;
1484
+ try {
1485
+ var _loop2 = function _loop2() {
1486
+ var receivedDataSet = _step9.value;
1487
+ var dataSet = _this12.dataSets[receivedDataSet.name];
1488
+ if (!(dataSet !== null && dataSet !== void 0 && dataSet.hashTree)) {
1489
+ // eslint-disable-next-line no-continue
1490
+ return 1; // continue
1491
+ }
1492
+ if (dataSet.heartbeatWatchdogTimer) {
1493
+ clearTimeout(dataSet.heartbeatWatchdogTimer);
1494
+ dataSet.heartbeatWatchdogTimer = undefined;
1495
+ }
1496
+ var backoffTime = _this12.getWeightedBackoffTime(dataSet.backoff);
1497
+ var delay = _this12.heartbeatIntervalMs + backoffTime;
1498
+ dataSet.heartbeatWatchdogTimer = setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
1499
+ return _regenerator.default.wrap(function (_context8) {
1500
+ while (1) switch (_context8.prev = _context8.next) {
1501
+ case 0:
1502
+ dataSet.heartbeatWatchdogTimer = undefined;
1503
+ _loggerProxy.default.logger.warn("HashTreeParser#resetHeartbeatWatchdogs --> ".concat(_this12.debugId, " Heartbeat watchdog fired for data set \"").concat(dataSet.name, "\" - no heartbeat received within expected interval, initiating sync"));
1504
+ _context8.next = 1;
1505
+ return _this12.performSync(dataSet, dataSet.hashTree.getRootHash(), "heartbeat watchdog expired");
1506
+ case 1:
1507
+ case "end":
1508
+ return _context8.stop();
1509
+ }
1510
+ }, _callee7);
1511
+ })), delay);
1512
+ };
1513
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1514
+ if (_loop2()) continue;
1515
+ }
1516
+ } catch (err) {
1517
+ _iterator9.e(err);
1518
+ } finally {
1519
+ _iterator9.f();
1520
+ }
1521
+ }
1522
+
1159
1523
  /**
1160
1524
  * Stops all timers for the data sets to prevent any further sync attempts.
1161
1525
  * @returns {void}
@@ -1168,39 +1532,119 @@ var HashTreeParser = /*#__PURE__*/function () {
1168
1532
  clearTimeout(dataSet.timer);
1169
1533
  dataSet.timer = undefined;
1170
1534
  }
1535
+ if (dataSet.heartbeatWatchdogTimer) {
1536
+ clearTimeout(dataSet.heartbeatWatchdogTimer);
1537
+ dataSet.heartbeatWatchdogTimer = undefined;
1538
+ }
1539
+ });
1540
+ }
1541
+
1542
+ /**
1543
+ * Stops the HashTreeParser, preventing it from processing any further messages and clearing all timers.
1544
+ * It also clears all the hash trees, so if the parser is resumed later, it will need to do a sync
1545
+ * to be up-to-date.
1546
+ * @returns {void}
1547
+ */
1548
+ }, {
1549
+ key: "stop",
1550
+ value: function stop() {
1551
+ _loggerProxy.default.logger.info("HashTreeParser#stop --> ".concat(this.debugId, " Stopping HashTreeParser, clearing timers and hash trees"));
1552
+ this.stopAllTimers();
1553
+ (0, _values.default)(this.dataSets).forEach(function (dataSet) {
1554
+ dataSet.hashTree = undefined;
1171
1555
  });
1556
+ this.visibleDataSets = [];
1557
+ this.state = 'stopped';
1558
+ }
1559
+
1560
+ /**
1561
+ * Resumes the HashTreeParser that was previously stopped.
1562
+ * @param {HashTreeMessage} message - The message to resume with, it must contain metadata with visible data sets info
1563
+ * @returns {void}
1564
+ */
1565
+ }, {
1566
+ key: "resume",
1567
+ value: function resume(message) {
1568
+ var _message$locusStateEl3, _metadataObject$data;
1569
+ // check that message contains metadata with visible data sets - this is essential to be able to resume
1570
+ var metadataObject = (_message$locusStateEl3 = message.locusStateElements) === null || _message$locusStateEl3 === void 0 ? void 0 : _message$locusStateEl3.find(function (el) {
1571
+ return (0, _utils.isMetadata)(el);
1572
+ });
1573
+ if (!(metadataObject !== null && metadataObject !== void 0 && (_metadataObject$data = metadataObject.data) !== null && _metadataObject$data !== void 0 && _metadataObject$data.visibleDataSets)) {
1574
+ _loggerProxy.default.logger.warn("HashTreeParser#resume --> ".concat(this.debugId, " Cannot resume HashTreeParser because the message is missing metadata with visible data sets info"));
1575
+ return;
1576
+ }
1577
+ this.setVisibleDataSets(metadataObject.data.visibleDataSets, message.dataSets);
1578
+ this.dataSets = {};
1579
+ var _iterator0 = _createForOfIteratorHelper(message.dataSets),
1580
+ _step0;
1581
+ try {
1582
+ for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
1583
+ var dataSet = _step0.value;
1584
+ var name = dataSet.name,
1585
+ leafCount = dataSet.leafCount;
1586
+ this.dataSets[name] = _objectSpread(_objectSpread({}, dataSet), {}, {
1587
+ hashTree: this.isVisibleDataSet(name) ? new _hashTree.default([], leafCount) : undefined
1588
+ });
1589
+ }
1590
+ } catch (err) {
1591
+ _iterator0.e(err);
1592
+ } finally {
1593
+ _iterator0.f();
1594
+ }
1595
+ _loggerProxy.default.logger.info("HashTreeParser#resume --> ".concat(this.debugId, " Resuming HashTreeParser with data sets: ").concat((0, _keys.default)(this.dataSets).join(', '), ", visible data sets: ").concat(this.visibleDataSets.map(function (ds) {
1596
+ return ds.name;
1597
+ }).join(', ')));
1598
+ this.state = 'active';
1599
+ this.handleMessage(message, 'on resume');
1600
+ }
1601
+ }, {
1602
+ key: "checkForSentinelHttpResponse",
1603
+ value: function checkForSentinelHttpResponse(error, dataSetName) {
1604
+ var _error$body;
1605
+ var isValidDataSetForSentinel = dataSetName === undefined || PossibleSentinelMessageDataSetNames.includes(dataSetName.toLowerCase());
1606
+ if ((error.statusCode === 409 && ((_error$body = error.body) === null || _error$body === void 0 ? void 0 : _error$body.errorCode) === 2403004 || error.statusCode === 404) && isValidDataSetForSentinel) {
1607
+ _loggerProxy.default.logger.info("HashTreeParser#checkForSentinelHttpResponse --> ".concat(this.debugId, " Received ").concat(error.statusCode, " for data set \"").concat(dataSetName, "\", indicating that the meeting has ended"));
1608
+ this.stopAllTimers();
1609
+ throw new MeetingEndedError();
1610
+ }
1172
1611
  }
1173
1612
 
1174
1613
  /**
1175
1614
  * Gets the current hashes from the locus for a specific data set.
1176
1615
  * @param {string} dataSetName
1616
+ * @param {string} currentRootHash
1177
1617
  * @returns {string[]}
1178
1618
  */
1179
1619
  }, {
1180
1620
  key: "getHashesFromLocus",
1181
- value: function getHashesFromLocus(dataSetName) {
1182
- var _this9 = this;
1621
+ value: function getHashesFromLocus(dataSetName, currentRootHash) {
1622
+ var _this13 = this;
1183
1623
  _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(this.debugId, " Requesting hashes for data set \"").concat(dataSetName, "\""));
1184
1624
  var dataSet = this.dataSets[dataSetName];
1185
1625
  var url = "".concat(dataSet.url, "/hashtree");
1186
1626
  return this.webexRequest({
1187
1627
  method: _constants.HTTP_VERBS.GET,
1188
- uri: url
1628
+ uri: url,
1629
+ qs: {
1630
+ rootHash: currentRootHash
1631
+ }
1189
1632
  }).then(function (response) {
1190
1633
  var _response$body, _response$body2;
1191
1634
  var hashes = (_response$body = response.body) === null || _response$body === void 0 ? void 0 : _response$body.hashes;
1192
1635
  var dataSetFromResponse = (_response$body2 = response.body) === null || _response$body2 === void 0 ? void 0 : _response$body2.dataSet;
1193
1636
  if (!hashes || !(0, _isArray.default)(hashes)) {
1194
- _loggerProxy.default.logger.warn("HashTreeParser#getHashesFromLocus --> ".concat(_this9.debugId, " Locus returned invalid hashes, response body="), response.body);
1637
+ _loggerProxy.default.logger.warn("HashTreeParser#getHashesFromLocus --> ".concat(_this13.debugId, " Locus returned invalid hashes, response body="), response.body);
1195
1638
  throw new Error("Locus returned invalid hashes: ".concat(hashes));
1196
1639
  }
1197
- _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this9.debugId, " Received hashes for data set \"").concat(dataSetName, "\": ").concat((0, _stringify.default)(hashes)));
1640
+ _loggerProxy.default.logger.info("HashTreeParser#getHashesFromLocus --> ".concat(_this13.debugId, " Received hashes for data set \"").concat(dataSetName, "\": ").concat((0, _stringify.default)(hashes)));
1198
1641
  return {
1199
1642
  hashes: hashes,
1200
1643
  dataSet: dataSetFromResponse
1201
1644
  };
1202
1645
  }).catch(function (error) {
1203
- _loggerProxy.default.logger.error("HashTreeParser#getHashesFromLocus --> ".concat(_this9.debugId, " Error ").concat(error.statusCode, " fetching hashes for data set \"").concat(dataSetName, "\":"), error);
1646
+ _loggerProxy.default.logger.error("HashTreeParser#getHashesFromLocus --> ".concat(_this13.debugId, " Error ").concat(error.statusCode, " fetching hashes for data set \"").concat(dataSetName, "\":"), error);
1647
+ _this13.checkForSentinelHttpResponse(error, dataSet.name);
1204
1648
  throw error;
1205
1649
  });
1206
1650
  }
@@ -1215,7 +1659,7 @@ var HashTreeParser = /*#__PURE__*/function () {
1215
1659
  }, {
1216
1660
  key: "sendSyncRequestToLocus",
1217
1661
  value: function sendSyncRequestToLocus(dataSet, mismatchedLeavesData) {
1218
- var _this0 = this;
1662
+ var _this14 = this;
1219
1663
  _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(this.debugId, " Sending sync request for data set \"").concat(dataSet.name, "\""));
1220
1664
  var url = "".concat(dataSet.url, "/sync");
1221
1665
  var body = {
@@ -1228,19 +1672,24 @@ var HashTreeParser = /*#__PURE__*/function () {
1228
1672
  elementIds: mismatchedLeavesData[index]
1229
1673
  });
1230
1674
  });
1675
+ var ourCurrentRootHash = dataSet.hashTree ? dataSet.hashTree.getRootHash() : _constants2.EMPTY_HASH;
1231
1676
  return this.webexRequest({
1232
1677
  method: _constants.HTTP_VERBS.POST,
1233
1678
  uri: url,
1679
+ qs: {
1680
+ rootHash: ourCurrentRootHash
1681
+ },
1234
1682
  body: body
1235
1683
  }).then(function (resp) {
1236
- _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this0.debugId, " Sync request succeeded for \"").concat(dataSet.name, "\""));
1684
+ _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this14.debugId, " Sync request succeeded for \"").concat(dataSet.name, "\""));
1237
1685
  if (!resp.body || (0, _lodash.isEmpty)(resp.body)) {
1238
- _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this0.debugId, " Got ").concat(resp.statusCode, " with empty body for sync request for data set \"").concat(dataSet.name, "\", data should arrive via messages"));
1686
+ _loggerProxy.default.logger.info("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this14.debugId, " Got ").concat(resp.statusCode, " with empty body for sync request for data set \"").concat(dataSet.name, "\", data should arrive via messages"));
1239
1687
  return null;
1240
1688
  }
1241
1689
  return resp.body;
1242
1690
  }).catch(function (error) {
1243
- _loggerProxy.default.logger.error("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this0.debugId, " Error ").concat(error.statusCode, " sending sync request for data set \"").concat(dataSet.name, "\":"), error);
1691
+ _loggerProxy.default.logger.error("HashTreeParser#sendSyncRequestToLocus --> ".concat(_this14.debugId, " Error ").concat(error.statusCode, " sending sync request for data set \"").concat(dataSet.name, "\":"), error);
1692
+ _this14.checkForSentinelHttpResponse(error, dataSet.name);
1244
1693
  throw error;
1245
1694
  });
1246
1695
  }