@webex/plugin-meetings 3.11.0 → 3.12.0-next.2

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