@webex/plugin-meetings 3.11.0 → 3.12.0

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 +5 -1
  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 +709 -380
  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 +217 -79
  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 +1082 -861
  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 +100 -45
  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 +3 -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 +99 -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 +21 -2
  88. package/dist/types/locus-info/types.d.ts +1 -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 +38 -6
  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 +260 -90
  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 +3 -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 +627 -249
  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 +231 -61
  127. package/src/locus-info/selfUtils.ts +1 -0
  128. package/src/locus-info/types.ts +1 -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 +205 -44
  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 +135 -41
  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 +162 -5
  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 +1869 -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 +383 -46
  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 +716 -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 +652 -31
  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 +348 -36
  170. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -1,10 +1,14 @@
1
1
  import HashTreeParser, {
2
2
  LocusInfoUpdateType,
3
+ MeetingEndedError,
3
4
  } from '@webex/plugin-meetings/src/hashTree/hashTreeParser';
4
5
  import HashTree from '@webex/plugin-meetings/src/hashTree/hashTree';
5
6
  import {expect} from '@webex/test-helper-chai';
6
7
  import sinon from 'sinon';
7
8
  import {assert} from '@webex/test-helper-chai';
9
+ import {EMPTY_HASH} from '@webex/plugin-meetings/src/hashTree/constants';
10
+
11
+ const visibleDataSetsUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/visibleDataSets';
8
12
 
