@webex/plugin-meetings 3.12.0-task-refactor.1 → 3.12.0-webex-services-ready.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +197 -0
  3. package/dist/aiEnableRequest/index.js.map +1 -0
  4. package/dist/aiEnableRequest/utils.js +36 -0
  5. package/dist/aiEnableRequest/utils.js.map +1 -0
  6. package/dist/annotation/index.js +14 -5
  7. package/dist/annotation/index.js.map +1 -1
  8. package/dist/breakouts/breakout.js +8 -3
  9. package/dist/breakouts/breakout.js.map +1 -1
  10. package/dist/breakouts/index.js +26 -2
  11. package/dist/breakouts/index.js.map +1 -1
  12. package/dist/common/errors/webex-errors.js +49 -5
  13. package/dist/common/errors/webex-errors.js.map +1 -1
  14. package/dist/config.js +9 -3
  15. package/dist/config.js.map +1 -1
  16. package/dist/constants.js +59 -10
  17. package/dist/constants.js.map +1 -1
  18. package/dist/controls-options-manager/constants.js +11 -1
  19. package/dist/controls-options-manager/constants.js.map +1 -1
  20. package/dist/controls-options-manager/index.js +67 -29
  21. package/dist/controls-options-manager/index.js.map +1 -1
  22. package/dist/controls-options-manager/util.js +91 -0
  23. package/dist/controls-options-manager/util.js.map +1 -1
  24. package/dist/hashTree/constants.js +34 -0
  25. package/dist/hashTree/constants.js.map +1 -0
  26. package/dist/hashTree/hashTree.js +533 -0
  27. package/dist/hashTree/hashTree.js.map +1 -0
  28. package/dist/hashTree/hashTreeParser.js +2068 -36
  29. package/dist/hashTree/hashTreeParser.js.map +1 -1
  30. package/dist/hashTree/types.js +13 -3
  31. package/dist/hashTree/types.js.map +1 -1
  32. package/dist/hashTree/utils.js +111 -0
  33. package/dist/hashTree/utils.js.map +1 -0
  34. package/dist/index.js +18 -2
  35. package/dist/index.js.map +1 -1
  36. package/dist/interceptors/constant.js +12 -0
  37. package/dist/interceptors/constant.js.map +1 -0
  38. package/dist/interceptors/dataChannelAuthToken.js +350 -0
  39. package/dist/interceptors/dataChannelAuthToken.js.map +1 -0
  40. package/dist/interceptors/index.js +7 -0
  41. package/dist/interceptors/index.js.map +1 -1
  42. package/dist/interceptors/locusRetry.js +23 -8
  43. package/dist/interceptors/locusRetry.js.map +1 -1
  44. package/dist/interceptors/locusRouteToken.js +27 -5
  45. package/dist/interceptors/locusRouteToken.js.map +1 -1
  46. package/dist/interceptors/utils.js +27 -0
  47. package/dist/interceptors/utils.js.map +1 -0
  48. package/dist/interpretation/index.js +11 -2
  49. package/dist/interpretation/index.js.map +1 -1
  50. package/dist/interpretation/interpretation.types.js +7 -0
  51. package/dist/interpretation/interpretation.types.js.map +1 -0
  52. package/dist/interpretation/siLanguage.js +1 -1
  53. package/dist/locus-info/controlsUtils.js +11 -4
  54. package/dist/locus-info/controlsUtils.js.map +1 -1
  55. package/dist/locus-info/index.js +896 -277
  56. package/dist/locus-info/index.js.map +1 -1
  57. package/dist/locus-info/infoUtils.js +36 -5
  58. package/dist/locus-info/infoUtils.js.map +1 -1
  59. package/dist/locus-info/selfUtils.js +1 -0
  60. package/dist/locus-info/selfUtils.js.map +1 -1
  61. package/dist/locus-info/types.js +19 -0
  62. package/dist/locus-info/types.js.map +1 -1
  63. package/dist/media/MediaConnectionAwaiter.js +72 -3
  64. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  65. package/dist/media/index.js +8 -2
  66. package/dist/media/index.js.map +1 -1
  67. package/dist/media/properties.js +5 -2
  68. package/dist/media/properties.js.map +1 -1
  69. package/dist/meeting/in-meeting-actions.js +11 -1
  70. package/dist/meeting/in-meeting-actions.js.map +1 -1
  71. package/dist/meeting/index.js +2075 -1096
  72. package/dist/meeting/index.js.map +1 -1
  73. package/dist/meeting/locusMediaRequest.js +229 -82
  74. package/dist/meeting/locusMediaRequest.js.map +1 -1
  75. package/dist/meeting/muteState.js +10 -1
  76. package/dist/meeting/muteState.js.map +1 -1
  77. package/dist/meeting/request.js +55 -2
  78. package/dist/meeting/request.js.map +1 -1
  79. package/dist/meeting/request.type.js.map +1 -1
  80. package/dist/meeting/util.js +168 -5
  81. package/dist/meeting/util.js.map +1 -1
  82. package/dist/meeting-info/meeting-info-v2.js +2 -2
  83. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  84. package/dist/meetings/index.js +369 -173
  85. package/dist/meetings/index.js.map +1 -1
  86. package/dist/meetings/meetings.types.js +6 -1
  87. package/dist/meetings/meetings.types.js.map +1 -1
  88. package/dist/meetings/request.js +39 -0
  89. package/dist/meetings/request.js.map +1 -1
  90. package/dist/meetings/util.js +127 -25
  91. package/dist/meetings/util.js.map +1 -1
  92. package/dist/member/index.js +20 -0
  93. package/dist/member/index.js.map +1 -1
  94. package/dist/member/types.js.map +1 -1
  95. package/dist/member/util.js +40 -0
  96. package/dist/member/util.js.map +1 -1
  97. package/dist/members/index.js +101 -43
  98. package/dist/members/index.js.map +1 -1
  99. package/dist/members/util.js +8 -1
  100. package/dist/members/util.js.map +1 -1
  101. package/dist/metrics/constants.js +11 -1
  102. package/dist/metrics/constants.js.map +1 -1
  103. package/dist/multistream/codec/constants.js +63 -0
  104. package/dist/multistream/codec/constants.js.map +1 -0
  105. package/dist/multistream/mediaRequestManager.js +64 -68
  106. package/dist/multistream/mediaRequestManager.js.map +1 -1
  107. package/dist/multistream/receiveSlot.js +9 -0
  108. package/dist/multistream/receiveSlot.js.map +1 -1
  109. package/dist/multistream/remoteMediaManager.js +11 -0
  110. package/dist/multistream/remoteMediaManager.js.map +1 -1
  111. package/dist/multistream/sendSlotManager.js +116 -2
  112. package/dist/multistream/sendSlotManager.js.map +1 -1
  113. package/dist/reachability/clusterReachability.js +171 -18
  114. package/dist/reachability/clusterReachability.js.map +1 -1
  115. package/dist/reachability/index.js +142 -94
  116. package/dist/reachability/index.js.map +1 -1
  117. package/dist/reachability/reachability.types.js +2 -0
  118. package/dist/reachability/reachability.types.js.map +1 -1
  119. package/dist/reachability/reachabilityPeerConnection.js +1 -1
  120. package/dist/reachability/reachabilityPeerConnection.js.map +1 -1
  121. package/dist/reachability/util.js +45 -0
  122. package/dist/reachability/util.js.map +1 -1
  123. package/dist/reactions/reactions.type.js.map +1 -1
  124. package/dist/reconnection-manager/index.js +0 -1
  125. package/dist/reconnection-manager/index.js.map +1 -1
  126. package/dist/recording-controller/index.js +1 -3
  127. package/dist/recording-controller/index.js.map +1 -1
  128. package/dist/types/aiEnableRequest/index.d.ts +5 -0
  129. package/dist/types/aiEnableRequest/utils.d.ts +2 -0
  130. package/dist/types/common/browser-detection.d.ts +1 -0
  131. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  132. package/dist/types/common/events/events-scope.d.ts +1 -0
  133. package/dist/types/common/events/events.d.ts +1 -0
  134. package/dist/types/config.d.ts +7 -2
  135. package/dist/types/constants.d.ts +35 -1
  136. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  137. package/dist/types/controls-options-manager/index.d.ts +16 -0
  138. package/dist/types/hashTree/constants.d.ts +11 -0
  139. package/dist/types/hashTree/hashTree.d.ts +136 -0
  140. package/dist/types/hashTree/hashTreeParser.d.ts +392 -14
  141. package/dist/types/hashTree/types.d.ts +20 -0
  142. package/dist/types/hashTree/utils.d.ts +40 -0
  143. package/dist/types/index.d.ts +4 -0
  144. package/dist/types/interceptors/constant.d.ts +5 -0
  145. package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
  146. package/dist/types/interceptors/index.d.ts +2 -1
  147. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  148. package/dist/types/interceptors/locusRouteToken.d.ts +2 -0
  149. package/dist/types/interceptors/utils.d.ts +1 -0
  150. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  151. package/dist/types/locus-info/index.d.ts +116 -51
  152. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  153. package/dist/types/locus-info/types.d.ts +48 -12
  154. package/dist/types/media/MediaConnectionAwaiter.d.ts +20 -2
  155. package/dist/types/media/properties.d.ts +3 -1
  156. package/dist/types/meeting/in-meeting-actions.d.ts +10 -0
  157. package/dist/types/meeting/index.d.ts +196 -15
  158. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  159. package/dist/types/meeting/request.d.ts +17 -1
  160. package/dist/types/meeting/request.type.d.ts +5 -0
  161. package/dist/types/meeting/util.d.ts +40 -0
  162. package/dist/types/meeting-info/util.d.ts +1 -0
  163. package/dist/types/meeting-info/utilv2.d.ts +1 -0
  164. package/dist/types/meetings/index.d.ts +34 -20
  165. package/dist/types/meetings/meetings.types.d.ts +15 -0
  166. package/dist/types/meetings/request.d.ts +14 -0
  167. package/dist/types/member/index.d.ts +2 -0
  168. package/dist/types/member/types.d.ts +5 -4
  169. package/dist/types/member/util.d.ts +14 -0
  170. package/dist/types/members/index.d.ts +15 -2
  171. package/dist/types/members/util.d.ts +1 -5
  172. package/dist/types/metrics/constants.d.ts +10 -0
  173. package/dist/types/multistream/codec/constants.d.ts +7 -0
  174. package/dist/types/multistream/mediaRequestManager.d.ts +20 -26
  175. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  176. package/dist/types/reachability/clusterReachability.d.ts +33 -6
  177. package/dist/types/reachability/index.d.ts +10 -3
  178. package/dist/types/reachability/reachability.types.d.ts +7 -0
  179. package/dist/types/reachability/util.d.ts +17 -0
  180. package/dist/types/reactions/reactions.type.d.ts +4 -0
  181. package/dist/types/recording-controller/util.d.ts +5 -5
  182. package/dist/types/roap/index.d.ts +1 -1
  183. package/dist/types/webinar/utils.d.ts +6 -0
  184. package/dist/webinar/index.js +585 -164
  185. package/dist/webinar/index.js.map +1 -1
  186. package/dist/webinar/utils.js +25 -0
  187. package/dist/webinar/utils.js.map +1 -0
  188. package/package.json +26 -24
  189. package/src/aiEnableRequest/README.md +84 -0
  190. package/src/aiEnableRequest/index.ts +186 -0
  191. package/src/aiEnableRequest/utils.ts +25 -0
  192. package/src/annotation/index.ts +27 -7
  193. package/src/breakouts/breakout.ts +3 -1
  194. package/src/breakouts/index.ts +31 -0
  195. package/src/common/errors/webex-errors.ts +50 -3
  196. package/src/config.ts +7 -2
  197. package/src/constants.ts +49 -3
  198. package/src/controls-options-manager/constants.ts +14 -1
  199. package/src/controls-options-manager/index.ts +87 -28
  200. package/src/controls-options-manager/util.ts +81 -1
  201. package/src/hashTree/constants.ts +26 -0
  202. package/src/hashTree/hashTree.ts +480 -0
  203. package/src/hashTree/hashTreeParser.ts +1911 -29
  204. package/src/hashTree/types.ts +24 -1
  205. package/src/hashTree/utils.ts +98 -0
  206. package/src/index.ts +14 -1
  207. package/src/interceptors/constant.ts +6 -0
  208. package/src/interceptors/dataChannelAuthToken.ts +246 -0
  209. package/src/interceptors/index.ts +2 -1
  210. package/src/interceptors/locusRetry.ts +25 -4
  211. package/src/interceptors/locusRouteToken.ts +22 -5
  212. package/src/interceptors/utils.ts +16 -0
  213. package/src/interpretation/index.ts +29 -11
  214. package/src/interpretation/interpretation.types.ts +11 -0
  215. package/src/locus-info/controlsUtils.ts +20 -1
  216. package/src/locus-info/index.ts +958 -250
  217. package/src/locus-info/infoUtils.ts +41 -6
  218. package/src/locus-info/selfUtils.ts +1 -0
  219. package/src/locus-info/types.ts +51 -12
  220. package/src/media/MediaConnectionAwaiter.ts +62 -5
  221. package/src/media/index.ts +10 -1
  222. package/src/media/properties.ts +4 -1
  223. package/src/meeting/in-meeting-actions.ts +20 -0
  224. package/src/meeting/index.ts +1025 -146
  225. package/src/meeting/locusMediaRequest.ts +106 -6
  226. package/src/meeting/muteState.ts +10 -1
  227. package/src/meeting/request.ts +53 -0
  228. package/src/meeting/request.type.ts +6 -0
  229. package/src/meeting/util.ts +207 -7
  230. package/src/meeting-info/meeting-info-v2.ts +4 -2
  231. package/src/meetings/index.ts +307 -132
  232. package/src/meetings/meetings.types.ts +19 -0
  233. package/src/meetings/request.ts +43 -0
  234. package/src/meetings/util.ts +127 -13
  235. package/src/member/index.ts +20 -0
  236. package/src/member/types.ts +1 -0
  237. package/src/member/util.ts +41 -0
  238. package/src/members/index.ts +70 -7
  239. package/src/members/util.ts +12 -4
  240. package/src/metrics/constants.ts +11 -0
  241. package/src/multistream/codec/constants.ts +58 -0
  242. package/src/multistream/mediaRequestManager.ts +117 -76
  243. package/src/multistream/receiveSlot.ts +18 -0
  244. package/src/multistream/remoteMediaManager.ts +13 -0
  245. package/src/multistream/sendSlotManager.ts +97 -3
  246. package/src/reachability/clusterReachability.ts +156 -29
  247. package/src/reachability/index.ts +62 -17
  248. package/src/reachability/reachability.types.ts +11 -0
  249. package/src/reachability/reachabilityPeerConnection.ts +3 -1
  250. package/src/reachability/util.ts +36 -0
  251. package/src/reactions/reactions.type.ts +4 -0
  252. package/src/reconnection-manager/index.ts +0 -1
  253. package/src/recording-controller/index.ts +1 -2
  254. package/src/webinar/index.ts +448 -11
  255. package/src/webinar/utils.ts +16 -0
  256. package/test/unit/spec/aiEnableRequest/index.ts +1067 -0
  257. package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
  258. package/test/unit/spec/annotation/index.ts +69 -7
  259. package/test/unit/spec/breakouts/breakout.ts +9 -3
  260. package/test/unit/spec/breakouts/index.ts +49 -0
  261. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  262. package/test/unit/spec/controls-options-manager/index.js +244 -29
  263. package/test/unit/spec/controls-options-manager/util.js +165 -0
  264. package/test/unit/spec/hashTree/hashTree.ts +721 -0
  265. package/test/unit/spec/hashTree/hashTreeParser.ts +5328 -0
  266. package/test/unit/spec/hashTree/utils.ts +264 -0
  267. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +406 -0
  268. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  269. package/test/unit/spec/interceptors/locusRouteToken.ts +44 -0
  270. package/test/unit/spec/interceptors/utils.ts +75 -0
  271. package/test/unit/spec/interpretation/index.ts +26 -4
  272. package/test/unit/spec/locus-info/controlsUtils.js +222 -52
  273. package/test/unit/spec/locus-info/index.js +2000 -171
  274. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  275. package/test/unit/spec/media/MediaConnectionAwaiter.ts +96 -1
  276. package/test/unit/spec/media/index.ts +92 -0
  277. package/test/unit/spec/media/properties.ts +12 -3
  278. package/test/unit/spec/meeting/in-meeting-actions.ts +12 -2
  279. package/test/unit/spec/meeting/index.js +2925 -209
  280. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  281. package/test/unit/spec/meeting/muteState.js +81 -0
  282. package/test/unit/spec/meeting/request.js +82 -0
  283. package/test/unit/spec/meeting/utils.js +595 -27
  284. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  285. package/test/unit/spec/meetings/index.js +1214 -75
  286. package/test/unit/spec/meetings/request.js +141 -0
  287. package/test/unit/spec/meetings/utils.js +453 -52
  288. package/test/unit/spec/member/index.js +35 -4
  289. package/test/unit/spec/member/util.js +154 -27
  290. package/test/unit/spec/members/index.js +216 -0
  291. package/test/unit/spec/members/request.js +37 -1
  292. package/test/unit/spec/members/utils.js +63 -0
  293. package/test/unit/spec/multistream/mediaRequestManager.ts +503 -122
  294. package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
  295. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  296. package/test/unit/spec/reachability/clusterReachability.ts +125 -1
  297. package/test/unit/spec/reachability/index.ts +154 -49
  298. package/test/unit/spec/reachability/util.ts +31 -0
  299. package/test/unit/spec/reconnection-manager/index.js +4 -8
  300. package/test/unit/spec/recording-controller/index.js +9 -8
  301. package/test/unit/spec/webinar/index.ts +837 -39
  302. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -1,5 +1,6 @@
