@webex/plugin-meetings 3.9.0-webinar5k.1 → 3.9.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 (83) hide show
  1. package/dist/breakouts/breakout.js +1 -1
  2. package/dist/breakouts/index.js +1 -1
  3. package/dist/constants.js +16 -0
  4. package/dist/constants.js.map +1 -1
  5. package/dist/interpretation/index.js +1 -1
  6. package/dist/interpretation/siLanguage.js +1 -1
  7. package/dist/locus-info/index.js +40 -328
  8. package/dist/locus-info/index.js.map +1 -1
  9. package/dist/meeting/in-meeting-actions.js +6 -0
  10. package/dist/meeting/in-meeting-actions.js.map +1 -1
  11. package/dist/meeting/index.js +196 -160
  12. package/dist/meeting/index.js.map +1 -1
  13. package/dist/meeting/muteState.js +5 -2
  14. package/dist/meeting/muteState.js.map +1 -1
  15. package/dist/meeting/type.js +7 -0
  16. package/dist/meeting/type.js.map +1 -0
  17. package/dist/meeting/util.js +79 -10
  18. package/dist/meeting/util.js.map +1 -1
  19. package/dist/meetings/index.js +37 -39
  20. package/dist/meetings/index.js.map +1 -1
  21. package/dist/member/types.js.map +1 -1
  22. package/dist/members/collection.js +0 -13
  23. package/dist/members/collection.js.map +1 -1
  24. package/dist/members/index.js +21 -40
  25. package/dist/members/index.js.map +1 -1
  26. package/dist/members/util.js.map +1 -1
  27. package/dist/multistream/mediaRequestManager.js +1 -1
  28. package/dist/multistream/mediaRequestManager.js.map +1 -1
  29. package/dist/multistream/remoteMedia.js +34 -5
  30. package/dist/multistream/remoteMedia.js.map +1 -1
  31. package/dist/multistream/remoteMediaGroup.js +42 -2
  32. package/dist/multistream/remoteMediaGroup.js.map +1 -1
  33. package/dist/types/constants.d.ts +16 -0
  34. package/dist/types/locus-info/index.d.ts +3 -102
  35. package/dist/types/meeting/in-meeting-actions.d.ts +6 -0
  36. package/dist/types/meeting/index.d.ts +23 -28
  37. package/dist/types/meeting/type.d.ts +9 -0
  38. package/dist/types/meeting/util.d.ts +6 -3
  39. package/dist/types/member/types.d.ts +0 -1
  40. package/dist/types/members/collection.d.ts +0 -6
  41. package/dist/types/members/index.d.ts +7 -16
  42. package/dist/types/members/util.d.ts +2 -1
  43. package/dist/types/multistream/remoteMedia.d.ts +20 -1
  44. package/dist/types/multistream/remoteMediaGroup.d.ts +11 -0
  45. package/dist/webinar/index.js +1 -1
  46. package/package.json +22 -24
  47. package/src/constants.ts +16 -2
  48. package/src/locus-info/index.ts +39 -409
  49. package/src/meeting/in-meeting-actions.ts +13 -0
  50. package/src/meeting/index.ts +92 -63
  51. package/src/meeting/muteState.ts +6 -2
  52. package/src/meeting/type.ts +9 -0
  53. package/src/meeting/util.ts +93 -19
  54. package/src/meetings/index.ts +6 -19
  55. package/src/member/types.ts +0 -1
  56. package/src/members/collection.ts +0 -11
  57. package/src/members/index.ts +10 -33
  58. package/src/members/util.ts +2 -1
  59. package/src/multistream/mediaRequestManager.ts +7 -7
  60. package/src/multistream/remoteMedia.ts +34 -4
  61. package/src/multistream/remoteMediaGroup.ts +37 -2
  62. package/test/unit/spec/locus-info/index.js +8 -365
  63. package/test/unit/spec/meeting/in-meeting-actions.ts +6 -0
  64. package/test/unit/spec/meeting/index.js +254 -38
  65. package/test/unit/spec/meeting/utils.js +122 -1
  66. package/test/unit/spec/meetings/index.js +2 -0
  67. package/test/unit/spec/members/index.js +37 -1
  68. package/test/unit/spec/multistream/mediaRequestManager.ts +19 -6
  69. package/test/unit/spec/multistream/remoteMedia.ts +66 -2
  70. package/dist/hashTree/constants.js +0 -23
  71. package/dist/hashTree/constants.js.map +0 -1
  72. package/dist/hashTree/hashTree.js +0 -516
  73. package/dist/hashTree/hashTree.js.map +0 -1
  74. package/dist/hashTree/hashTreeParser.js +0 -521
  75. package/dist/hashTree/hashTreeParser.js.map +0 -1
  76. package/dist/types/hashTree/constants.d.ts +0 -8
  77. package/dist/types/hashTree/hashTree.d.ts +0 -128
  78. package/dist/types/hashTree/hashTreeParser.d.ts +0 -152
  79. package/src/hashTree/constants.ts +0 -12
  80. package/src/hashTree/hashTree.ts +0 -460
  81. package/src/hashTree/hashTreeParser.ts +0 -556
  82. package/test/unit/spec/hashTree/hashTree.ts +0 -394
  83. package/test/unit/spec/hashTree/hashTreeParser.ts +0 -156