9
13
  const exampleInitialLocus = {
10
14
  dataSets: [
@@ -46,6 +50,7 @@ const exampleInitialLocus = {
46
50
  },
47
51
  dataSetNames: ['main'],
48
52
  },
53
+ links: {resources: {visibleDataSets: {url: visibleDataSetsUrl}}},
49
54
  participants: [
50
55
  {
51
56
  url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/11941033',
@@ -62,7 +67,6 @@ const exampleInitialLocus = {
62
67
  ],
63
68
  self: {
64
69
  url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/11941033',
65
- visibleDataSets: ['main', 'self', 'atd-unmuted'],
66
70
  person: {},
67
71
  htMeta: {
68
72
  elementId: {
@@ -76,6 +80,28 @@ const exampleInitialLocus = {
76
80
  },
77
81
  };
78
82
 
83
+ const exampleMetadata = {
84
+ htMeta: {
85
+ elementId: {
86
+ type: 'metadata',
87
+ id: 5,
88
+ version: 50,
89
+ },
90
+ dataSetNames: ['self'],
91
+ },
92
+ visibleDataSets: [
93
+ {name: 'main', url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main'},
94
+ {
95
+ name: 'self',
96
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
97
+ },
98
+ {
99
+ name: 'atd-unmuted',
100
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
101
+ },
102
+ ],
103
+ };
104
+
79
105
  function createDataSet(name: string, leafCount: number, version = 1) {
80
106
  return {
81
107
  url: `https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/${name}`,
@@ -119,7 +145,6 @@ function mockSyncRequest(webexRequest: sinon.SinonStub, datasetUrl: string, resp
119
145
  }
120
146
 
121
147
  describe('HashTreeParser', () => {
122
- const visibleDataSetsUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/visibleDataSets';
123
148
  const locusUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f';
124
149
 
125
150
  let clock;
@@ -139,12 +164,18 @@ describe('HashTreeParser', () => {
139
164
  });
140
165
 
141
166
  // Helper to create a HashTreeParser instance with common defaults
142
- function createHashTreeParser(initialLocus: any = exampleInitialLocus) {
167
+ function createHashTreeParser(
168
+ initialLocus: any = exampleInitialLocus,
169
+ metadata: any = exampleMetadata,
170
+ excludedDataSets?: string[]
171
+ ) {
143
172
  return new HashTreeParser({
144
173
  initialLocus,
174
+ metadata,
145
175
  webexRequest,
146
176
  locusInfoUpdateCallback: callback,
147
177
  debugId: 'test',
178
+ excludedDataSets,
148
179
  });
149
180
  }
150
181
 
@@ -197,9 +228,50 @@ describe('HashTreeParser', () => {
197
228
  body: response,
198
229
  });
199
230
  }
231
+
232
+ async function checkAsyncDatasetInitialization(
233
+ parser: HashTreeParser,
234
+ newDataSet: {name: string; leafCount: number; url: string}
235
+ ) {
236
+ // immediately we don't have the dataset yet, so it should not be in visibleDataSets
237
+ // and no hash tree should exist yet
238
+ expect(parser.visibleDataSets.some((vds) => vds.name === newDataSet.name)).to.be.false;
239
+ assert.isUndefined(parser.dataSets[newDataSet.name]);
240
+
241
+ // Wait for the async initialization to complete (queued as microtask)
242
+ await clock.tickAsync(0);
243
+
244
+ // The visibleDataSets is updated from the metadata object data
245
+ expect(parser.visibleDataSets.some((vds) => vds.name === newDataSet.name)).to.be.true;
246
+
247
+ // Verify that a hash tree was created for newDataSet
248
+ assert.exists(parser.dataSets[newDataSet.name].hashTree);
249
+ assert.equal(parser.dataSets[newDataSet.name].hashTree.numLeaves, newDataSet.leafCount);
250
+
251
+ // Verify getAllDataSetsMetadata was called for async initialization
252
+ assert.calledWith(
253
+ webexRequest,
254
+ sinon.match({
255
+ method: 'GET',
256
+ uri: visibleDataSetsUrl,
257
+ })
258
+ );
259
+
260
+ // Verify sync request was sent for the new dataset
261
+ assert.calledWith(
262
+ webexRequest,
263
+ sinon.match({
264
+ method: 'POST',
265
+ uri: `${newDataSet.url}/sync`,
266
+ })
267
+ );
268
+ }
200
269
  it('should correctly initialize trees from initialLocus data', () => {
201
270
  const parser = createHashTreeParser();
202
271
 
272
+ // verify that visibleDataSetsUrl is read out from inside locus
273
+ expect(parser.visibleDataSetsUrl).to.equal(visibleDataSetsUrl);
274
+
203
275
  // Check that the correct number of trees are created
204
276
  expect(Object.keys(parser.dataSets).length).to.equal(3);
205
277
 
@@ -215,7 +287,11 @@ describe('HashTreeParser', () => {
215
287
  const selfTree = parser.dataSets.self.hashTree;
216
288
  expect(selfTree).to.be.instanceOf(HashTree);
217
289
  const expectedSelfLeaves = new Array(1).fill(null).map(() => ({}));
218
- expectedSelfLeaves[4 % 1] = {self: {4: {type: 'self', id: 4, version: 100}}};
290
+ // Both self (id=4) and metadata (id=5) map to the same leaf (4%1=0, 5%1=0)
291
+ expectedSelfLeaves[0] = {
292
+ self: {4: {type: 'self', id: 4, version: 100}},
293
+ metadata: {5: {type: 'metadata', id: 5, version: 50}},
294
+ };
219
295
  expect(selfTree.leaves).to.deep.equal(expectedSelfLeaves);
220
296
  expect(selfTree.numLeaves).to.equal(1);
221
297
 
@@ -247,7 +323,7 @@ describe('HashTreeParser', () => {
247
323
  name: 'empty-set',
248
324
  });
249
325
 
250
- const parser = createHashTreeParser(modifiedLocus);
326
+ const parser = createHashTreeParser(modifiedLocus, exampleMetadata);
251
327
 
252
328
  expect(Object.keys(parser.dataSets).length).to.equal(4); // main, self, atd-unmuted (now empty), empty-set
253
329
 
@@ -260,7 +336,10 @@ describe('HashTreeParser', () => {
260
336
 
261
337
  const selfTree = parser.dataSets.self.hashTree;
262
338
  const expectedSelfLeaves = new Array(1).fill(null).map(() => ({}));
263
- expectedSelfLeaves[4 % 1] = {self: {4: {type: 'self', id: 4, version: 100}}};
339
+ expectedSelfLeaves[4 % 1] = {
340
+ self: {4: {type: 'self', id: 4, version: 100}},
341
+ metadata: {5: exampleMetadata.htMeta.elementId},
342
+ };
264
343
  expect(selfTree.leaves).to.deep.equal(expectedSelfLeaves);
265
344
  expect(selfTree.numLeaves).to.equal(1);
266
345
 
@@ -277,31 +356,100 @@ describe('HashTreeParser', () => {
277
356
  expect(emptySet.hashTree).to.be.undefined;
278
357
  });
279
358
 
359
+ it('should exclude datasets listed in excludedDataSets during initialization', () => {
360
+ const parser = createHashTreeParser(exampleInitialLocus, exampleMetadata, ['atd-unmuted']);
361
+
362
+ // 'atd-unmuted' should be excluded from visibleDataSets
363
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'atd-unmuted')).to.be.false;
364
+
365
+ // 'main' and 'self' should still be visible
366
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'main')).to.be.true;
367
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'self')).to.be.true;
368
+
369
+ // 'atd-unmuted' dataset entry should exist but without a hash tree (because it's not visible)
370
+ expect(parser.dataSets['atd-unmuted']).to.exist;
371
+ expect(parser.dataSets['atd-unmuted'].hashTree).to.be.undefined;
372
+
373
+ // 'main' and 'self' should have hash trees
374
+ expect(parser.dataSets.main.hashTree).to.be.instanceOf(HashTree);
375
+ expect(parser.dataSets.self.hashTree).to.be.instanceOf(HashTree);
376
+ });
377
+
378
+ it('should exclude datasets listed in excludedDataSets when adding new visible datasets', async () => {
379
+ // Create parser without 'atd-unmuted' in initial metadata visibleDataSets
380
+ const metadataWithoutAtdUnmuted = {
381
+ ...exampleMetadata,
382
+ visibleDataSets: exampleMetadata.visibleDataSets.filter((vds) => vds.name !== 'atd-unmuted'),
383
+ };
384
+ const parser = createHashTreeParser(exampleInitialLocus, metadataWithoutAtdUnmuted, [
385
+ 'atd-unmuted',
386
+ ]);
387
+
388
+ // 'atd-unmuted' should not be in visibleDataSets initially
389
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'atd-unmuted')).to.be.false;
390
+
391
+ // Now simulate initializeDataSets which calls addToVisibleDataSetsList
392
+ const atdUnmutedDataSet = createDataSet('atd-unmuted', 16, 3000);
393
+
394
+ mockGetAllDataSetsMetadata(webexRequest, visibleDataSetsUrl, [
395
+ createDataSet('main', 16, 1000),
396
+ createDataSet('self', 1, 2000),
397
+ atdUnmutedDataSet,
398
+ ]);
399
+
400
+ mockSyncRequest(
401
+ webexRequest,
402
+ 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted'
403
+ );
404
+
405
+ const message = {
406
+ dataSets: [createDataSet('main', 16, 1000)],
407
+ visibleDataSetsUrl,
408
+ locusUrl,
409
+ };
410
+ await parser.initializeFromMessage(message);
411
+
412
+ // 'atd-unmuted' should still not be in visibleDataSets because it is excluded
413
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'atd-unmuted')).to.be.false;
414
+ // but 'main' and 'self' should be there
415
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'main')).to.be.true;
416
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'self')).to.be.true;
417
+ });
418
+
280
419
  // helper method, needed because both initializeFromMessage and initializeFromGetLociResponse
281
420
  // do almost exactly the same thing
282
421
  const testInitializationOfDatasetsAndHashTrees = async (testCallback) => {
283
422
  // Create a parser with minimal initial data
284
423
  const minimalInitialLocus = {
285
424
  dataSets: [],
286
- locus: {
287
- self: {
288
- visibleDataSets: ['main', 'self'],
425
+ locus: null,
426
+ };
427
+
428
+ const minimalMetadata = {
429
+ htMeta: {
430
+ elementId: {
431
+ type: 'metadata',
432
+ id: 5,
433
+ version: 50,
289
434
  },
435
+ dataSetNames: ['self'],
290
436
  },
437
+ visibleDataSets: [
438
+ {name: 'main', url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main'},
439
+ {
440
+ name: 'self',
441
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
442
+ },
443
+ ],
291
444
  };
292
445
 
293
- const hashTreeParser = createHashTreeParser(minimalInitialLocus);
446
+ const hashTreeParser = createHashTreeParser(minimalInitialLocus, minimalMetadata);
294
447
 
295
448
  // Setup the datasets that will be returned from getAllDataSetsMetadata
296
449
  const mainDataSet = createDataSet('main', 16, 1100);
297
450
  const selfDataSet = createDataSet('self', 1, 2100);
298
- const invisibleDataSet = createDataSet('invisible', 4, 4000);
299
451
 
300
- mockGetAllDataSetsMetadata(webexRequest, visibleDataSetsUrl, [
301
- mainDataSet,
302
- selfDataSet,
303
- invisibleDataSet,
304
- ]);
452
+ mockGetAllDataSetsMetadata(webexRequest, visibleDataSetsUrl, [mainDataSet, selfDataSet]);
305
453
 
306
454
  // Mock sync requests for visible datasets with some updated objects
307
455
  const mainSyncResponse = {
@@ -357,15 +505,16 @@ describe('HashTreeParser', () => {
357
505
  })
358
506
  );
359
507
 
360
- // Verify all datasets are added to dataSets
508
+ // verify that visibleDataSetsUrl is set on the parser
509
+ expect(hashTreeParser.visibleDataSetsUrl).to.equal(visibleDataSetsUrl);
510
+
511
+ // Verify all datasets returned from visibleDataSetsUrl are added to dataSets
361
512
  expect(hashTreeParser.dataSets.main).to.exist;
362
513
  expect(hashTreeParser.dataSets.self).to.exist;
363
- expect(hashTreeParser.dataSets.invisible).to.exist;
364
514
 
365
515
  // Verify hash trees are created only for visible datasets
366
516
  expect(hashTreeParser.dataSets.main.hashTree).to.be.instanceOf(HashTree);
367
517
  expect(hashTreeParser.dataSets.self.hashTree).to.be.instanceOf(HashTree);
368
- expect(hashTreeParser.dataSets.invisible.hashTree).to.be.undefined;
369
518
 
370
519
  // Verify hash trees have correct leaf counts
371
520
  expect(hashTreeParser.dataSets.main.hashTree.numLeaves).to.equal(16);
@@ -403,15 +552,6 @@ describe('HashTreeParser', () => {
403
552
  })
404
553
  );
405
554
 
406
- // Verify sync request was NOT sent for invisible dataset
407
- assert.neverCalledWith(
408
- webexRequest,
409
- sinon.match({
410
- method: 'POST',
411
- uri: `${invisibleDataSet.url}/sync`,
412
- })
413
- );
414
-
415
555
  // Verify callback was called with OBJECTS_UPDATED and correct updatedObjects list
416
556
  assert.calledWith(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
417
557
  updatedObjects: [
@@ -443,8 +583,6 @@ describe('HashTreeParser', () => {
443
583
  // verify that sync timers are set for visible datasets
444
584
  expect(hashTreeParser.dataSets.main.timer).to.not.be.undefined;
445
585
  expect(hashTreeParser.dataSets.self.timer).to.not.be.undefined;
446
- // and not for invisible dataset
447
- expect(hashTreeParser.dataSets.invisible.timer).to.be.undefined;
448
586
  };
449
587
 
450
588
  describe('#initializeFromMessage', () => {
@@ -457,11 +595,91 @@ describe('HashTreeParser', () => {
457
595
  });
458
596
  });
459
597
  });
598
+
599
+ it('handles sync response that has locusStateElements undefined', async () => {
600
+ const minimalInitialLocus = {
601
+ dataSets: [],
602
+ locus: null,
603
+ };
604
+
605
+ const parser = createHashTreeParser(minimalInitialLocus, null);
606
+
607
+ const mainDataSet = createDataSet('main', 16, 1100);
608
+
609
+ // Mock getAllVisibleDataSetsFromLocus to return the main dataset
610
+ mockGetAllDataSetsMetadata(webexRequest, visibleDataSetsUrl, [mainDataSet]);
611
+
612
+ // Mock the sync response to have locusStateElements: undefined
613
+ // This is what sendInitializationSyncRequestToLocus will receive and pass to parseMessage
614
+ mockSyncRequest(webexRequest, mainDataSet.url, {
615
+ dataSets: [mainDataSet],
616
+ visibleDataSetsUrl,
617
+ locusUrl,
618
+ locusStateElements: undefined,
619
+ });
620
+
621
+ // Trigger sendInitializationSyncRequestToLocus via initializeFromMessage
622
+ await parser.initializeFromMessage({
623
+ dataSets: [],
624
+ visibleDataSetsUrl,
625
+ locusUrl,
626
+ });
627
+
628
+ // Verify the hash tree was created for main dataset
629
+ expect(parser.dataSets.main.hashTree).to.be.instanceOf(HashTree);
630
+
631
+ // updateItems should NOT have been called because locusStateElements is undefined
632
+ const mainUpdateItemsStub = sinon.spy(parser.dataSets.main.hashTree, 'updateItems');
633
+ assert.notCalled(mainUpdateItemsStub);
634
+
635
+ // callback should not be called, because there are no updates
636
+ assert.notCalled(callback);
637
+ });
638
+
639
+ [404, 409].forEach((errorCode) => {
640
+ it(`emits MeetingEndedError if getting visible datasets returns ${errorCode}`, async () => {
641
+ const minimalInitialLocus = {
642
+ dataSets: [],
643
+ locus: null,
644
+ };
645
+
646
+ const parser = createHashTreeParser(minimalInitialLocus, null);
647
+
648
+ // Mock getAllVisibleDataSetsFromLocus to reject with the error code
649
+ const error: any = new Error(`Request failed with status ${errorCode}`);
650
+ error.statusCode = errorCode;
651
+ if (errorCode === 409) {
652
+ error.body = {errorCode: 2403004};
653
+ }
654
+ webexRequest
655
+ .withArgs(
656
+ sinon.match({
657
+ method: 'GET',
658
+ uri: visibleDataSetsUrl,
659
+ })
660
+ )
661
+ .rejects(error);
662
+
663
+ // initializeFromMessage should throw MeetingEndedError
664
+ let thrownError;
665
+ try {
666
+ await parser.initializeFromMessage({
667
+ dataSets: [],
668
+ visibleDataSetsUrl,
669
+ locusUrl,
670
+ });
671
+ } catch (e) {
672
+ thrownError = e;
673
+ }
674
+
675
+ expect(thrownError).to.be.instanceOf(MeetingEndedError);
676
+ });
677
+ });
460
678
  });
461
679
 
462
680
  describe('#initializeFromGetLociResponse', () => {
463
681
  it('does nothing if url for visibleDataSets is missing from locus', async () => {
464
- const parser = createHashTreeParser({dataSets: [], locus: {}});
682
+ const parser = createHashTreeParser({dataSets: [], locus: {}}, null);
465
683
 
466
684
  await parser.initializeFromGetLociResponse({participants: []});
467
685
 
@@ -488,12 +706,9 @@ describe('HashTreeParser', () => {
488
706
  it('updates hash trees based on provided new locus', () => {
489
707
  const parser = createHashTreeParser();
490
708
 
491
- const mainPutItemsSpy = sinon
492
- .spy(parser.dataSets.main.hashTree, 'putItems');
493
- const selfPutItemsSpy = sinon
494
- .spy(parser.dataSets.self.hashTree, 'putItems');
495
- const atdUnmutedPutItemsSpy = sinon
496
- .spy(parser.dataSets['atd-unmuted'].hashTree, 'putItems');
709
+ const mainPutItemsSpy = sinon.spy(parser.dataSets.main.hashTree, 'putItems');
710
+ const selfPutItemsSpy = sinon.spy(parser.dataSets.self.hashTree, 'putItems');
711
+ const atdUnmutedPutItemsSpy = sinon.spy(parser.dataSets['atd-unmuted'].hashTree, 'putItems');
497
712
 
498
713
  // Create a locus update with new htMeta information for some things
499
714
  const locusUpdate = {
@@ -540,7 +755,6 @@ describe('HashTreeParser', () => {
540
755
  ],
541
756
  self: {
542
757
  url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/11941033',
543
- visibleDataSets: ['main', 'self', 'atd-unmuted'],
544
758
  person: {},
545
759
  htMeta: {
546
760
  elementId: {
@@ -711,73 +925,339 @@ describe('HashTreeParser', () => {
711
925
  ],
712
926
  });
713
927
  });
714
- });
715
928
 
716
- describe('#handleMessage', () => {
717
- it('handles root hash heartbeat message correctly', async () => {
929
+ it('handles metadata updates with new version', async () => {
718
930
  const parser = createHashTreeParser();
719
931
 
720
- // Step 1: Send a normal message with locusStateElements to start the sync timer
721
- const normalMessage = {
722
- dataSets: [
723
- {
724
- ...createDataSet('main', 16, 1100),
725
- root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1', // different from our hash
932
+ const selfPutItemSpy = sinon.spy(parser.dataSets.self.hashTree, 'putItem');
933
+
934
+ // Create a locus update with updated metadata
935
+ const locusUpdate = {
936
+ dataSets: [createDataSet('self', 1, 2100), createDataSet('attendees', 8, 4000)],
937
+ locus: {
938
+ links: {resources: {visibleDataSets: {url: visibleDataSetsUrl}}},
939
+ participants: [
940
+ {
941
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/15',
942
+ person: {},
943
+ htMeta: {
944
+ elementId: {
945
+ type: 'participant',
946
+ id: 15, // new participant
947
+ version: 999,
948
+ },
949
+ dataSetNames: ['attendees'],
950
+ },
951
+ },
952
+ ],
953
+ },
954
+ metadata: {
955
+ htMeta: {
956
+ elementId: {
957
+ type: 'metadata',
958
+ id: 5,
959
+ version: 51, // incremented version
960
+ },
961
+ dataSetNames: ['self'],
726
962
  },
727
- ],
963
+ // new visibleDataSets: atd-unmuted removed, "attendees" and "new-dataset" added
964
+ visibleDataSets: [
965
+ {
966
+ name: 'main',
967
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
968
+ },
969
+ {
970
+ name: 'self',
971
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
972
+ },
973
+ {
974
+ name: 'new-dataset', // this one is not in dataSets, so will require async initialization
975
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/new-dataset',
976
+ },
977
+ {
978
+ name: 'attendees', // this one is in dataSets, so should be processed immediately
979
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
980
+ },
981
+ ],
982
+ },
983
+ };
984
+
985
+ // Mock the async initialization of the new dataset
986
+ const newDataSet = createDataSet('new-dataset', 4, 5000);
987
+ mockGetAllDataSetsMetadata(webexRequest, visibleDataSetsUrl, [newDataSet]);
988
+ mockSyncRequest(webexRequest, newDataSet.url, {
989
+ dataSets: [newDataSet],
728
990
  visibleDataSetsUrl,
729
991
  locusUrl,
730
- locusStateElements: [
992
+ locusStateElements: [],
993
+ });
994
+
995
+ // Call handleLocusUpdate
996
+ parser.handleLocusUpdate(locusUpdate);
997
+
998
+ // Verify putItem was called on self hash tree with metadata
999
+ assert.calledOnceWithExactly(selfPutItemSpy, {type: 'metadata', id: 5, version: 51});
1000
+
1001
+ // Verify callback was called with metadata object and removed dataset objects
1002
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
1003
+ updatedObjects: [
1004
+ // updated metadata object:
731
1005
  {
732
1006
  htMeta: {
733
1007
  elementId: {
734
- type: 'locus' as const,
735
- id: 0,
736
- version: 201,
1008
+ type: 'metadata',
1009
+ id: 5,
1010
+ version: 51,
1011
+ },
1012
+ dataSetNames: ['self'],
1013
+ },
1014
+ data: {
1015
+ htMeta: {
1016
+ elementId: {
1017
+ type: 'metadata',
1018
+ id: 5,
1019
+ version: 51,
1020
+ },
1021
+ dataSetNames: ['self'],
1022
+ },
1023
+ visibleDataSets: [
1024
+ {
1025
+ name: 'main',
1026
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
1027
+ },
1028
+ {
1029
+ name: 'self',
1030
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
1031
+ },
1032
+ {
1033
+ name: 'new-dataset',
1034
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/new-dataset',
1035
+ },
1036
+ {
1037
+ name: 'attendees',
1038
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
1039
+ },
1040
+ ],
1041
+ },
1042
+ },
1043
+ // removed participant from a removed dataset 'atd-unmuted':
1044
+ {
1045
+ htMeta: {
1046
+ elementId: {
1047
+ type: 'participant',
1048
+ id: 14,
1049
+ version: 300,
1050
+ },
1051
+ dataSetNames: ['atd-unmuted'],
1052
+ },
1053
+ data: null,
1054
+ },
1055
+ // new participant from a new data set 'attendees':
1056
+ {
1057
+ htMeta: {
1058
+ elementId: {
1059
+ type: 'participant',
1060
+ id: 15,
1061
+ version: 999,
1062
+ },
1063
+ dataSetNames: ['attendees'],
1064
+ },
1065
+ data: {
1066
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/15',
1067
+ person: {},
1068
+ htMeta: {
1069
+ elementId: {
1070
+ type: 'participant',
1071
+ id: 15,
1072
+ version: 999,
1073
+ },
1074
+ dataSetNames: ['attendees'],
737
1075
  },
738
- dataSetNames: ['main'],
739
1076
  },
740
- data: {someData: 'value'},
741
1077
  },
742
1078
  ],
743
- };
744
-
745
- await parser.handleMessage(normalMessage, 'initial message');
1079
+ });
746
1080
 
747
- // Verify the timer was set (the sync algorithm should have started)
748
- expect(parser.dataSets.main.timer).to.not.be.undefined;
749
- const firstTimerDelay = parser.dataSets.main.idleMs; // 1000ms base + random backoff
1081
+ // verify also that an async initialization was done for
1082
+ await checkAsyncDatasetInitialization(parser, newDataSet);
1083
+ });
750
1084
 
751
- // Step 2: Simulate half of the time passing
752
- clock.tick(500);
1085
+ it('handles metadata updates with same version (no callback)', () => {
1086
+ const parser = createHashTreeParser();
753
1087
 
754
- // Verify no webex requests have been made yet
755
- assert.notCalled(webexRequest);
1088
+ const selfPutItemSpy = sinon.spy(parser.dataSets.self.hashTree, 'putItem');
756
1089
 
757
- // Step 3: Send a heartbeat message (no locusStateElements) with mismatched root hash
758
- const heartbeatMessage = createHeartbeatMessage(
759
- 'main',
760
- 16,
761
- 1101,
762
- 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' // still different from our hash
763
- );
1090
+ // Create a locus update with metadata that has the same version and same visibleDataSets
1091
+ const locusUpdate = {
1092
+ dataSets: [createDataSet('self', 1, 2100)],
1093
+ locus: {},
1094
+ metadata: {
1095
+ htMeta: {
1096
+ elementId: {
1097
+ type: 'metadata',
1098
+ id: 5,
1099
+ version: 50, // same version as initial
1100
+ },
1101
+ dataSetNames: ['self'],
1102
+ },
1103
+ visibleDataSets: [
1104
+ {
1105
+ name: 'main',
1106
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
1107
+ },
1108
+ {
1109
+ name: 'self',
1110
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
1111
+ },
1112
+ {
1113
+ name: 'atd-unmuted',
1114
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
1115
+ },
1116
+ ],
1117
+ },
1118
+ };
764
1119
 
765
- await parser.handleMessage(heartbeatMessage, 'heartbeat message');
1120
+ // Call handleLocusUpdate
1121
+ parser.handleLocusUpdate(locusUpdate);
766
1122
 
767
- // Verify the timer was restarted (should still exist)
768
- expect(parser.dataSets.main.timer).to.not.be.undefined;
1123
+ // Verify putItem was called on self hash tree
1124
+ assert.calledOnceWithExactly(selfPutItemSpy, {type: 'metadata', id: 5, version: 50});
769
1125
 
770
- // Step 4: Simulate more time passing (another 500ms) - total 1000ms from start
771
- // This should NOT trigger the sync yet because the timer was restarted
772
- clock.tick(500);
1126
+ // Verify callback was NOT called because version didn't change
1127
+ assert.notCalled(callback);
1128
+ });
773
1129
 
774
- // Verify still no hash requests or sync requests were sent
775
- assert.notCalled(webexRequest);
1130
+ it('handles updates with no dataSets and metadata fields gracefully', () => {
1131
+ const parser = createHashTreeParser();
776
1132
 
777
- // Step 5: Mock the responses for the sync algorithm
778
- const mainDataSetUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main';
1133
+ const mainPutItemsSpy = sinon.spy(parser.dataSets.main.hashTree, 'putItems');
1134
+ const selfPutItemsSpy = sinon.spy(parser.dataSets.self.hashTree, 'putItems');
1135
+ const atdUnmutedPutItemsSpy = sinon.spy(parser.dataSets['atd-unmuted'].hashTree, 'putItems');
779
1136
 
780
- // Mock getHashesFromLocus response
1137
+ // Create a locus update with no dataSets and no metadata
1138
+ const locusUpdate = {
1139
+ locus: {
1140
+ htMeta: {
1141
+ elementId: {
1142
+ type: 'locus',
1143
+ id: 0,
1144
+ version: 201,
1145
+ },
1146
+ dataSetNames: ['main'],
1147
+ },
1148
+ someData: 'value',
1149
+ },
1150
+ };
1151
+
1152
+ // Call handleLocusUpdate - should not throw
1153
+ parser.handleLocusUpdate(locusUpdate);
1154
+
1155
+ // Verify putItems was still called for the dataset referenced in locus
1156
+ assert.calledOnceWithExactly(mainPutItemsSpy, [{type: 'locus', id: 0, version: 201}]);
1157
+
1158
+ // Verify putItems was not called on other hash trees
1159
+ assert.notCalled(selfPutItemsSpy);
1160
+ assert.notCalled(atdUnmutedPutItemsSpy);
1161
+
1162
+ // Verify callback was called with the updated object
1163
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
1164
+ updatedObjects: [
1165
+ {
1166
+ htMeta: {
1167
+ elementId: {
1168
+ type: 'locus',
1169
+ id: 0,
1170
+ version: 201,
1171
+ },
1172
+ dataSetNames: ['main'],
1173
+ },
1174
+ data: {
1175
+ someData: 'value',
1176
+ htMeta: {
1177
+ elementId: {
1178
+ type: 'locus',
1179
+ id: 0,
1180
+ version: 201,
1181
+ },
1182
+ dataSetNames: ['main'],
1183
+ },
1184
+ },
1185
+ },
1186
+ ],
1187
+ });
1188
+
1189
+ // Verify that dataset versions were NOT updated (no dataSets in the update)
1190
+ expect(parser.dataSets.main.version).to.equal(1000);
1191
+ expect(parser.dataSets.self.version).to.equal(2000);
1192
+ expect(parser.dataSets['atd-unmuted'].version).to.equal(3000);
1193
+ });
1194
+ });
1195
+
1196
+ describe('#handleMessage', () => {
1197
+ it('handles root hash heartbeat message correctly', async () => {
1198
+ const parser = createHashTreeParser();
1199
+
1200
+ // Step 1: Send a normal message with locusStateElements to start the sync timer
1201
+ const normalMessage = {
1202
+ dataSets: [
1203
+ {
1204
+ ...createDataSet('main', 16, 1100),
1205
+ root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1', // different from our hash
1206
+ },
1207
+ ],
1208
+ visibleDataSetsUrl,
1209
+ locusUrl,
1210
+ locusStateElements: [
1211
+ {
1212
+ htMeta: {
1213
+ elementId: {
1214
+ type: 'locus' as const,
1215
+ id: 0,
1216
+ version: 201,
1217
+ },
1218
+ dataSetNames: ['main'],
1219
+ },
1220
+ data: {someData: 'value'},
1221
+ },
1222
+ ],
1223
+ };
1224
+
1225
+ parser.handleMessage(normalMessage, 'initial message');
1226
+
1227
+ // Verify the timer was set (the sync algorithm should have started)
1228
+ expect(parser.dataSets.main.timer).to.not.be.undefined;
1229
+ const firstTimerDelay = parser.dataSets.main.idleMs; // 1000ms base + random backoff
1230
+
1231
+ // Step 2: Simulate half of the time passing
1232
+ clock.tick(500);
1233
+
1234
+ // Verify no webex requests have been made yet
1235
+ assert.notCalled(webexRequest);
1236
+
1237
+ // Step 3: Send a heartbeat message (no locusStateElements) with mismatched root hash
1238
+ const heartbeatMessage = createHeartbeatMessage(
1239
+ 'main',
1240
+ 16,
1241
+ 1101,
1242
+ 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' // still different from our hash
1243
+ );
1244
+
1245
+ parser.handleMessage(heartbeatMessage, 'heartbeat message');
1246
+
1247
+ // Verify the timer was restarted (should still exist)
1248
+ expect(parser.dataSets.main.timer).to.not.be.undefined;
1249
+
1250
+ // Step 4: Simulate more time passing (another 500ms) - total 1000ms from start
1251
+ // This should NOT trigger the sync yet because the timer was restarted
1252
+ clock.tick(500);
1253
+
1254
+ // Verify still no hash requests or sync requests were sent
1255
+ assert.notCalled(webexRequest);
1256
+
1257
+ // Step 5: Mock the responses for the sync algorithm
1258
+ const mainDataSetUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main';
1259
+
1260
+ // Mock getHashesFromLocus response
781
1261
  mockGetHashesFromLocusResponse(
782
1262
  mainDataSetUrl,
783
1263
  new Array(16).fill('00000000000000000000000000000000'),
@@ -889,7 +1369,7 @@ describe('HashTreeParser', () => {
889
1369
  ],
890
1370
  };
891
1371
 
892
- await parser.handleMessage(message, 'normal update');
1372
+ parser.handleMessage(message, 'normal update');
893
1373
 
894
1374
  // Verify updateItems was called on main hash tree
895
1375
  assert.calledOnceWithExactly(mainUpdateItemsStub, [
@@ -910,13 +1390,6 @@ describe('HashTreeParser', () => {
910
1390
  // Verify callback was called with OBJECTS_UPDATED and all updated objects
911
1391
  assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
912
1392
  updatedObjects: [
913
- {
914
- htMeta: {
915
- elementId: {type: 'self', id: 4, version: 101},
916
- dataSetNames: ['self'],
917
- },
918
- data: {person: {name: 'updated self name'}},
919
- },
920
1393
  {
921
1394
  htMeta: {
922
1395
  elementId: {type: 'locus', id: 0, version: 201},
@@ -924,10 +1397,6 @@ describe('HashTreeParser', () => {
924
1397
  },
925
1398
  data: {info: {id: 'updated-locus-info'}},
926
1399
  },
927
- // self updates appear twice, because they are processed twice in HashTreeParser.parseMessage()
928
- // (first for checking for visibleDataSets changes and again with the rest of updates in the main part of parseMessage())
929
- // this is only temporary until SPARK-744859 is done and having them twice here is not harmful
930
- // so keeping it like this for now
931
1400
  {
932
1401
  htMeta: {
933
1402
  elementId: {type: 'self', id: 4, version: 101},
@@ -953,43 +1422,71 @@ describe('HashTreeParser', () => {
953
1422
  });
954
1423
  });
955
1424
 
956
- it('detects roster drop correctly', async () => {
957
- const parser = createHashTreeParser();
958
-
959
- // Stub updateItems to return true (indicating the change was applied)
960
- sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
1425
+ describe('handles sentinel messages correctly', () => {
1426
+ ['main', 'self', 'unjoined'].forEach((dataSetName) => {
1427
+ it('emits MEETING_ENDED for sentinel message with dataset ' + dataSetName, async () => {
1428
+ const parser = createHashTreeParser();
1429
+
1430
+ // Create a sentinel message: leafCount=1, root=EMPTY_HASH, version higher than current
1431
+ const sentinelMessage = createHeartbeatMessage(
1432
+ dataSetName,
1433
+ 1,
1434
+ parser.dataSets[dataSetName]?.version
1435
+ ? parser.dataSets[dataSetName].version + 1
1436
+ : 10000,
1437
+ EMPTY_HASH
1438
+ );
1439
+
1440
+ // If the dataset doesn't exist yet (e.g. 'unjoined'), create it
1441
+ if (!parser.dataSets[dataSetName]) {
1442
+ parser.dataSets[dataSetName] = {
1443
+ url: `https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/${dataSetName}`,
1444
+ name: dataSetName,
1445
+ version: 1,
1446
+ leafCount: 16,
1447
+ root: '0'.repeat(32),
1448
+ idleMs: 1000,
1449
+ backoff: {maxMs: 1000, exponent: 2},
1450
+ } as any;
1451
+ }
961
1452
 
962
- // Send a roster drop message (SELF object with no data)
963
- const rosterDropMessage = {
964
- dataSets: [createDataSet('self', 1, 2101)],
965
- visibleDataSetsUrl,
966
- locusUrl,
967
- locusStateElements: [
968
- {
969
- htMeta: {
970
- elementId: {
971
- type: 'self' as const,
972
- id: 4,
973
- version: 102,
974
- },
975
- dataSetNames: ['self'],
976
- },
977
- data: undefined, // No data - this indicates roster drop
978
- },
979
- ],
980
- };
1453
+ parser.handleMessage(sentinelMessage, 'sentinel message');
981
1454
 
982
- await parser.handleMessage(rosterDropMessage, 'roster drop message');
1455
+ // Verify callback was called with MEETING_ENDED
1456
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
1457
+ updatedObjects: undefined,
1458
+ });
983
1459
 
984
- // Verify callback was called with MEETING_ENDED
985
- assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
986
- updatedObjects: undefined,
1460
+ // Verify that all timers were stopped
1461
+ Object.values(parser.dataSets).forEach((ds: any) => {
1462
+ assert.isUndefined(ds.timer);
1463
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
1464
+ });
1465
+ });
987
1466
  });
988
1467
 
989
- // Verify that all timers were stopped (timer should be undefined after roster drop)
990
- assert.equal(parser.dataSets.self.timer, undefined);
991
- assert.equal(parser.dataSets.main.timer, undefined);
992
- assert.equal(parser.dataSets['atd-unmuted'].timer, undefined);
1468
+ it('emits MEETING_ENDED for sentinel message with unknown dataset', async () => {
1469
+ const parser = createHashTreeParser();
1470
+
1471
+ // 'unjoined' is a valid sentinel dataset name but is not tracked by the parser
1472
+ assert.isUndefined(parser.dataSets['unjoined']);
1473
+
1474
+ // Create a sentinel message for 'unjoined' dataset which the parser has never seen
1475
+ const sentinelMessage = createHeartbeatMessage('unjoined', 1, 10000, EMPTY_HASH);
1476
+
1477
+ parser.handleMessage(sentinelMessage, 'sentinel message');
1478
+
1479
+ // Verify callback was called with MEETING_ENDED
1480
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
1481
+ updatedObjects: undefined,
1482
+ });
1483
+
1484
+ // Verify that all timers were stopped
1485
+ Object.values(parser.dataSets).forEach((ds: any) => {
1486
+ assert.isUndefined(ds.timer);
1487
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
1488
+ });
1489
+ });
993
1490
  });
994
1491
 
995
1492
  describe('sync algorithm', () => {
@@ -1020,7 +1517,7 @@ describe('HashTreeParser', () => {
1020
1517
  ],
1021
1518
  };
1022
1519
 
1023
- await parser.handleMessage(message, 'initial message');
1520
+ parser.handleMessage(message, 'initial message');
1024
1521
 
1025
1522
  // Verify callback was called with initial updates
1026
1523
  assert.calledOnce(callback);
@@ -1090,6 +1587,134 @@ describe('HashTreeParser', () => {
1090
1587
  ],
1091
1588
  });
1092
1589
  });
1590
+
1591
+ describe('emits MEETING_ENDED', () => {
1592
+ [404, 409].forEach((statusCode) => {
1593
+ it(`when /hashtree returns ${statusCode}`, async () => {
1594
+ const parser = createHashTreeParser();
1595
+
1596
+ // Send a message to trigger sync algorithm
1597
+ const message = {
1598
+ dataSets: [createDataSet('main', 16, 1100)],
1599
+ visibleDataSetsUrl,
1600
+ locusUrl,
1601
+ locusStateElements: [
1602
+ {
1603
+ htMeta: {
1604
+ elementId: {
1605
+ type: 'locus' as const,
1606
+ id: 0,
1607
+ version: 201,
1608
+ },
1609
+ dataSetNames: ['main'],
1610
+ },
1611
+ data: {info: {id: 'initial-update'}},
1612
+ },
1613
+ ],
1614
+ };
1615
+
1616
+ parser.handleMessage(message, 'initial message');
1617
+ callback.resetHistory();
1618
+
1619
+ const mainDataSetUrl = parser.dataSets.main.url;
1620
+
1621
+ // Mock getHashesFromLocus to reject with the sentinel error
1622
+ const error: any = new Error(`Request failed with status ${statusCode}`);
1623
+ error.statusCode = statusCode;
1624
+ if (statusCode === 409) {
1625
+ error.body = {errorCode: 2403004};
1626
+ }
1627
+ webexRequest
1628
+ .withArgs(
1629
+ sinon.match({
1630
+ method: 'GET',
1631
+ uri: `${mainDataSetUrl}/hashtree`,
1632
+ })
1633
+ )
1634
+ .rejects(error);
1635
+
1636
+ // Trigger sync by advancing time
1637
+ await clock.tickAsync(1000);
1638
+
1639
+ // Verify callback was called with MEETING_ENDED
1640
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
1641
+ updatedObjects: undefined,
1642
+ });
1643
+
1644
+ // Verify all timers are stopped
1645
+ Object.values(parser.dataSets).forEach((ds: any) => {
1646
+ assert.isUndefined(ds.timer);
1647
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
1648
+ });
1649
+ });
1650
+
1651
+ it(`when /sync returns ${statusCode}`, async () => {
1652
+ const parser = createHashTreeParser();
1653
+
1654
+ // Send a message to trigger sync algorithm
1655
+ const message = {
1656
+ dataSets: [createDataSet('main', 16, 1100)],
1657
+ visibleDataSetsUrl,
1658
+ locusUrl,
1659
+ locusStateElements: [
1660
+ {
1661
+ htMeta: {
1662
+ elementId: {
1663
+ type: 'locus' as const,
1664
+ id: 0,
1665
+ version: 201,
1666
+ },
1667
+ dataSetNames: ['main'],
1668
+ },
1669
+ data: {info: {id: 'initial-update'}},
1670
+ },
1671
+ ],
1672
+ };
1673
+
1674
+ parser.handleMessage(message, 'initial message');
1675
+ callback.resetHistory();
1676
+
1677
+ const mainDataSetUrl = parser.dataSets.main.url;
1678
+
1679
+ // Mock getHashesFromLocus to succeed
1680
+ mockGetHashesFromLocusResponse(
1681
+ mainDataSetUrl,
1682
+ new Array(16).fill('00000000000000000000000000000000'),
1683
+ createDataSet('main', 16, 1101)
1684
+ );
1685
+
1686
+ // Mock sendSyncRequestToLocus to reject with the sentinel error
1687
+ const error: any = new Error(`Request failed with status ${statusCode}`);
1688
+ error.statusCode = statusCode;
1689
+ if (statusCode === 409) {
1690
+ error.body = {errorCode: 2403004};
1691
+ }
1692
+ webexRequest
1693
+ .withArgs(
1694
+ sinon.match({
1695
+ method: 'POST',
1696
+ uri: `${mainDataSetUrl}/sync`,
1697
+ })
1698
+ )
1699
+ .rejects(error);
1700
+
1701
+ // Trigger sync by advancing time
1702
+ await clock.tickAsync(1000);
1703
+
1704
+ // Verify callback was called with MEETING_ENDED
1705
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
1706
+ updatedObjects: undefined,
1707
+ });
1708
+
1709
+ // Verify all timers are stopped
1710
+ Object.values(parser.dataSets).forEach((ds: any) => {
1711
+ assert.isUndefined(ds.timer);
1712
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
1713
+ });
1714
+ });
1715
+ });
1716
+ });
1717
+
1093
1718
  it('requests only mismatched hashes during sync', async () => {
1094
1719
  const parser = createHashTreeParser();
1095
1720
 
@@ -1135,7 +1760,7 @@ describe('HashTreeParser', () => {
1135
1760
  ],
1136
1761
  };
1137
1762
 
1138
- await parser.handleMessage(message, 'initial message');
1763
+ parser.handleMessage(message, 'initial message');
1139
1764
 
1140
1765
  callback.resetHistory();
1141
1766
 
@@ -1179,6 +1804,9 @@ describe('HashTreeParser', () => {
1179
1804
  sinon.match({
1180
1805
  method: 'GET',
1181
1806
  uri: `${mainDataSetUrl}/hashtree`,
1807
+ qs: {
1808
+ rootHash: hashTree.getRootHash(),
1809
+ },
1182
1810
  })
1183
1811
  );
1184
1812
 
@@ -1186,6 +1814,7 @@ describe('HashTreeParser', () => {
1186
1814
  assert.calledWith(webexRequest, {
1187
1815
  method: 'POST',
1188
1816
  uri: `${mainDataSetUrl}/sync`,
1817
+ qs: {rootHash: hashTree.getRootHash()},
1189
1818
  body: {
1190
1819
  leafCount: 16,
1191
1820
  leafDataEntries: [
@@ -1219,7 +1848,7 @@ describe('HashTreeParser', () => {
1219
1848
  ],
1220
1849
  };
1221
1850
 
1222
- await parser.handleMessage(message, 'message with self update');
1851
+ parser.handleMessage(message, 'message with self update');
1223
1852
 
1224
1853
  callback.resetHistory();
1225
1854
 
@@ -1239,10 +1868,17 @@ describe('HashTreeParser', () => {
1239
1868
  assert.calledWith(webexRequest, {
1240
1869
  method: 'POST',
1241
1870
  uri: `${parser.dataSets.self.url}/sync`,
1871
+ qs: {rootHash: parser.dataSets.self.hashTree.getRootHash()},
1242
1872
  body: {
1243
1873
  leafCount: 1,
1244
1874
  leafDataEntries: [
1245
- {leafIndex: 0, elementIds: [{type: 'self', id: 4, version: 102}]},
1875
+ {
1876
+ leafIndex: 0,
1877
+ elementIds: [
1878
+ {type: 'self', id: 4, version: 102},
1879
+ {type: 'metadata', id: 5, version: 50},
1880
+ ],
1881
+ },
1246
1882
  ],
1247
1883
  },
1248
1884
  });
@@ -1257,7 +1893,7 @@ describe('HashTreeParser', () => {
1257
1893
  // Stub updateItems on self hash tree to return true
1258
1894
  sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
1259
1895
 
1260
- // Send a message with SELF object that has a new visibleDataSets list
1896
+ // Send a message with Metadata object that has a new visibleDataSets list
1261
1897
  const message = {
1262
1898
  dataSets: [createDataSet('self', 1, 2100), createDataSet('attendees', 8, 4000)],
1263
1899
  visibleDataSetsUrl,
@@ -1266,47 +1902,98 @@ describe('HashTreeParser', () => {
1266
1902
  {
1267
1903
  htMeta: {
1268
1904
  elementId: {
1269
- type: 'self' as const,
1270
- id: 4,
1271
- version: 101,
1905
+ type: 'metadata' as const,
1906
+ id: 5,
1907
+ version: 51,
1272
1908
  },
1273
1909
  dataSetNames: ['self'],
1274
1910
  },
1275
1911
  data: {
1276
- visibleDataSets: ['main', 'self', 'atd-unmuted', 'attendees'], // added 'attendees'
1912
+ visibleDataSets: [
1913
+ {
1914
+ name: 'main',
1915
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
1916
+ },
1917
+ {
1918
+ name: 'self',
1919
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
1920
+ },
1921
+ {
1922
+ name: 'atd-unmuted',
1923
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
1924
+ },
1925
+ {
1926
+ name: 'attendees',
1927
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
1928
+ },
1929
+ ], // added 'attendees'
1277
1930
  },
1278
1931
  },
1279
1932
  ],
1280
1933
  };
1281
1934
 
1282
- await parser.handleMessage(message, 'add visible dataset');
1935
+ parser.handleMessage(message, 'add visible dataset');
1283
1936
 
1284
1937
  // Verify that 'attendees' was added to visibleDataSets
1285
- assert.include(parser.visibleDataSets, 'attendees');
1938
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'attendees')).to.be.true;
1286
1939
 
1287
1940
  // Verify that a hash tree was created for 'attendees'
1288
1941
  assert.exists(parser.dataSets.attendees.hashTree);
1289
1942
  assert.equal(parser.dataSets.attendees.hashTree.numLeaves, 8);
1290
1943
 
1291
- // Verify callback was called with the self update (appears twice due to SPARK-744859)
1944
+ // Verify callback was called with the metadata update (appears twice - processed once for visible dataset changes, once in main loop)
1292
1945
  assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
1293
1946
  updatedObjects: [
1294
1947
  {
1295
1948
  htMeta: {
1296
- elementId: {type: 'self', id: 4, version: 101},
1949
+ elementId: {type: 'metadata', id: 5, version: 51},
1297
1950
  dataSetNames: ['self'],
1298
1951
  },
1299
1952
  data: {
1300
- visibleDataSets: ['main', 'self', 'atd-unmuted', 'attendees'],
1953
+ visibleDataSets: [
1954
+ {
1955
+ name: 'main',
1956
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
1957
+ },
1958
+ {
1959
+ name: 'self',
1960
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
1961
+ },
1962
+ {
1963
+ name: 'atd-unmuted',
1964
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
1965
+ },
1966
+ {
1967
+ name: 'attendees',
1968
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
1969
+ },
1970
+ ],
1301
1971
  },
1302
1972
  },
1303
1973
  {
1304
1974
  htMeta: {
1305
- elementId: {type: 'self', id: 4, version: 101},
1975
+ elementId: {type: 'metadata', id: 5, version: 51},
1306
1976
  dataSetNames: ['self'],
1307
1977
  },
1308
1978
  data: {
1309
- visibleDataSets: ['main', 'self', 'atd-unmuted', 'attendees'],
1979
+ visibleDataSets: [
1980
+ {
1981
+ name: 'main',
1982
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
1983
+ },
1984
+ {
1985
+ name: 'self',
1986
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
1987
+ },
1988
+ {
1989
+ name: 'atd-unmuted',
1990
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
1991
+ },
1992
+ {
1993
+ name: 'attendees',
1994
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
1995
+ },
1996
+ ],
1310
1997
  },
1311
1998
  },
1312
1999
  ],
@@ -1320,7 +2007,7 @@ describe('HashTreeParser', () => {
1320
2007
  // Stub updateItems on self hash tree to return true
1321
2008
  sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
1322
2009
 
1323
- // Send a message with SELF object that has a new visibleDataSets list (adding 'new-dataset')
2010
+ // Send a message with Metadata object that has a new visibleDataSets list (adding 'new-dataset')
1324
2011
  // but WITHOUT providing info about the new dataset in dataSets array
1325
2012
  const message = {
1326
2013
  dataSets: [createDataSet('self', 1, 2100)],
@@ -1330,14 +2017,31 @@ describe('HashTreeParser', () => {
1330
2017
  {
1331
2018
  htMeta: {
1332
2019
  elementId: {
1333
- type: 'self' as const,
1334
- id: 4,
1335
- version: 101,
2020
+ type: 'metadata' as const,
2021
+ id: 5,
2022
+ version: 51,
1336
2023
  },
1337
2024
  dataSetNames: ['self'],
1338
2025
  },
1339
2026
  data: {
1340
- visibleDataSets: ['main', 'self', 'atd-unmuted', 'new-dataset'],
2027
+ visibleDataSets: [
2028
+ {
2029
+ name: 'main',
2030
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2031
+ },
2032
+ {
2033
+ name: 'self',
2034
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2035
+ },
2036
+ {
2037
+ name: 'atd-unmuted',
2038
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
2039
+ },
2040
+ {
2041
+ name: 'new-dataset',
2042
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/new-dataset',
2043
+ },
2044
+ ],
1341
2045
  },
1342
2046
  },
1343
2047
  ],
@@ -1353,40 +2057,80 @@ describe('HashTreeParser', () => {
1353
2057
  locusStateElements: [],
1354
2058
  });
1355
2059
 
1356
- await parser.handleMessage(message, 'add new dataset requiring async init');
2060
+ parser.handleMessage(message, 'add new dataset requiring async init');
1357
2061
 
1358
- // immediately we don't have the dataset yet, so it should not be in visibleDataSets
1359
- // and no hash tree should exist yet
1360
- assert.isFalse(parser.visibleDataSets.includes('new-dataset'));
1361
- assert.isUndefined(parser.dataSets['new-dataset']);
2062
+ await checkAsyncDatasetInitialization(parser, newDataSet);
2063
+ });
1362
2064
 
1363
- // Wait for the async initialization to complete (queued as microtask)
1364
- await clock.tickAsync(0);
2065
+ it('emits MEETING_ENDED if async init of a new visible dataset fails with 404', async () => {
2066
+ const parser = createHashTreeParser();
1365
2067
 
1366
- // The visibleDataSets is updated from the self object data
1367
- assert.include(parser.visibleDataSets, 'new-dataset');
2068
+ // Stub updateItems on self hash tree to return true
2069
+ sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
1368
2070
 
1369
- // Verify that a hash tree was created for 'new-dataset'
1370
- assert.exists(parser.dataSets['new-dataset'].hashTree);
1371
- assert.equal(parser.dataSets['new-dataset'].hashTree.numLeaves, 4);
2071
+ // Send a message with Metadata object that adds a new visible dataset
2072
+ const message = {
2073
+ dataSets: [createDataSet('self', 1, 2100)],
2074
+ visibleDataSetsUrl,
2075
+ locusUrl,
2076
+ locusStateElements: [
2077
+ {
2078
+ htMeta: {
2079
+ elementId: {
2080
+ type: 'metadata' as const,
2081
+ id: 5,
2082
+ version: 51,
2083
+ },
2084
+ dataSetNames: ['self'],
2085
+ },
2086
+ data: {
2087
+ visibleDataSets: [
2088
+ {
2089
+ name: 'main',
2090
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2091
+ },
2092
+ {
2093
+ name: 'self',
2094
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2095
+ },
2096
+ {
2097
+ name: 'atd-unmuted',
2098
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
2099
+ },
2100
+ {
2101
+ name: 'new-dataset',
2102
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/new-dataset',
2103
+ },
2104
+ ],
2105
+ },
2106
+ },
2107
+ ],
2108
+ };
1372
2109
 
1373
- // Verify getAllDataSetsMetadata was called for async initialization
1374
- assert.calledWith(
1375
- webexRequest,
1376
- sinon.match({
1377
- method: 'GET',
1378
- uri: visibleDataSetsUrl,
1379
- })
1380
- );
2110
+ // Mock getAllDataSetsMetadata to reject with 404
2111
+ const error: any = new Error('Request failed with status 404');
2112
+ error.statusCode = 404;
2113
+ webexRequest
2114
+ .withArgs(
2115
+ sinon.match({
2116
+ method: 'GET',
2117
+ uri: visibleDataSetsUrl,
2118
+ })
2119
+ )
2120
+ .rejects(error);
2121
+
2122
+ parser.handleMessage(message, 'add new dataset triggering 404');
2123
+
2124
+ // The first callback call is from parseMessage with the metadata update
2125
+ callback.resetHistory();
1381
2126
 
1382
- // Verify sync request was sent for the new dataset
1383
- assert.calledWith(
1384
- webexRequest,
1385
- sinon.match({
1386
- method: 'POST',
1387
- uri: `${newDataSet.url}/sync`,
1388
- })
1389
- );
2127
+ // Wait for the async initialization (queueMicrotask) to complete
2128
+ await clock.tickAsync(0);
2129
+
2130
+ // Verify callback was called with MEETING_ENDED
2131
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
2132
+ updatedObjects: undefined,
2133
+ });
1390
2134
  });
1391
2135
 
1392
2136
  it('handles removal of visible data set', async () => {
@@ -1406,7 +2150,7 @@ describe('HashTreeParser', () => {
1406
2150
  // Stub updateItems on self hash tree to return true
1407
2151
  sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
1408
2152
 
1409
- // Send a message with SELF object that has removed 'atd-unmuted' from visibleDataSets
2153
+ // Send a message with Metadata object that has removed 'atd-unmuted' from visibleDataSets
1410
2154
  const message = {
1411
2155
  dataSets: [createDataSet('self', 1, 2100)],
1412
2156
  visibleDataSetsUrl,
@@ -1415,23 +2159,32 @@ describe('HashTreeParser', () => {
1415
2159
  {
1416
2160
  htMeta: {
1417
2161
  elementId: {
1418
- type: 'self' as const,
1419
- id: 4,
1420
- version: 101,
2162
+ type: 'metadata' as const,
2163
+ id: 5,
2164
+ version: 51,
1421
2165
  },
1422
2166
  dataSetNames: ['self'],
1423
2167
  },
1424
2168
  data: {
1425
- visibleDataSets: ['main', 'self'], // removed 'atd-unmuted'
2169
+ visibleDataSets: [
2170
+ {
2171
+ name: 'main',
2172
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2173
+ },
2174
+ {
2175
+ name: 'self',
2176
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2177
+ },
2178
+ ], // removed 'atd-unmuted'
1426
2179
  },
1427
2180
  },
1428
2181
  ],
1429
2182
  };
1430
2183
 
1431
- await parser.handleMessage(message, 'remove visible dataset');
2184
+ parser.handleMessage(message, 'remove visible dataset');
1432
2185
 
1433
2186
  // Verify that 'atd-unmuted' was removed from visibleDataSets
1434
- assert.notInclude(parser.visibleDataSets, 'atd-unmuted');
2187
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'atd-unmuted')).to.be.false;
1435
2188
 
1436
2189
  // Verify that the hash tree for 'atd-unmuted' was deleted
1437
2190
  assert.isUndefined(parser.dataSets['atd-unmuted'].hashTree);
@@ -1439,16 +2192,25 @@ describe('HashTreeParser', () => {
1439
2192
  // Verify that the timer was cleared
1440
2193
  assert.isUndefined(parser.dataSets['atd-unmuted'].timer);
1441
2194
 
1442
- // Verify callback was called with both the self update and the removed objects
2195
+ // Verify callback was called with the metadata update and the removed objects (metadata appears twice - processed once for dataset changes, once in main loop)
1443
2196
  assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
1444
2197
  updatedObjects: [
1445
2198
  {
1446
2199
  htMeta: {
1447
- elementId: {type: 'self', id: 4, version: 101},
2200
+ elementId: {type: 'metadata', id: 5, version: 51},
1448
2201
  dataSetNames: ['self'],
1449
2202
  },
1450
2203
  data: {
1451
- visibleDataSets: ['main', 'self'],
2204
+ visibleDataSets: [
2205
+ {
2206
+ name: 'main',
2207
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2208
+ },
2209
+ {
2210
+ name: 'self',
2211
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2212
+ },
2213
+ ],
1452
2214
  },
1453
2215
  },
1454
2216
  {
@@ -1460,11 +2222,20 @@ describe('HashTreeParser', () => {
1460
2222
  },
1461
2223
  {
1462
2224
  htMeta: {
1463
- elementId: {type: 'self', id: 4, version: 101}, // 2nd self because of SPARK-744859
2225
+ elementId: {type: 'metadata', id: 5, version: 51},
1464
2226
  dataSetNames: ['self'],
1465
2227
  },
1466
2228
  data: {
1467
- visibleDataSets: ['main', 'self'],
2229
+ visibleDataSets: [
2230
+ {
2231
+ name: 'main',
2232
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2233
+ },
2234
+ {
2235
+ name: 'self',
2236
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2237
+ },
2238
+ ],
1468
2239
  },
1469
2240
  },
1470
2241
  ],
@@ -1489,7 +2260,7 @@ describe('HashTreeParser', () => {
1489
2260
  });
1490
2261
 
1491
2262
  // Verify attendees is NOT in visibleDataSets
1492
- assert.notInclude(parser.visibleDataSets, 'attendees');
2263
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'attendees')).to.be.false;
1493
2264
 
1494
2265
  // Send a message with attendees data
1495
2266
  const message = {
@@ -1511,7 +2282,7 @@ describe('HashTreeParser', () => {
1511
2282
  ],
1512
2283
  };
1513
2284
 
1514
- await parser.handleMessage(message, 'message with non-visible dataset');
2285
+ parser.handleMessage(message, 'message with non-visible dataset');
1515
2286
 
1516
2287
  // Verify that no hash tree was created for attendees
1517
2288
  assert.isUndefined(parser.dataSets.attendees.hashTree);
@@ -1520,5 +2291,914 @@ describe('HashTreeParser', () => {
1520
2291
  assert.notCalled(callback);
1521
2292
  });
1522
2293
  });
2294
+
2295
+ describe('heartbeat watchdog', () => {
2296
+ it('initiates sync immediately only for the specific data set whose heartbeat watchdog fires', async () => {
2297
+ const parser = createHashTreeParser();
2298
+ const heartbeatIntervalMs = 5000;
2299
+
2300
+ // Send initial heartbeat message for 'main' only
2301
+ const heartbeatMessage = {
2302
+ dataSets: [
2303
+ {
2304
+ ...createDataSet('main', 16, 1100),
2305
+ root: parser.dataSets.main.hashTree.getRootHash(),
2306
+ },
2307
+ ],
2308
+ visibleDataSetsUrl,
2309
+ locusUrl,
2310
+ heartbeatIntervalMs,
2311
+ };
2312
+
2313
+ parser.handleMessage(heartbeatMessage, 'initial heartbeat');
2314
+
2315
+ // Verify only 'main' watchdog timer is set
2316
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2317
+ expect(parser.dataSets.self.heartbeatWatchdogTimer).to.be.undefined;
2318
+ expect(parser.dataSets['atd-unmuted'].heartbeatWatchdogTimer).to.be.undefined;
2319
+
2320
+ // Mock responses for performSync (GET hashtree then POST sync for leafCount > 1)
2321
+ const mainDataSetUrl = parser.dataSets.main.url;
2322
+ mockGetHashesFromLocusResponse(
2323
+ mainDataSetUrl,
2324
+ new Array(16).fill('00000000000000000000000000000000'),
2325
+ createDataSet('main', 16, 1101)
2326
+ );
2327
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
2328
+
2329
+ // Advance time past heartbeatIntervalMs + backoff (Math.random returns 0, so backoff = 0)
2330
+ // performSync is called immediately when the watchdog fires - no additional delay
2331
+ await clock.tickAsync(heartbeatIntervalMs);
2332
+
2333
+ // Verify sync request was sent immediately for 'main' (GET hashtree + POST sync)
2334
+ assert.calledWith(
2335
+ webexRequest,
2336
+ sinon.match({
2337
+ method: 'GET',
2338
+ uri: `${mainDataSetUrl}/hashtree`,
2339
+ })
2340
+ );
2341
+
2342
+ // Verify no sync requests were sent for other datasets
2343
+ assert.neverCalledWith(
2344
+ webexRequest,
2345
+ sinon.match({
2346
+ method: 'POST',
2347
+ uri: `${parser.dataSets.self.url}/sync`,
2348
+ })
2349
+ );
2350
+ assert.neverCalledWith(
2351
+ webexRequest,
2352
+ sinon.match({
2353
+ method: 'GET',
2354
+ uri: `${parser.dataSets['atd-unmuted'].url}/hashtree`,
2355
+ })
2356
+ );
2357
+ });
2358
+
2359
+ it('calls POST sync directly for leafCount === 1 data sets', async () => {
2360
+ const parser = createHashTreeParser();
2361
+ const heartbeatIntervalMs = 5000;
2362
+
2363
+ // Send heartbeat for 'self' (leafCount === 1)
2364
+ const heartbeatMessage = {
2365
+ dataSets: [
2366
+ {
2367
+ ...createDataSet('self', 1, 2100),
2368
+ url: parser.dataSets.self.url,
2369
+ root: parser.dataSets.self.hashTree.getRootHash(),
2370
+ },
2371
+ ],
2372
+ visibleDataSetsUrl,
2373
+ locusUrl,
2374
+ heartbeatIntervalMs,
2375
+ };
2376
+
2377
+ parser.handleMessage(heartbeatMessage, 'self heartbeat');
2378
+
2379
+ // Mock sync response for self
2380
+ mockSendSyncRequestResponse(parser.dataSets.self.url, null);
2381
+
2382
+ // Advance time past watchdog delay
2383
+ await clock.tickAsync(heartbeatIntervalMs);
2384
+
2385
+ // For leafCount === 1, performSync skips GET hashtree and goes straight to POST sync
2386
+ assert.neverCalledWith(
2387
+ webexRequest,
2388
+ sinon.match({
2389
+ method: 'GET',
2390
+ uri: `${parser.dataSets.self.url}/hashtree`,
2391
+ })
2392
+ );
2393
+ assert.calledWith(
2394
+ webexRequest,
2395
+ sinon.match({
2396
+ method: 'POST',
2397
+ uri: `${parser.dataSets.self.url}/sync`,
2398
+ })
2399
+ );
2400
+ });
2401
+
2402
+ it('sets watchdog timers for each data set in the message', async () => {
2403
+ const parser = createHashTreeParser();
2404
+ const heartbeatIntervalMs = 5000;
2405
+
2406
+ // Send heartbeat with multiple datasets
2407
+ const heartbeatMessage = {
2408
+ dataSets: [
2409
+ {
2410
+ ...createDataSet('main', 16, 1100),
2411
+ root: parser.dataSets.main.hashTree.getRootHash(),
2412
+ },
2413
+ {
2414
+ ...createDataSet('self', 1, 2100),
2415
+ url: parser.dataSets.self.url,
2416
+ root: parser.dataSets.self.hashTree.getRootHash(),
2417
+ },
2418
+ ],
2419
+ visibleDataSetsUrl,
2420
+ locusUrl,
2421
+ heartbeatIntervalMs,
2422
+ };
2423
+
2424
+ parser.handleMessage(heartbeatMessage, 'multi-dataset heartbeat');
2425
+
2426
+ // Watchdog timers should be set for both datasets in the message
2427
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2428
+ expect(parser.dataSets.self.heartbeatWatchdogTimer).to.not.be.undefined;
2429
+ // But not for datasets not in the message
2430
+ expect(parser.dataSets['atd-unmuted'].heartbeatWatchdogTimer).to.be.undefined;
2431
+ });
2432
+
2433
+ it('resets the watchdog timer for a specific data set when a new heartbeat for it is received', async () => {
2434
+ const parser = createHashTreeParser();
2435
+ const heartbeatIntervalMs = 5000;
2436
+
2437
+ // Send first heartbeat for 'main'
2438
+ const heartbeat1 = {
2439
+ dataSets: [
2440
+ {
2441
+ ...createDataSet('main', 16, 1100),
2442
+ root: parser.dataSets.main.hashTree.getRootHash(),
2443
+ },
2444
+ ],
2445
+ visibleDataSetsUrl,
2446
+ locusUrl,
2447
+ heartbeatIntervalMs,
2448
+ };
2449
+
2450
+ parser.handleMessage(heartbeat1, 'first heartbeat');
2451
+
2452
+ const firstTimer = parser.dataSets.main.heartbeatWatchdogTimer;
2453
+ expect(firstTimer).to.not.be.undefined;
2454
+
2455
+ // Advance time to just before the watchdog would fire
2456
+ clock.tick(4000);
2457
+
2458
+ // Send second heartbeat for 'main' - this should reset the watchdog
2459
+ const heartbeat2 = {
2460
+ dataSets: [
2461
+ {
2462
+ ...createDataSet('main', 16, 1101),
2463
+ root: parser.dataSets.main.hashTree.getRootHash(),
2464
+ },
2465
+ ],
2466
+ visibleDataSetsUrl,
2467
+ locusUrl,
2468
+ heartbeatIntervalMs,
2469
+ };
2470
+
2471
+ parser.handleMessage(heartbeat2, 'second heartbeat');
2472
+
2473
+ const secondTimer = parser.dataSets.main.heartbeatWatchdogTimer;
2474
+ expect(secondTimer).to.not.be.undefined;
2475
+ expect(secondTimer).to.not.equal(firstTimer);
2476
+
2477
+ // Advance another 4000ms (total 8000ms from start, but only 4000ms since last heartbeat)
2478
+ // The watchdog should NOT fire yet
2479
+ await clock.tickAsync(4000);
2480
+
2481
+ // No sync requests should have been sent
2482
+ assert.notCalled(webexRequest);
2483
+ });
2484
+
2485
+ it('resets the watchdog timer when a normal message (with locusStateElements) is received', async () => {
2486
+ const parser = createHashTreeParser();
2487
+ const heartbeatIntervalMs = 5000;
2488
+
2489
+ // Send initial heartbeat to start the watchdog for 'main'
2490
+ const heartbeat = {
2491
+ dataSets: [
2492
+ {
2493
+ ...createDataSet('main', 16, 1100),
2494
+ root: parser.dataSets.main.hashTree.getRootHash(),
2495
+ },
2496
+ ],
2497
+ visibleDataSetsUrl,
2498
+ locusUrl,
2499
+ heartbeatIntervalMs,
2500
+ };
2501
+
2502
+ parser.handleMessage(heartbeat, 'initial heartbeat');
2503
+
2504
+ const firstTimer = parser.dataSets.main.heartbeatWatchdogTimer;
2505
+ expect(firstTimer).to.not.be.undefined;
2506
+
2507
+ // Advance time partially
2508
+ clock.tick(3000);
2509
+
2510
+ // Stub updateItems so the normal message is processed
2511
+ sinon.stub(parser.dataSets.main.hashTree, 'updateItems').returns([true]);
2512
+
2513
+ // Send a normal message (with locusStateElements) for 'main' - should also reset watchdog
2514
+ const normalMessage = {
2515
+ dataSets: [createDataSet('main', 16, 1101)],
2516
+ visibleDataSetsUrl,
2517
+ locusUrl,
2518
+ locusStateElements: [
2519
+ {
2520
+ htMeta: {
2521
+ elementId: {type: 'locus' as const, id: 0, version: 201},
2522
+ dataSetNames: ['main'],
2523
+ },
2524
+ data: {someData: 'value'},
2525
+ },
2526
+ ],
2527
+ heartbeatIntervalMs,
2528
+ };
2529
+
2530
+ parser.handleMessage(normalMessage, 'normal message');
2531
+
2532
+ const secondTimer = parser.dataSets.main.heartbeatWatchdogTimer;
2533
+ expect(secondTimer).to.not.be.undefined;
2534
+ expect(secondTimer).to.not.equal(firstTimer);
2535
+ });
2536
+
2537
+ it('does not set the watchdog timer when heartbeatIntervalMs is not set', async () => {
2538
+ const parser = createHashTreeParser();
2539
+
2540
+ // Send a heartbeat message without heartbeatIntervalMs
2541
+ const heartbeatMessage = createHeartbeatMessage(
2542
+ 'main',
2543
+ 16,
2544
+ 1100,
2545
+ parser.dataSets.main.hashTree.getRootHash()
2546
+ );
2547
+
2548
+ parser.handleMessage(heartbeatMessage, 'heartbeat without interval');
2549
+
2550
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.be.undefined;
2551
+ });
2552
+
2553
+ it('stops all watchdog timers when meeting ends via sentinel message', async () => {
2554
+ const parser = createHashTreeParser();
2555
+ const heartbeatIntervalMs = 5000;
2556
+
2557
+ // Send heartbeat for multiple datasets
2558
+ const heartbeat = {
2559
+ dataSets: [
2560
+ {
2561
+ ...createDataSet('main', 16, 1100),
2562
+ root: parser.dataSets.main.hashTree.getRootHash(),
2563
+ },
2564
+ {
2565
+ ...createDataSet('self', 1, 2100),
2566
+ url: parser.dataSets.self.url,
2567
+ root: parser.dataSets.self.hashTree.getRootHash(),
2568
+ },
2569
+ ],
2570
+ visibleDataSetsUrl,
2571
+ locusUrl,
2572
+ heartbeatIntervalMs,
2573
+ };
2574
+
2575
+ parser.handleMessage(heartbeat, 'initial heartbeat');
2576
+
2577
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2578
+ expect(parser.dataSets.self.heartbeatWatchdogTimer).to.not.be.undefined;
2579
+
2580
+ // Send a sentinel END MEETING message
2581
+ const sentinelMessage = createHeartbeatMessage(
2582
+ 'main',
2583
+ 1,
2584
+ parser.dataSets.main.version + 1,
2585
+ EMPTY_HASH
2586
+ );
2587
+
2588
+ parser.handleMessage(sentinelMessage as any, 'sentinel message');
2589
+
2590
+ // All watchdog timers should have been stopped
2591
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.be.undefined;
2592
+ expect(parser.dataSets.self.heartbeatWatchdogTimer).to.be.undefined;
2593
+ });
2594
+
2595
+ it("uses each data set's own backoff for its watchdog delay", async () => {
2596
+ // Create a parser where datasets have different backoff configs
2597
+ const initialLocus = {
2598
+ dataSets: [
2599
+ {
2600
+ ...createDataSet('main', 16, 1000),
2601
+ backoff: {maxMs: 500, exponent: 2},
2602
+ },
2603
+ {
2604
+ ...createDataSet('self', 1, 2000),
2605
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2606
+ backoff: {maxMs: 2000, exponent: 3},
2607
+ },
2608
+ ],
2609
+ locus: {
2610
+ ...exampleInitialLocus.locus,
2611
+ },
2612
+ };
2613
+
2614
+ const metadata = {
2615
+ ...exampleMetadata,
2616
+ visibleDataSets: [
2617
+ {name: 'main', url: initialLocus.dataSets[0].url},
2618
+ {name: 'self', url: initialLocus.dataSets[1].url},
2619
+ ],
2620
+ };
2621
+
2622
+ const parser = createHashTreeParser(initialLocus, metadata);
2623
+ const heartbeatIntervalMs = 5000;
2624
+
2625
+ // Set Math.random to return 1 so that backoff = 1^exponent * maxMs = maxMs
2626
+ mathRandomStub.returns(1);
2627
+
2628
+ // Send heartbeat for both datasets
2629
+ const heartbeat = {
2630
+ dataSets: [
2631
+ {
2632
+ ...createDataSet('main', 16, 1100),
2633
+ backoff: {maxMs: 500, exponent: 2},
2634
+ root: parser.dataSets.main.hashTree.getRootHash(),
2635
+ },
2636
+ {
2637
+ ...createDataSet('self', 1, 2100),
2638
+ url: parser.dataSets.self.url,
2639
+ backoff: {maxMs: 2000, exponent: 3},
2640
+ root: parser.dataSets.self.hashTree.getRootHash(),
2641
+ },
2642
+ ],
2643
+ visibleDataSetsUrl,
2644
+ locusUrl,
2645
+ heartbeatIntervalMs,
2646
+ };
2647
+
2648
+ parser.handleMessage(heartbeat, 'heartbeat');
2649
+
2650
+ // 'main' watchdog delay = 5000 + 1^2 * 500 = 5500ms
2651
+ // 'self' watchdog delay = 5000 + 1^3 * 2000 = 7000ms
2652
+
2653
+ // Mock sync responses
2654
+ mockGetHashesFromLocusResponse(
2655
+ parser.dataSets.main.url,
2656
+ new Array(16).fill('00000000000000000000000000000000'),
2657
+ createDataSet('main', 16, 1101)
2658
+ );
2659
+ mockSendSyncRequestResponse(parser.dataSets.main.url, null);
2660
+ mockSendSyncRequestResponse(parser.dataSets.self.url, null);
2661
+
2662
+ // At 5499ms, neither watchdog should have fired
2663
+ await clock.tickAsync(5499);
2664
+ assert.notCalled(webexRequest);
2665
+
2666
+ // At 5500ms, 'main' watchdog fires and performSync runs immediately
2667
+ await clock.tickAsync(1);
2668
+
2669
+ // main sync should have triggered immediately (GET hashtree + POST sync)
2670
+ assert.calledWith(
2671
+ webexRequest,
2672
+ sinon.match({
2673
+ method: 'GET',
2674
+ uri: `${parser.dataSets.main.url}/hashtree`,
2675
+ })
2676
+ );
2677
+
2678
+ webexRequest.resetHistory();
2679
+
2680
+ // At 7000ms, 'self' watchdog fires and performSync runs immediately
2681
+ await clock.tickAsync(1500);
2682
+
2683
+ // self sync should have also triggered (POST sync only, leafCount === 1)
2684
+ assert.calledWith(
2685
+ webexRequest,
2686
+ sinon.match({
2687
+ method: 'POST',
2688
+ uri: `${parser.dataSets.self.url}/sync`,
2689
+ })
2690
+ );
2691
+ });
2692
+
2693
+ it('does not set watchdog for data sets without a hash tree', async () => {
2694
+ const parser = createHashTreeParser();
2695
+ const heartbeatIntervalMs = 5000;
2696
+
2697
+ // 'atd-active' is in the initial locus but is not visible (no hash tree)
2698
+ // Send heartbeat mentioning a non-visible dataset
2699
+ const heartbeatMessage = {
2700
+ dataSets: [
2701
+ {
2702
+ ...createDataSet('main', 16, 1100),
2703
+ root: parser.dataSets.main.hashTree.getRootHash(),
2704
+ },
2705
+ createDataSet('atd-active', 16, 4000),
2706
+ ],
2707
+ visibleDataSetsUrl,
2708
+ locusUrl,
2709
+ heartbeatIntervalMs,
2710
+ };
2711
+
2712
+ parser.handleMessage(heartbeatMessage, 'heartbeat with non-visible dataset');
2713
+
2714
+ // Watchdog set for main (visible) but not for atd-active (no hash tree)
2715
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2716
+ expect(parser.dataSets['atd-active']?.heartbeatWatchdogTimer).to.be.undefined;
2717
+ });
2718
+ });
2719
+ });
2720
+
2721
+ describe('#callLocusInfoUpdateCallback filtering', () => {
2722
+ // Helper to setup parser with initial objects and reset callback history
2723
+ function setupParserWithObjects(locusStateElements: any[]) {
2724
+ const parser = createHashTreeParser();
2725
+
2726
+ if (locusStateElements.length > 0) {
2727
+ // Determine which datasets to include based on the objects' dataSetNames
2728
+ const dataSetNames = new Set<string>();
2729
+ locusStateElements.forEach((element) => {
2730
+ element.htMeta?.dataSetNames?.forEach((name) => dataSetNames.add(name));
2731
+ });
2732
+
2733
+ const dataSets = [];
2734
+ if (dataSetNames.has('main')) dataSets.push(createDataSet('main', 16, 1100));
2735
+ if (dataSetNames.has('self')) dataSets.push(createDataSet('self', 1, 2100));
2736
+ if (dataSetNames.has('atd-unmuted')) dataSets.push(createDataSet('atd-unmuted', 16, 3100));
2737
+
2738
+ const setupMessage = {
2739
+ dataSets,
2740
+ visibleDataSetsUrl,
2741
+ locusUrl,
2742
+ locusStateElements,
2743
+ };
2744
+
2745
+ parser.handleMessage(setupMessage, 'setup');
2746
+ }
2747
+
2748
+ callback.resetHistory();
2749
+ return parser;
2750
+ }
2751
+
2752
+ it('filters out updates when a dataset has a higher version', () => {
2753
+ const parser = setupParserWithObjects([
2754
+ {
2755
+ htMeta: {
2756
+ elementId: {type: 'locus' as const, id: 5, version: 100},
2757
+ dataSetNames: ['main'],
2758
+ },
2759
+ data: {existingField: 'existing'},
2760
+ },
2761
+ ]);
2762
+
2763
+ // Try to update with an older version (90)
2764
+ const updateMessage = {
2765
+ dataSets: [createDataSet('main', 16, 1101)],
2766
+ visibleDataSetsUrl,
2767
+ locusUrl,
2768
+ locusStateElements: [
2769
+ {
2770
+ htMeta: {
2771
+ elementId: {type: 'locus' as const, id: 5, version: 90},
2772
+ dataSetNames: ['main'],
2773
+ },
2774
+ data: {someField: 'value'},
2775
+ },
2776
+ ],
2777
+ };
2778
+
2779
+ parser.handleMessage(updateMessage, 'update with older version');
2780
+
2781
+ // Callback should not be called because the update was filtered out
2782
+ assert.notCalled(callback);
2783
+ });
2784
+
2785
+ it('allows updates when version is newer than existing', () => {
2786
+ const parser = setupParserWithObjects([
2787
+ {
2788
+ htMeta: {
2789
+ elementId: {type: 'locus' as const, id: 5, version: 100},
2790
+ dataSetNames: ['main'],
2791
+ },
2792
+ data: {existingField: 'existing'},
2793
+ },
2794
+ ]);
2795
+
2796
+ // Try to update with a newer version (110)
2797
+ const updateMessage = {
2798
+ dataSets: [createDataSet('main', 16, 1101)],
2799
+ visibleDataSetsUrl,
2800
+ locusUrl,
2801
+ locusStateElements: [
2802
+ {
2803
+ htMeta: {
2804
+ elementId: {type: 'locus' as const, id: 5, version: 110},
2805
+ dataSetNames: ['main'],
2806
+ },
2807
+ data: {someField: 'new value'},
2808
+ },
2809
+ ],
2810
+ };
2811
+
2812
+ parser.handleMessage(updateMessage, 'update with newer version');
2813
+
2814
+ // Callback should be called with the update
2815
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
2816
+ updatedObjects: [
2817
+ {
2818
+ htMeta: {
2819
+ elementId: {type: 'locus', id: 5, version: 110},
2820
+ dataSetNames: ['main'],
2821
+ },
2822
+ data: {someField: 'new value'},
2823
+ },
2824
+ ],
2825
+ });
2826
+ });
2827
+
2828
+ it('filters out removal when object still exists in any dataset', () => {
2829
+ const parser = setupParserWithObjects([
2830
+ {
2831
+ htMeta: {
2832
+ elementId: {type: 'participant' as const, id: 10, version: 50},
2833
+ dataSetNames: ['main', 'atd-unmuted'],
2834
+ },
2835
+ data: {name: 'participant'},
2836
+ },
2837
+ ]);
2838
+
2839
+ // Try to remove the object from main only (it still exists in atd-unmuted)
2840
+ const removalMessage = {
2841
+ dataSets: [createDataSet('main', 16, 1101)],
2842
+ visibleDataSetsUrl,
2843
+ locusUrl,
2844
+ locusStateElements: [
2845
+ {
2846
+ htMeta: {
2847
+ elementId: {type: 'participant' as const, id: 10, version: 50},
2848
+ dataSetNames: ['main'],
2849
+ },
2850
+ data: null, // removal
2851
+ },
2852
+ ],
2853
+ };
2854
+
2855
+ parser.handleMessage(removalMessage, 'removal from one dataset');
2856
+
2857
+ // Callback should not be called because object still exists in atd-unmuted
2858
+ assert.notCalled(callback);
2859
+ });
2860
+
2861
+ it('allows removal when object does not exist in any dataset', () => {
2862
+ const parser = setupParserWithObjects([]);
2863
+
2864
+ // Stub updateItems to return true (simulating that the removal was "applied")
2865
+ sinon.stub(parser.dataSets.main.hashTree, 'updateItems').returns([true]);
2866
+
2867
+ // Try to remove an object that doesn't exist anywhere
2868
+ const removalMessage = {
2869
+ dataSets: [createDataSet('main', 16, 1100)],
2870
+ visibleDataSetsUrl,
2871
+ locusUrl,
2872
+ locusStateElements: [
2873
+ {
2874
+ htMeta: {
2875
+ elementId: {type: 'participant' as const, id: 99, version: 10},
2876
+ dataSetNames: ['main'],
2877
+ },
2878
+ data: null, // removal
2879
+ },
2880
+ ],
2881
+ };
2882
+
2883
+ parser.handleMessage(removalMessage, 'removal of non-existent object');
2884
+
2885
+ // Callback should be called with the removal
2886
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
2887
+ updatedObjects: [
2888
+ {
2889
+ htMeta: {
2890
+ elementId: {type: 'participant', id: 99, version: 10},
2891
+ dataSetNames: ['main'],
2892
+ },
2893
+ data: null,
2894
+ },
2895
+ ],
2896
+ });
2897
+ });
2898
+
2899
+ it('filters out removal when object exists in another dataset with newer version', () => {
2900
+ const parser = createHashTreeParser();
2901
+
2902
+ // Setup: Add object to main with version 40
2903
+ parser.handleMessage(
2904
+ {
2905
+ dataSets: [createDataSet('main', 16, 1100)],
2906
+ visibleDataSetsUrl,
2907
+ locusUrl,
2908
+ locusStateElements: [
2909
+ {
2910
+ htMeta: {
2911
+ elementId: {type: 'participant' as const, id: 10, version: 40},
2912
+ dataSetNames: ['main'],
2913
+ },
2914
+ data: {name: 'participant v40'},
2915
+ },
2916
+ ],
2917
+ },
2918
+ 'setup main'
2919
+ );
2920
+
2921
+ // Add object to atd-unmuted with version 50
2922
+ parser.handleMessage(
2923
+ {
2924
+ dataSets: [createDataSet('atd-unmuted', 16, 3100)],
2925
+ visibleDataSetsUrl,
2926
+ locusUrl,
2927
+ locusStateElements: [
2928
+ {
2929
+ htMeta: {
2930
+ elementId: {type: 'participant' as const, id: 10, version: 50},
2931
+ dataSetNames: ['atd-unmuted'],
2932
+ },
2933
+ data: {name: 'participant v50'},
2934
+ },
2935
+ ],
2936
+ },
2937
+ 'setup atd-unmuted'
2938
+ );
2939
+ callback.resetHistory();
2940
+
2941
+ // Try to remove with version 40 from main
2942
+ const removalMessage = {
2943
+ dataSets: [createDataSet('main', 16, 1101)],
2944
+ visibleDataSetsUrl,
2945
+ locusUrl,
2946
+ locusStateElements: [
2947
+ {
2948
+ htMeta: {
2949
+ elementId: {type: 'participant' as const, id: 10, version: 40},
2950
+ dataSetNames: ['main'],
2951
+ },
2952
+ data: null, // removal
2953
+ },
2954
+ ],
2955
+ };
2956
+
2957
+ parser.handleMessage(removalMessage, 'removal with older version');
2958
+
2959
+ // Callback should not be called because object still exists with newer version
2960
+ assert.notCalled(callback);
2961
+ });
2962
+
2963
+ it('filters mixed updates correctly - some pass, some filtered', () => {
2964
+ const parser = setupParserWithObjects([
2965
+ {
2966
+ htMeta: {
2967
+ elementId: {type: 'participant' as const, id: 1, version: 100},
2968
+ dataSetNames: ['main'],
2969
+ },
2970
+ data: {name: 'participant 1'},
2971
+ },
2972
+ {
2973
+ htMeta: {
2974
+ elementId: {type: 'participant' as const, id: 2, version: 50},
2975
+ dataSetNames: ['atd-unmuted'],
2976
+ },
2977
+ data: {name: 'participant 2'},
2978
+ },
2979
+ ]);
2980
+
2981
+ // Send mixed updates
2982
+ const mixedMessage = {
2983
+ dataSets: [createDataSet('main', 16, 1101)],
2984
+ visibleDataSetsUrl,
2985
+ locusUrl,
2986
+ locusStateElements: [
2987
+ {
2988
+ htMeta: {
2989
+ elementId: {type: 'participant' as const, id: 1, version: 110}, // newer version - should pass
2990
+ dataSetNames: ['main'],
2991
+ },
2992
+ data: {name: 'updated'},
2993
+ },
2994
+ {
2995
+ htMeta: {
2996
+ elementId: {type: 'participant' as const, id: 1, version: 90}, // older version - should be filtered
2997
+ dataSetNames: ['main'],
2998
+ },
2999
+ data: {name: 'old'},
3000
+ },
3001
+ {
3002
+ htMeta: {
3003
+ elementId: {type: 'participant' as const, id: 3, version: 10}, // new object - should pass
3004
+ dataSetNames: ['main'],
3005
+ },
3006
+ data: {name: 'new'},
3007
+ },
3008
+ {
3009
+ htMeta: {
3010
+ elementId: {type: 'participant' as const, id: 2, version: 50}, // removal but exists in atd-unmuted - should be filtered
3011
+ dataSetNames: ['main'],
3012
+ },
3013
+ data: null,
3014
+ },
3015
+ ],
3016
+ };
3017
+
3018
+ parser.handleMessage(mixedMessage, 'mixed updates');
3019
+
3020
+ // Callback should be called with only the valid updates (participant 1 v110 and participant 3 v10)
3021
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
3022
+ updatedObjects: [
3023
+ {
3024
+ htMeta: {
3025
+ elementId: {type: 'participant', id: 1, version: 110},
3026
+ dataSetNames: ['main'],
3027
+ },
3028
+ data: {name: 'updated'},
3029
+ },
3030
+ {
3031
+ htMeta: {
3032
+ elementId: {type: 'participant', id: 3, version: 10},
3033
+ dataSetNames: ['main'],
3034
+ },
3035
+ data: {name: 'new'},
3036
+ },
3037
+ ],
3038
+ });
3039
+ });
3040
+
3041
+ it('does not call callback when all updates are filtered out', () => {
3042
+ const parser = setupParserWithObjects([
3043
+ {
3044
+ htMeta: {
3045
+ elementId: {type: 'locus' as const, id: 5, version: 100},
3046
+ dataSetNames: ['main'],
3047
+ },
3048
+ data: {existingField: 'existing'},
3049
+ },
3050
+ ]);
3051
+
3052
+ // Try to update with older versions (all should be filtered)
3053
+ const updateMessage = {
3054
+ dataSets: [createDataSet('main', 16, 1101)],
3055
+ visibleDataSetsUrl,
3056
+ locusUrl,
3057
+ locusStateElements: [
3058
+ {
3059
+ htMeta: {
3060
+ elementId: {type: 'locus' as const, id: 5, version: 80},
3061
+ dataSetNames: ['main'],
3062
+ },
3063
+ data: {someField: 'value'},
3064
+ },
3065
+ {
3066
+ htMeta: {
3067
+ elementId: {type: 'locus' as const, id: 5, version: 90},
3068
+ dataSetNames: ['main'],
3069
+ },
3070
+ data: {someField: 'another value'},
3071
+ },
3072
+ ],
3073
+ };
3074
+
3075
+ parser.handleMessage(updateMessage, 'all filtered updates');
3076
+
3077
+ // Callback should not be called at all
3078
+ assert.notCalled(callback);
3079
+ });
3080
+
3081
+ it('checks all visible datasets when filtering', () => {
3082
+ const parser = createHashTreeParser();
3083
+
3084
+ // Setup: Add same object to multiple datasets with different versions
3085
+ parser.handleMessage(
3086
+ {
3087
+ dataSets: [createDataSet('main', 16, 1100)],
3088
+ visibleDataSetsUrl,
3089
+ locusUrl,
3090
+ locusStateElements: [
3091
+ {
3092
+ htMeta: {
3093
+ elementId: {type: 'participant' as const, id: 10, version: 100},
3094
+ dataSetNames: ['main'],
3095
+ },
3096
+ data: {name: 'v100'},
3097
+ },
3098
+ ],
3099
+ },
3100
+ 'setup main'
3101
+ );
3102
+
3103
+ parser.handleMessage(
3104
+ {
3105
+ dataSets: [createDataSet('self', 1, 2100)],
3106
+ visibleDataSetsUrl,
3107
+ locusUrl,
3108
+ locusStateElements: [
3109
+ {
3110
+ htMeta: {
3111
+ elementId: {type: 'participant' as const, id: 10, version: 120}, // highest
3112
+ dataSetNames: ['self'],
3113
+ },
3114
+ data: {name: 'v120'},
3115
+ },
3116
+ ],
3117
+ },
3118
+ 'setup self'
3119
+ );
3120
+
3121
+ parser.handleMessage(
3122
+ {
3123
+ dataSets: [createDataSet('atd-unmuted', 16, 3100)],
3124
+ visibleDataSetsUrl,
3125
+ locusUrl,
3126
+ locusStateElements: [
3127
+ {
3128
+ htMeta: {
3129
+ elementId: {type: 'participant' as const, id: 10, version: 110},
3130
+ dataSetNames: ['atd-unmuted'],
3131
+ },
3132
+ data: {name: 'v110'},
3133
+ },
3134
+ ],
3135
+ },
3136
+ 'setup atd-unmuted'
3137
+ );
3138
+ callback.resetHistory();
3139
+
3140
+ // Try to update with version 115 (newer than main and atd-unmuted, but older than self)
3141
+ const updateMessage = {
3142
+ dataSets: [createDataSet('main', 16, 1101)],
3143
+ visibleDataSetsUrl,
3144
+ locusUrl,
3145
+ locusStateElements: [
3146
+ {
3147
+ htMeta: {
3148
+ elementId: {type: 'participant' as const, id: 10, version: 115},
3149
+ dataSetNames: ['main'],
3150
+ },
3151
+ data: {name: 'update'},
3152
+ },
3153
+ ],
3154
+ };
3155
+
3156
+ parser.handleMessage(updateMessage, 'update with v115');
3157
+
3158
+ // Should be filtered out because self dataset has version 120
3159
+ assert.notCalled(callback);
3160
+ });
3161
+
3162
+ it('does not call callback for empty locusStateElements', () => {
3163
+ const parser = setupParserWithObjects([]);
3164
+
3165
+ const emptyMessage = {
3166
+ dataSets: [createDataSet('main', 16, 1100)],
3167
+ visibleDataSetsUrl,
3168
+ locusUrl,
3169
+ locusStateElements: [],
3170
+ };
3171
+
3172
+ parser.handleMessage(emptyMessage, 'empty elements');
3173
+
3174
+ assert.notCalled(callback);
3175
+ });
3176
+
3177
+ it('always calls callback for MEETING_ENDED regardless of filtering', () => {
3178
+ const parser = setupParserWithObjects([
3179
+ {
3180
+ htMeta: {
3181
+ elementId: {type: 'locus' as const, id: 0, version: 100},
3182
+ dataSetNames: ['main'],
3183
+ },
3184
+ data: {info: 'data'},
3185
+ },
3186
+ ]);
3187
+
3188
+ // Send a sentinel END MEETING message
3189
+ const sentinelMessage = createHeartbeatMessage(
3190
+ 'main',
3191
+ 1,
3192
+ parser.dataSets.main.version + 1,
3193
+ EMPTY_HASH
3194
+ );
3195
+
3196
+ parser.handleMessage(sentinelMessage as any, 'sentinel message');
3197
+
3198
+ // Callback should be called with MEETING_ENDED
3199
+ assert.calledOnceWithExactly(callback, LocusInfoUpdateType.MEETING_ENDED, {
3200
+ updatedObjects: undefined,
3201
+ });
3202
+ });
1523
3203
  });
1524
3204
  });