1
- import {DISPLAY_HINTS} from '../constants';
1
+ import {CONTROLS, DISPLAY_HINTS, HTTP_VERBS} from '../constants';
2
2
  import {Control} from './enums';
3
+ import {AUDIO_CONTROL_BODY_KEYS} from './constants';
3
4
  import {
4
5
  ControlConfig,
5
6
  AudioProperties,
@@ -400,6 +401,85 @@ class Utils {
400
401
 
401
402
  return determinant;
402
403
  }
404
+
405
+ /**
406
+ * Check if all body keys represent audio controls.
407
+ *
408
+ * @param {Record<string, any>} body - The request body to inspect.
409
+ * @returns {boolean} - True if every key in the body is an audio control key.
410
+ */
411
+ public static isAudioControl(body: Record<string, any>): boolean {
412
+ return Object.keys(body).every((key) => AUDIO_CONTROL_BODY_KEYS.has(key));
413
+ }
414
+
415
+ /**
416
+ * Check if the current locus URL differs from the main locus URL,
417
+ * indicating a breakout session.
418
+ *
419
+ * @param {string} locusUrl - The current locus URL.
420
+ * @param {string} [mainLocusUrl] - The main locus URL.
421
+ * @returns {boolean} - True if in a breakout session.
422
+ */
423
+ public static isBreakoutLocusUrl(locusUrl: string, mainLocusUrl?: string): boolean {
424
+ return Boolean(mainLocusUrl) && mainLocusUrl !== locusUrl;
425
+ }
426
+
427
+ /**
428
+ * Resolve the target URL and extra body fields for a controls request,
429
+ * handling breakout session routing. Note: This is a pure computation function.
430
+ * It does not validate that locusUrl is
431
+ * defined. Callers must guard against falsy locusUrl before
432
+ * invoking this function.
433
+ * Mixed audio and non-audio keys in a single body (e.g., {audio: {...},
434
+ * raiseHand: {...}}) are treated as non-audio and routed to mainLocusUrl with
435
+ * authorizingLocusUrl. This means the audio portion would go through unsupported
436
+ * cross-locus authorization. Callers must not produce mixed payloads — update()
437
+ * sends each control scope as a separate request, and setControls() only handles
438
+ * audio-related settings.
439
+ *
440
+ * The authorizingLocusUrl mechanism on PATCH /loci/{lid}/controls is not supported
441
+ * for audio control updates (mute/unmute, muteOnEntry, disallowUnmute).
442
+ * Audio controls are not wired into the cross-locus GraphQL authorization path that
443
+ * other control types (raiseHand, viewParticipantList, admit, reactions, etc.) use.
444
+ * Specifically, the GraphQL authorization layer does not recognize audio as a control
445
+ * type eligible for remote locus authorization.
446
+ * This means authorizingLocusUrl is effectively ignored for audio controls and the
447
+ * server evaluates the request against the target locus only, where the host may not
448
+ * be currently joined.
449
+ * Audio control updates must be sent directly to the locus the user is currently in.
450
+ * If the host is in a breakout and wants to mute participants in that breakout, the
451
+ * request should target the breakout locus URL directly, not the main session locus
452
+ * with authorizingLocusUrl.
453
+ * Meeting-wide audio control actions (e.g., muting panelists across all breakouts
454
+ * from a single request) are not currently supported through this mechanism.
455
+ *
456
+ * @param {object} options
457
+ * @param {Record<string, any>} options.body - The request body.
458
+ * @param {string} options.locusUrl - The current locus URL. Must be defined (callers must validate).
459
+ * @param {string} [options.mainLocusUrl] - The main locus URL.
460
+ * @returns {{ uri: string, body: Record<string, any>, method: string }}
461
+ */
462
+ public static getControlsRequestParams(options: {
463
+ body: Record<string, any>;
464
+ locusUrl: string;
465
+ mainLocusUrl?: string;
466
+ }): {
467
+ uri: string;
468
+ body: Record<string, any>;
469
+ method: string;
470
+ } {
471
+ const {body, locusUrl, mainLocusUrl} = options;
472
+
473
+ const isAudio = Utils.isAudioControl(body);
474
+ const inBreakout = Utils.isBreakoutLocusUrl(locusUrl, mainLocusUrl);
475
+ const targetUrl = inBreakout && !isAudio ? mainLocusUrl : locusUrl;
476
+
477
+ return {
478
+ uri: `${targetUrl}/${CONTROLS}`,
479
+ body: inBreakout && !isAudio ? {...body, authorizingLocusUrl: locusUrl} : body,
480
+ method: HTTP_VERBS.PATCH,
481
+ };
482
+ }
403
483
  }