@@ -1,460 +0,0 @@
1
- import {XXH3_128} from 'xxh3-ts';
2
- import {EMPTY_HASH} from './constants';
3
-
4
- export type LeafDataItem = {
5
- type: string;
6
- id: number;
7
- version: number;
8
- };
9
-
10
- /**
11
- * HashTree is a data structure that organizes items into leaves based on their IDs,
12
- */
13
- class HashTree {
14
- leaves: Array<Record<string, Record<number, LeafDataItem>>>;
15
-
16
- leafHashes: Array<string>;
17
- readonly numLeaves: number;
18
-
19
- /**
20
- * Constructs a new HashTree.
21
- * @param {LeafDataItem[]} leafData Initial data to populate the tree.
22
- * @param {number} numLeaves The number of leaf nodes in the tree. Must be 0 or a power of 2.
23
- * @throws {Error} If numLeaves is not 0 or a power of 2.
24
- */
25
- constructor(leafData: LeafDataItem[], numLeaves: number) {
26
- // eslint-disable-next-line no-bitwise
27
- if ((numLeaves & (numLeaves - 1)) !== 0) {
28
- throw new Error(`Number of leaves must be a power of 2, saw ${numLeaves}`);
29
- }
30
-
31
- this.numLeaves = numLeaves;
32
- this.leafHashes = new Array(numLeaves).fill(EMPTY_HASH);
33
-
34
- this.leaves = new Array(numLeaves).fill(null).map(() => {
35
- return {};
36
- });
37
-
38
- if (leafData) {
39
- this.putItems(leafData);
40
- }
41
- }
42
-
43
- /**
44
- * Internal logic for adding or updating an item, without computing the leaf hash.
45
- * @param {LeafDataItem} item The item to add or update.
46
- * @returns {{put: boolean, index: (number|null)}} Object indicating if put and the leaf index.
47
- * @private
48
- */
49
- private _putItemInternal(item: LeafDataItem): {put: boolean; index: number | null} {
50
- if (this.numLeaves === 0) {
51
- return {put: false, index: null}; // Cannot add to a tree with 0 leaves
52
- }
53
-
54
- const index = item.id % this.numLeaves;
55
-
56
- if (!this.leaves[index][item.type]) {
57
- this.leaves[index][item.type] = {};
58
- }
59
-
60
- const existingItem = this.leaves[index][item.type][item.id];
61
-
62
- if (!existingItem || existingItem.version < item.version) {
63
- this.leaves[index][item.type][item.id] = item;
64
-
65
- return {put: true, index};
66
- }
67
-
68
- return {put: false, index: null};
69
- }
70
-
71
- /**
72
- * Adds or updates a single item in the hash tree.
73
- * @param {LeafDataItem} item The item to add or update.
74
- * @returns {boolean} True if the item was added or updated, false otherwise (e.g., older version or tree has 0 leaves).
75
- */
76
- putItem(item: LeafDataItem): boolean {
77
- const {put, index} = this._putItemInternal(item);
78
-
79
- if (put && index !== null) {
80
- this.computeLeafHash(index);
81
- }
82
-
83
- return put;
84
- }
85
-
86
- /**
87
- * Adds or updates multiple items in the hash tree.
88
- * @param {LeafDataItem[]} items The array of items to add or update.
89
- * @returns {boolean[]} An array of booleans indicating success for each item.
90
- */
91
- putItems(items: LeafDataItem[]): boolean[] {
92
- if (this.numLeaves === 0 && items.length > 0) {
93
- // Cannot add items to a tree with 0 leaves.
94
- return items.map(() => false);
95
- }
96
- const results: boolean[] = [];
97
- const changedLeafIndexes = new Set<number>();
98
-
99
- items.forEach((item) => {
100
- const {put, index} = this._putItemInternal(item);
101
- results.push(put);
102
- if (put && index !== null) {
103
- changedLeafIndexes.add(index);
104
- }
105
- });
106
-
107
- changedLeafIndexes.forEach((index) => {
108
- this.computeLeafHash(index);
109
- });
110
-
111
- return results;
112
- }
113
-
114
- /**
115
- * Internal logic for removing an item, without computing the leaf hash.
116
- * @param {LeafDataItem} item The item to remove.
117
- * @returns {{removed: boolean, index: (number|null)}} Object indicating if removed and the leaf index.
118
- * @private
119
- */
120
- private _removeItemInternal(item: LeafDataItem): {removed: boolean; index: number | null} {
121
- if (this.numLeaves === 0) {
122
- return {removed: false, index: null};
123
- }
124
-
125
- const index = item.id % this.numLeaves;
126
-
127
- if (
128
- this.leaves[index] &&
129
- this.leaves[index][item.type] &&
130
- this.leaves[index][item.type][item.id]
131
- ) {
132
- const existingItem = this.leaves[index][item.type][item.id];
133
- if (
134
- existingItem.id === item.id &&
135
- existingItem.type === item.type &&
136
- existingItem.version <= item.version
137
- ) {
138
- delete this.leaves[index][item.type][item.id];
139
- if (Object.keys(this.leaves[index][item.type]).length === 0) {
140
- delete this.leaves[index][item.type];
141
- }
142
-
143
- return {removed: true, index};
144
- }
145
- }
146
-
147
- return {removed: false, index: null};
148
- }
149
-
150
- /**
151
- * Removes a single item from the hash tree.
152
- * The removal is based on matching type, id, and the provided item's version
153
- * being greater than or equal to the existing item's version.
154
- * @param {LeafDataItem} item The item to remove.
155
- * @returns {boolean} True if the item was removed, false otherwise.
156
- */
157
- removeItem(item: LeafDataItem): boolean {
158
- const {removed, index} = this._removeItemInternal(item);
159
-
160
- if (removed && index !== null) {
161
- this.computeLeafHash(index);
162
- }
163
-
164
- return removed;
165
- }
166
-
167
- /**
168
- * Removes multiple items from the hash tree.
169
- * @param {LeafDataItem[]} items The array of items to remove.
170
- * @returns {boolean[]} An array of booleans indicating success for each item.
171
- */
172
- removeItems(items: LeafDataItem[]): boolean[] {
173
- if (this.numLeaves === 0 && items.length > 0) {
174
- return items.map(() => false);
175
- }
176
-
177
- const results: boolean[] = [];
178
- const changedLeafIndexes = new Set<number>();
179
-
180
- items.forEach((item) => {
181
- const {removed, index} = this._removeItemInternal(item);
182
- results.push(removed);
183
- if (removed && index !== null) {
184
- changedLeafIndexes.add(index);
185
- }
186
- });
187
-
188
- changedLeafIndexes.forEach((index) => {
189
- this.computeLeafHash(index);
190
- });
191
-
192
- return results;
193
- }
194
-
195
- /**
196
- * Updates multiple items in the hash tree.
197
- * This method can handle both adding and removing items based on the `operation` flag.
198
- *
199
- * @param {object[]} itemUpdates An array of objects containing `operation` flag and the `item` to update.
200
- * @returns {boolean[]} An array of booleans indicating success for each operation.
201
- */
202
- updateItems(itemUpdates: {operation: 'update' | 'remove'; item: LeafDataItem}[]): boolean[] {
203
- if (this.numLeaves === 0 && itemUpdates.length > 0) {
204
- return itemUpdates.map(() => false);
205
- }
206
-
207
- const results: boolean[] = [];
208
- const changedLeafIndexes = new Set<number>();
209
-
210
- itemUpdates.forEach(({operation, item}) => {
211
- if (operation === 'remove') {
212
- const {removed, index} = this._removeItemInternal(item);
213
- results.push(removed);
214
- if (removed && index !== null) {
215
- changedLeafIndexes.add(index);
216
- }
217
- } else {
218
- const {put, index} = this._putItemInternal(item);
219
- results.push(put);
220
- if (put && index !== null) {
221
- changedLeafIndexes.add(index);
222
- }
223
- }
224
- });
225
-
226
- changedLeafIndexes.forEach((index) => {
227
- this.computeLeafHash(index);
228
- });
229
-
230
- return results;
231
- }
232
-
233
- /**
234
- * Computes the hash for a specific leaf.
235
- * The hash is based on the sorted items within the leaf.
236
- * @param {number} index The index of the leaf to compute the hash for.
237
- * @returns {void}
238
- */
239
- computeLeafHash(index: number) {
240
- const leafContent = this.leaves[index];
241
-
242
- const totalItemsCount = Object.keys(leafContent).reduce((count, type) => {
243
- return count + Object.keys(leafContent[type]).length;
244
- }, 0);
245
- const buffer = Buffer.alloc(totalItemsCount * 16);
246
-
247
- let offset = 0;
248
-
249
- // iterate through the item types lexicographically
250
- const itemTypes = Object.keys(leafContent).sort();
251
- itemTypes.forEach((type) => {
252
- // iterate through the items of this type in ascending order of ID
253
- const items = Object.values(leafContent[type]).sort(
254
- (a: LeafDataItem, b: LeafDataItem) => a.id - b.id
255
- );
256
-
257
- // add all the items id and version to the hasher
258
- items.forEach((item: LeafDataItem) => {
259
- buffer.writeBigInt64LE(BigInt(item.id), offset);
260
- buffer.writeBigInt64LE(BigInt(item.version), offset + 8);
261
-
262
- offset += 16;
263
- });
264
- });
265
-
266
- this.leafHashes[index] = XXH3_128(buffer, BigInt(0)).toString(16);
267
- }
268
-
269
- /**
270
- * Computes all internal and leaf node hashes of the tree.
271
- * Internal node hashes are computed bottom-up from the leaf hashes.
272
- * @returns {string[]} An array of hash strings, with internal node hashes first, followed by leaf hashes.
273
- * Returns `[EMPTY_HASH]` if the tree has 0 leaves.
274
- */
275
- computeTreeHashes(): string[] {
276
- if (this.numLeaves === 0) {
277
- return [EMPTY_HASH];
278
- }
279
-
280
- let currentLevelHashes = [...this.leafHashes];
281
- const allHashes = [];
282
-
283
- while (currentLevelHashes.length > 1) {
284
- const nextLevelHashes: string[] = [];
285
- for (let i = 0; i < currentLevelHashes.length; i += 2) {
286
- const leftHash = currentLevelHashes[i];
287
- const rightHash = i + 1 < currentLevelHashes.length ? currentLevelHashes[i + 1] : leftHash;
288
-
289
- const input = Buffer.concat([
290
- Buffer.from(leftHash, 'hex').subarray(0, 8).reverse(),
291
- Buffer.from(leftHash, 'hex').subarray(8, 16).reverse(),
292
- Buffer.from(rightHash, 'hex').subarray(0, 8).reverse(),
293
- Buffer.from(rightHash, 'hex').subarray(8, 16).reverse(),
294
- ]);
295
-
296
- nextLevelHashes.push(XXH3_128(input, BigInt(0)).toString(16));
297
- }
298
- currentLevelHashes = nextLevelHashes;
299
- allHashes.unshift(...currentLevelHashes);
300
- }
301
-
302
- return [...allHashes, ...this.leafHashes];
303
- }
304
-
305
- /**
306
- * Returns all hashes in the tree (internal nodes then leaf nodes).
307
- * @returns {string[]} An array of hash strings.
308
- */
309
- getHashes(): string[] {
310
- return this.computeTreeHashes();
311
- }
312
-
313
- /**
314
- * Computes and returns the hash value of the root node.
315
- * @returns {string} The root hash of the entire tree. Returns `EMPTY_HASH` if the tree has 0 leaves.
316
- */
317
- getRootHash(): string {
318
- if (this.numLeaves === 0) {
319
- return EMPTY_HASH;
320
- }
321
-
322
- return this.computeTreeHashes()[0];
323
- }
324
-
325
- /**
326
- * Gets the number of leaves in the tree.
327
- * @returns {number} The number of leaves.
328
- */
329
- getLeafCount(): number {
330
- return this.numLeaves;
331
- }
332
-
333
- /**
334
- * Calculates the total number of items stored in the tree.
335
- * @returns {number} The total number of items.
336
- */
337
- getTotalItemCount(): number {
338
- let count = 0;
339
- for (const leaf of this.leaves) {
340
- for (const type of Object.keys(leaf)) {
341
- count += Object.keys(leaf[type]).length;
342
- }
343
- }
344
-
345
- return count;
346
- }
347
-
348
- /**
349
- * Retrieves all data items from a specific leaf.
350
- * @param {number} leafIndex The index of the leaf.
351
- * @returns {LeafDataItem[]} An array of LeafDataItem in the specified leaf, sorted by ID,
352
- * or an empty array if the index is invalid or leaf is empty.
353
- */
354
- getLeafData(leafIndex: number): LeafDataItem[] {
355
- if (leafIndex < 0 || leafIndex >= this.numLeaves) {
356
- return [];
357
- }
358
- const leafContent = this.leaves[leafIndex];
359
- const items: LeafDataItem[] = [];
360
- for (const type of Object.keys(leafContent)) {
361
- items.push(...Object.values(leafContent[type]));
362
- }
363
- // Optionally sort them if a specific order is required, e.g., by ID
364
- items.sort((a, b) => a.id - b.id);
365
-
366
- return items;
367
- }
368
-
369
- /**
370
- * Resizes the HashTree to have a new number of leaf nodes, redistributing all existing items.
371
- * @param {number} newNumLeaves The new number of leaf nodes (must be 0 or a power of 2).
372
- * @returns {boolean} true if the tree was resized, false if the size didn't change.
373
- * @throws {Error} if newNumLeaves is not 0 or a power of 2.
374
- */
375
- resize(newNumLeaves: number): boolean {
376
- // eslint-disable-next-line no-bitwise
377
- if (newNumLeaves < 0 || (newNumLeaves !== 0 && (newNumLeaves & (newNumLeaves - 1)) !== 0)) {
378
- throw new Error('New number of leaves must be 0 or a power of 2');
379
- }
380
-
381
- if (newNumLeaves === this.numLeaves) {
382
- return false;
383
- }
384
-
385
- const allItems: LeafDataItem[] = [];
386
- for (const leaf of this.leaves) {
387
- for (const type of Object.keys(leaf)) {
388
- allItems.push(...Object.values(leaf[type]));
389
- }
390
- }
391
-
392
- // Re-initialize
393
- // eslint-disable-next-line no-extra-semi
394
- (this as any).numLeaves = newNumLeaves; // Type assertion to update readonly property
395
- this.leafHashes = new Array(newNumLeaves).fill(EMPTY_HASH);
396
- this.leaves = new Array(newNumLeaves).fill(null).map(() => ({}));
397
-
398
- if (newNumLeaves > 0) {
399
- this.putItems(allItems); // Re-add items which will be re-assigned to leaves and re-hashed
400
- }
401
-
402
- return true;
403
- }
404
-
405
- /**
406
- * Compares the tree's leaf hashes with an external set of hashes and returns the indices of differing leaf nodes.
407
- * The externalHashes array is expected to contain all node hashes (internal followed by leaves),
408
- * similar to the output of getHashes().
409
- * @param {string[]} externalHashes An array of hash strings (internal node hashes then leaf hashes).
410
- * @returns {number[]} An array of indices of the leaf nodes that have different hashes.
411
- */
412
- diffHashes(externalHashes: string[]): number[] {
413
- if (this.numLeaves === 0) {
414
- // If this tree is empty, its hash is EMPTY_HASH.
415
- // It differs if externalHashes is not a single EMPTY_HASH.
416
- if (externalHashes && externalHashes.length === 1 && externalHashes[0] === EMPTY_HASH) {
417
- return []; // No differences
418
- }
419
- // An empty tree has no leaves to differ, so return an empty array
420
- // as no specific leaf indexes are different.
421
-
422
- return [];
423
- }
424
-
425
- // todo: why is this not taking advantage of the tree structure and comparing from the root down?
426
-
427
- // We are interested in comparing the leaf hashes part.
428
- // The externalHashes array should also have its leaf hashes at the end.
429
- const differingLeafIndexes: number[] = [];
430
- // Calculate where the leaf hashes would start in the externalHashes array,
431
- // assuming it has the same number of leaves as this tree.
432
- const externalLeafHashesStart = externalHashes.length - this.numLeaves;
433
-
434
- if (externalLeafHashesStart < 0) {
435
- // externalHashes is too short to contain a complete set of leaf hashes
436
- // corresponding to this tree's numLeaves.
437
- // In this case, consider all of this tree's leaves as "different".
438
- for (let i = 0; i < this.numLeaves; i += 1) {
439
- differingLeafIndexes.push(i);
440
- }
441
-
442
- return differingLeafIndexes;
443
- }
444
-
445
- // Compare each leaf hash
446
- for (let i = 0; i < this.numLeaves; i += 1) {
447
- const ownLeafHash = this.leafHashes[i];
448
- // externalLeafHash might be undefined if externalHashes is shorter than expected
449
- // but externalLeafHashesStart was non-negative, implying a structural mismatch.
450
- const externalLeafHash = externalHashes[externalLeafHashesStart + i];
451
- if (ownLeafHash !== externalLeafHash) {
452
- differingLeafIndexes.push(i);
453
- }
454
- }
455
-
456
- return differingLeafIndexes;
457
- }
458
- }
459
-
460
- export default HashTree;