404
484
 
405
485
  export default Utils;
@@ -0,0 +1,26 @@
1
+ export const EMPTY_HASH = '99aa06d3014798d86001c324468d497f';
2
+
3
+ export const DataSetNames = {
4
+ MAIN: 'main', // sent to web client, contains also panelists, over LLM
5
+ ATTENDEES: 'attendees', // NOT SENT to web client, all the attendees in the locus
6
+ ATD_ACTIVE: 'atd-active', // only sent to panelists, over LLM; the attendees that have their hands raised or are allowed to unmute themselves
7
+ ATD_UNMUTED: 'atd-unmuted', // sent to web client, over LLM, not sent to panelists; the attendees that are unmuted
8
+ SELF: 'self', // sent to web client, over Mercury
9
+ UNJOINED: 'unjoined', // sent when you are not joined, but can still see some stuff from the meeting (mutually exclusive with "main")
10
+ };
11
+
12
+ // Priority order for initializing data sets — higher priority names come first.
13
+ // Data sets not listed here will be initialized after all prioritized ones.
14
+ // MAIN must come before SELF because LocusInfo.updateFromHashTree processes the
15
+ // batch of updatedObjects in order, and the SELF handler in updateLocusFromHashTreeObject
16
+ // checks locus.info?.isWebinar (which comes from MAIN) to decide whether to create a
17
+ // participant object for webinar attendees. If SELF were initialized first, locus.info
18
+ // would not yet be populated and the attendee participant would be skipped.
19
+ export const DATA_SET_INIT_PRIORITY: string[] = [DataSetNames.MAIN, DataSetNames.SELF];
20
+
21
+ // Data sets for which we normally receive events over LLM connection
22
+ export const LLM_DATASET_NAMES = [
23
+ DataSetNames.MAIN,
24
+ DataSetNames.ATD_ACTIVE,
25
+ DataSetNames.ATD_UNMUTED,
26
+ ];
@@ -0,0 +1,480 @@
1
+ import {XXH3_128} from 'xxh3-ts/xxh3';
2
+ import {EMPTY_HASH} from './constants';
3
+ import {ObjectType} from './types';
4
+
5
+ export type LeafDataItem = {
6
+ type: ObjectType;
7
+ id: number;
8
+ version: number;
9
+ };
10
+
11
+ /**
12
+ * HashTree is a data structure that organizes items into leaves based on their IDs,
13
+ */
14
+ class HashTree {
15
+ leaves: Array<Record<string, Record<number, LeafDataItem>>>;
16
+
17
+ leafHashes: Array<string>;
18
+ readonly numLeaves: number;
19
+
20
+ /**
21
+ * Constructs a new HashTree.
22
+ * @param {LeafDataItem[]} leafData Initial data to populate the tree.
23
+ * @param {number} numLeaves The number of leaf nodes in the tree. Must be 0 or a power of 2.
24
+ * @throws {Error} If numLeaves is not 0 or a power of 2.
25
+ */
26
+ constructor(leafData: LeafDataItem[], numLeaves: number) {
27
+ // eslint-disable-next-line no-bitwise
28
+ if ((numLeaves & (numLeaves - 1)) !== 0) {
29
+ throw new Error(`Number of leaves must be a power of 2, saw ${numLeaves}`);
30
+ }
31
+
32
+ this.numLeaves = numLeaves;
33
+ this.leafHashes = new Array(numLeaves).fill(EMPTY_HASH);
34
+
35
+ this.leaves = new Array(numLeaves).fill(null).map(() => {
36
+ return {};
37
+ });
38
+
39
+ if (leafData) {
40
+ this.putItems(leafData);
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Internal logic for adding or updating an item, without computing the leaf hash.
46
+ * @param {LeafDataItem} item The item to add or update.
47
+ * @returns {{put: boolean, index: (number|null)}} Object indicating if put and the leaf index.
48
+ * @private
49
+ */
50
+ private _putItemInternal(item: LeafDataItem): {put: boolean; index: number | null} {
51
+ if (this.numLeaves === 0) {
52
+ return {put: false, index: null}; // Cannot add to a tree with 0 leaves
53
+ }
54
+
55
+ const index = item.id % this.numLeaves;
56
+
57
+ if (!this.leaves[index][item.type]) {
58
+ this.leaves[index][item.type] = {};
59
+ }
60
+
61
+ const existingItem = this.leaves[index][item.type][item.id];
62
+
63
+ if (!existingItem || existingItem.version < item.version) {
64
+ this.leaves[index][item.type][item.id] = item;
65
+
66
+ return {put: true, index};
67
+ }
68
+
69
+ return {put: false, index: null};
70
+ }
71
+
72
+ /**
73
+ * Adds or updates a single item in the hash tree.
74
+ * @param {LeafDataItem} item The item to add or update.
75
+ * @returns {boolean} True if the item was added or updated, false otherwise (e.g., older version or tree has 0 leaves).
76
+ */
77
+ putItem(item: LeafDataItem): boolean {
78
+ const {put, index} = this._putItemInternal(item);
79
+
80
+ if (put && index !== null) {
81
+ this.computeLeafHash(index);
82
+ }
83
+
84
+ return put;
85
+ }
86
+
87
+ /**
88
+ * Adds or updates multiple items in the hash tree.
89
+ * @param {LeafDataItem[]} items The array of items to add or update.
90
+ * @returns {boolean[]} An array of booleans indicating success for each item.
91
+ */
92
+ putItems(items: LeafDataItem[]): boolean[] {
93
+ if (this.numLeaves === 0 && items.length > 0) {
94
+ // Cannot add items to a tree with 0 leaves.
95
+ return items.map(() => false);
96
+ }
97
+ const results: boolean[] = [];
98
+ const changedLeafIndexes = new Set<number>();
99
+
100
+ items.forEach((item) => {
101
+ const {put, index} = this._putItemInternal(item);
102
+ results.push(put);
103
+ if (put && index !== null) {
104
+ changedLeafIndexes.add(index);
105
+ }
106
+ });
107
+
108
+ changedLeafIndexes.forEach((index) => {
109
+ this.computeLeafHash(index);
110
+ });
111
+
112
+ return results;
113
+ }
114
+
115
+ /**
116
+ * Internal logic for removing an item, without computing the leaf hash.
117
+ * @param {LeafDataItem} item The item to remove.
118
+ * @returns {{removed: boolean, index: (number|null)}} Object indicating if removed and the leaf index.
119
+ * @private
120
+ */
121
+ private _removeItemInternal(item: LeafDataItem): {removed: boolean; index: number | null} {
122
+ if (this.numLeaves === 0) {
123
+ return {removed: false, index: null};
124
+ }
125
+
126
+ const index = item.id % this.numLeaves;
127
+
128
+ if (
129
+ this.leaves[index] &&
130
+ this.leaves[index][item.type] &&
131
+ this.leaves[index][item.type][item.id]
132
+ ) {
133
+ const existingItem = this.leaves[index][item.type][item.id];
134
+ if (
135
+ existingItem.id === item.id &&
136
+ existingItem.type === item.type &&
137
+ existingItem.version <= item.version
138
+ ) {
139
+ delete this.leaves[index][item.type][item.id];
140
+ if (Object.keys(this.leaves[index][item.type]).length === 0) {
141
+ delete this.leaves[index][item.type];
142
+ }
143
+
144
+ return {removed: true, index};
145
+ }
146
+ }
147
+
148
+ return {removed: false, index: null};
149
+ }
150
+
151
+ /**
152
+ * Removes a single item from the hash tree.
153
+ * The removal is based on matching type, id, and the provided item's version
154
+ * being greater than or equal to the existing item's version.
155
+ * @param {LeafDataItem} item The item to remove.
156
+ * @returns {boolean} True if the item was removed, false otherwise.
157
+ */
158
+ removeItem(item: LeafDataItem): boolean {
159
+ const {removed, index} = this._removeItemInternal(item);
160
+
161
+ if (removed && index !== null) {
162
+ this.computeLeafHash(index);
163
+ }
164
+
165
+ return removed;
166
+ }
167
+
168
+ /**
169
+ * Removes multiple items from the hash tree.
170
+ * @param {LeafDataItem[]} items The array of items to remove.
171
+ * @returns {boolean[]} An array of booleans indicating success for each item.
172
+ */
173
+ removeItems(items: LeafDataItem[]): boolean[] {
174
+ if (this.numLeaves === 0 && items.length > 0) {
175
+ return items.map(() => false);
176
+ }
177
+
178
+ const results: boolean[] = [];
179
+ const changedLeafIndexes = new Set<number>();
180
+
181
+ items.forEach((item) => {
182
+ const {removed, index} = this._removeItemInternal(item);
183
+ results.push(removed);
184
+ if (removed && index !== null) {
185
+ changedLeafIndexes.add(index);
186
+ }
187
+ });
188
+
189
+ changedLeafIndexes.forEach((index) => {
190
+ this.computeLeafHash(index);
191
+ });
192
+
193
+ return results;
194
+ }
195
+
196
+ /**
197
+ * Updates multiple items in the hash tree.
198
+ * This method can handle both updating and removing items based on the `operation` flag.
199
+ *
200
+ * @param {object[]} itemUpdates An array of objects containing `operation` flag and the `item` to update.
201
+ * @returns {boolean[]} An array of booleans indicating success for each operation.
202
+ */
203
+ updateItems(itemUpdates: {operation: 'update' | 'remove'; item: LeafDataItem}[]): boolean[] {
204
+ if (this.numLeaves === 0 && itemUpdates.length > 0) {
205
+ return itemUpdates.map(() => false);
206
+ }
207
+
208
+ const results: boolean[] = [];
209
+ const changedLeafIndexes = new Set<number>();
210
+
211
+ itemUpdates.forEach(({operation, item}) => {
212
+ if (operation === 'remove') {
213
+ const {removed, index} = this._removeItemInternal(item);
214
+ results.push(removed);
215
+ if (removed && index !== null) {
216
+ changedLeafIndexes.add(index);
217
+ }
218
+ } else {
219
+ const {put, index} = this._putItemInternal(item);
220
+ results.push(put);
221
+ if (put && index !== null) {
222
+ changedLeafIndexes.add(index);
223
+ }
224
+ }
225
+ });
226
+
227
+ changedLeafIndexes.forEach((index) => {
228
+ this.computeLeafHash(index);
229
+ });
230
+
231
+ return results;
232
+ }
233
+
234
+ /**
235
+ * Computes the hash for a specific leaf.
236
+ * The hash is based on the sorted items within the leaf.
237
+ * @param {number} index The index of the leaf to compute the hash for.
238
+ * @returns {void}
239
+ */
240
+ computeLeafHash(index: number) {
241
+ if (index < 0 || index >= this.numLeaves) {
242
+ // nothing to do
243
+ return;
244
+ }
245
+ const leafContent = this.leaves[index];
246
+
247
+ const totalItemsCount = Object.keys(leafContent).reduce((count, type) => {
248
+ return count + Object.keys(leafContent[type]).length;
249
+ }, 0);
250
+ const buffer = Buffer.alloc(totalItemsCount * 16);
251
+
252
+ let offset = 0;
253
+
254
+ // iterate through the item types lexicographically
255
+ const itemTypes = Object.keys(leafContent).sort();
256
+ itemTypes.forEach((type) => {
257
+ // iterate through the items of this type in ascending order of ID
258
+ const items = Object.values(leafContent[type]).sort(
259
+ (a: LeafDataItem, b: LeafDataItem) => a.id - b.id
260
+ );
261
+
262
+ // add all the items id and version to the hasher
263
+ items.forEach((item: LeafDataItem) => {
264
+ buffer.writeBigInt64LE(BigInt(item.id), offset);
265
+ buffer.writeBigInt64LE(BigInt(item.version), offset + 8);
266
+
267
+ offset += 16;
268
+ });
269
+ });
270
+
271
+ this.leafHashes[index] = XXH3_128(buffer, BigInt(0)).toString(16).padStart(32, '0');
272
+ }
273
+
274
+ /**
275
+ * Computes all internal and leaf node hashes of the tree.
276
+ * Internal node hashes are computed bottom-up from the leaf hashes.
277
+ * @returns {string[]} An array of hash strings, with internal node hashes first, followed by leaf hashes.
278
+ * Returns `[EMPTY_HASH]` if the tree has 0 leaves.
279
+ */
280
+ computeTreeHashes(): string[] {
281
+ if (this.numLeaves === 0) {
282
+ return [EMPTY_HASH];
283
+ }
284
+
285
+ let currentLevelHashes = [...this.leafHashes];
286
+ const allHashes = [];
287
+
288
+ while (currentLevelHashes.length > 1) {
289
+ const nextLevelHashes: string[] = [];
290
+ for (let i = 0; i < currentLevelHashes.length; i += 2) {
291
+ const leftHash = currentLevelHashes[i];
292
+ const rightHash = i + 1 < currentLevelHashes.length ? currentLevelHashes[i + 1] : leftHash;
293
+
294
+ const input = Buffer.concat([
295
+ Buffer.from(leftHash, 'hex').subarray(0, 8).reverse(),
296
+ Buffer.from(leftHash, 'hex').subarray(8, 16).reverse(),
297
+ Buffer.from(rightHash, 'hex').subarray(0, 8).reverse(),
298
+ Buffer.from(rightHash, 'hex').subarray(8, 16).reverse(),
299
+ ]);
300
+
301
+ nextLevelHashes.push(XXH3_128(input, BigInt(0)).toString(16).padStart(32, '0'));
302
+ }
303
+ currentLevelHashes = nextLevelHashes;
304
+ allHashes.unshift(...currentLevelHashes);
305
+ }
306
+
307
+ return [...allHashes, ...this.leafHashes];
308
+ }
309
+
310
+ /**
311
+ * Returns all hashes in the tree (internal nodes then leaf nodes).
312
+ * @returns {string[]} An array of hash strings.
313
+ */
314
+ getHashes(): string[] {
315
+ return this.computeTreeHashes();
316
+ }
317
+
318
+ /**
319
+ * Computes and returns the hash value of the root node.
320
+ * @returns {string} The root hash of the entire tree. Returns `EMPTY_HASH` if the tree has 0 leaves.
321
+ */
322
+ getRootHash(): string {
323
+ if (this.numLeaves === 0) {
324
+ return EMPTY_HASH;
325
+ }
326
+
327
+ return this.computeTreeHashes()[0];
328
+ }
329
+
330
+ /**
331
+ * Gets the number of leaves in the tree.
332
+ * @returns {number} The number of leaves.
333
+ */
334
+ getLeafCount(): number {
335
+ return this.numLeaves;
336
+ }
337
+
338
+ /**
339
+ * Calculates the total number of items stored in the tree.
340
+ * @returns {number} The total number of items.
341
+ */
342
+ getTotalItemCount(): number {
343
+ let count = 0;
344
+ for (const leaf of this.leaves) {
345
+ for (const type of Object.keys(leaf)) {
346
+ count += Object.keys(leaf[type]).length;
347
+ }
348
+ }
349
+
350
+ return count;
351
+ }
352
+
353
+ /**
354
+ * Retrieves all data items from a specific leaf.
355
+ * @param {number} leafIndex The index of the leaf.
356
+ * @returns {LeafDataItem[]} An array of LeafDataItem in the specified leaf, sorted by ID,
357
+ * or an empty array if the index is invalid or leaf is empty.
358
+ */
359
+ getLeafData(leafIndex: number): LeafDataItem[] {
360
+ if (leafIndex < 0 || leafIndex >= this.numLeaves) {
361
+ return [];
362
+ }
363
+ const leafContent = this.leaves[leafIndex];
364
+ const items: LeafDataItem[] = [];
365
+ for (const type of Object.keys(leafContent)) {
366
+ items.push(...Object.values(leafContent[type]));
367
+ }
368
+ // Optionally sort them if a specific order is required, e.g., by ID
369
+ items.sort((a, b) => a.id - b.id);
370
+
371
+ return items;
372
+ }
373
+
374
+ /**
375
+ * Retrieves the version of a specific item by its id and type.
376
+ * @param {number} id The ID of the item.
377
+ * @param {ObjectType} type The type of the item.
378
+ * @returns {number | undefined} The version of the item if found, undefined otherwise.
379
+ */
380
+ getItemVersion(id: number, type: ObjectType): number | undefined {
381
+ if (this.numLeaves === 0) {
382
+ return undefined;
383
+ }
384
+
385
+ const index = id % this.numLeaves;
386
+ const item = this.leaves[index]?.[type]?.[id];
387
+
388
+ return item?.version;
389
+ }
390
+
391
+ /**
392
+ * Resizes the HashTree to have a new number of leaf nodes, redistributing all existing items.
393
+ * @param {number} newNumLeaves The new number of leaf nodes (must be 0 or a power of 2).
394
+ * @returns {boolean} true if the tree was resized, false if the size didn't change.
395
+ * @throws {Error} if newNumLeaves is not 0 or a power of 2.
396
+ */
397
+ resize(newNumLeaves: number): boolean {
398
+ // eslint-disable-next-line no-bitwise
399
+ if (newNumLeaves < 0 || (newNumLeaves !== 0 && (newNumLeaves & (newNumLeaves - 1)) !== 0)) {
400
+ throw new Error('New number of leaves must be 0 or a power of 2');
401
+ }
402
+
403
+ if (newNumLeaves === this.numLeaves) {
404
+ return false;
405
+ }
406
+
407
+ const allItems: LeafDataItem[] = [];
408
+ for (const leaf of this.leaves) {
409
+ for (const type of Object.keys(leaf)) {
410
+ allItems.push(...Object.values(leaf[type]));
411
+ }
412
+ }
413
+
414
+ // Re-initialize
415
+ // eslint-disable-next-line no-extra-semi
416
+ (this as any).numLeaves = newNumLeaves; // Type assertion to update readonly property
417
+ this.leafHashes = new Array(newNumLeaves).fill(EMPTY_HASH);
418
+ this.leaves = new Array(newNumLeaves).fill(null).map(() => ({}));
419
+
420
+ if (newNumLeaves > 0) {
421
+ this.putItems(allItems); // Re-add items which will be re-assigned to leaves and re-hashed
422
+ }
423
+
424
+ return true;
425
+ }
426
+
427
+ /**
428
+ * Compares the tree's leaf hashes with an external set of hashes and returns the indices of differing leaf nodes.
429
+ * The externalHashes array is expected to contain all node hashes (internal followed by leaves),
430
+ * similar to the output of getHashes().
431
+ * @param {string[]} externalHashes An array of hash strings (internal node hashes then leaf hashes).
432
+ * @returns {number[]} An array of indices of the leaf nodes that have different hashes.
433
+ */
434
+ diffHashes(externalHashes: string[]): number[] {
435
+ if (this.numLeaves === 0) {
436
+ // If this tree is empty, its hash is EMPTY_HASH.
437
+ // It differs if externalHashes is not a single EMPTY_HASH.
438
+ if (externalHashes && externalHashes.length === 1 && externalHashes[0] === EMPTY_HASH) {
439
+ return []; // No differences
440
+ }
441
+ // An empty tree has no leaves to differ, so return an empty array
442
+ // as no specific leaf indexes are different.
443
+
444
+ return [];
445
+ }
446
+
447
+ // We are interested in comparing the leaf hashes part.
448
+ // The externalHashes array should also have its leaf hashes at the end.
449
+ const differingLeafIndexes: number[] = [];
450
+ // Calculate where the leaf hashes would start in the externalHashes array,
451
+ // assuming it has the same number of leaves as this tree.
452
+ const externalLeafHashesStart = externalHashes.length - this.numLeaves;
453
+
454
+ if (externalLeafHashesStart < 0) {
455
+ // externalHashes is too short to contain a complete set of leaf hashes
456
+ // corresponding to this tree's numLeaves.
457
+ // In this case, consider all of this tree's leaves as "different".
458
+ for (let i = 0; i < this.numLeaves; i += 1) {
459
+ differingLeafIndexes.push(i);
460
+ }
461
+
462
+ return differingLeafIndexes;
463
+ }
464
+
465
+ // Compare each leaf hash
466
+ for (let i = 0; i < this.numLeaves; i += 1) {
467
+ const ownLeafHash = this.leafHashes[i];
468
+ // externalLeafHash might be undefined if externalHashes is shorter than expected
469
+ // but externalLeafHashesStart was non-negative, implying a structural mismatch.
470
+ const externalLeafHash = externalHashes[externalLeafHashesStart + i];
471
+ if (ownLeafHash !== externalLeafHash) {
472
+ differingLeafIndexes.push(i);
473
+ }
474
+ }
475
+
476
+ return differingLeafIndexes;
477
+ }
478
+ }
479
+
480
+ export default HashTree;