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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -5,7 +5,7 @@ import {assert} from '@webex/test-helper-chai';
5
5
  import MockWebex from '@webex/test-helper-mock-webex';
6
6
  import testUtils from '../../../utils/testUtils';
7
7
  import Meetings from '@webex/plugin-meetings';
8
- import LocusInfo from '@webex/plugin-meetings/src/locus-info';
8
+ import LocusInfo, {createLocusFromHashTreeMessage, findMeetingForHashTreeMessage} from '@webex/plugin-meetings/src/locus-info';
9
9
  import SelfUtils from '@webex/plugin-meetings/src/locus-info/selfUtils';
10
10
  import InfoUtils from '@webex/plugin-meetings/src/locus-info/infoUtils';
11
11
  import EmbeddedAppsUtils from '@webex/plugin-meetings/src/locus-info/embeddedAppsUtils';
@@ -13,6 +13,7 @@ import MediaSharesUtils from '@webex/plugin-meetings/src/locus-info//mediaShares
13
13
  import LocusDeltaParser from '@webex/plugin-meetings/src/locus-info/parser';
14
14
  import Metrics from '@webex/plugin-meetings/src/metrics';
15
15
  import * as HashTreeParserModule from '@webex/plugin-meetings/src/hashTree/hashTreeParser';
16
+ import MeetingsUtil from '@webex/plugin-meetings/src/meetings/util';
16
17
 
17
18
  import {
18
19
  LOCUSINFO,
@@ -29,7 +30,8 @@ import {
29
30
  } from '../../../../src/constants';
30
31
 
31
32
  import {self, selfWithInactivity} from './selfConstant';
32
- import { MEETING_REMOVED_REASON } from '@webex/plugin-meetings/src/constants';
33
+ import {MEETING_REMOVED_REASON} from '@webex/plugin-meetings/src/constants';
34
+ import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
33
35
 
34
36
  describe('plugin-meetings', () => {
35
37
  describe('LocusInfo index', () => {
@@ -104,9 +106,10 @@ describe('plugin-meetings', () => {
104
106
  });
105
107
 
106
108
  const createHashTreeMessage = (visibleDataSets) => ({
109
+ locusUrl: 'http://locus-url.com',
107
110
  locusStateElements: [
108
111
  {
109
- htMeta: {elementId: {type: 'self'}},
112
+ htMeta: {elementId: {type: 'metadata'}},
110
113
  data: {visibleDataSets},
111
114
  },
112
115
  ],
@@ -114,6 +117,7 @@ describe('plugin-meetings', () => {
114
117
  });
115
118
 
116
119
  const createLocusWithVisibleDataSets = (visibleDataSets) => ({
120
+ url: 'http://locus-url.com',
117
121
  self: {visibleDataSets},
118
122
  participants: [],
119
123
  links: {
@@ -136,8 +140,12 @@ describe('plugin-meetings', () => {
136
140
  HashTreeParserStub,
137
141
  sinon.match({
138
142
  initialLocus: {
139
- locus: {self: {visibleDataSets}},
140
- dataSets: [],
143
+ locus: null,
144
+ dataSets: hashTreeMessage.dataSets,
145
+ },
146
+ metadata: {
147
+ htMeta: hashTreeMessage.locusStateElements[0].htMeta,
148
+ visibleDataSets,
141
149
  },
142
150
  webexRequest: sinon.match.func,
143
151
  locusInfoUpdateCallback: sinon.match.func,
@@ -169,11 +177,16 @@ describe('plugin-meetings', () => {
169
177
  const visibleDataSets = ['dataset1', 'dataset2'];
170
178
  const locus = createLocusWithVisibleDataSets(visibleDataSets);
171
179
  const dataSets = [{name: 'dataset1', url: 'http://dataset-url.com'}];
180
+ const metadata = {
181
+ htMeta: {elementId: {type: 'metadata'}},
182
+ visibleDataSets,
183
+ };
172
184
 
173
185
  await locusInfo.initialSetup({
174
186
  trigger: 'join-response',
175
187
  locus,
176
188
  dataSets,
189
+ metadata,
177
190
  });
178
191
 
179
192
  assert.calledOnceWithExactly(
@@ -183,6 +196,7 @@ describe('plugin-meetings', () => {
183
196
  locus,
184
197
  dataSets,
185
198
  },
199
+ metadata,
186
200
  webexRequest: sinon.match.func,
187
201
  locusInfoUpdateCallback: sinon.match.func,
188
202
  debugId: sinon.match.string,
@@ -207,6 +221,47 @@ describe('plugin-meetings', () => {
207
221
  assert.isTrue(locusInfo.emitChange);
208
222
  });
209
223
 
224
+ it('calls onLocusSynced callback passed as second argument with full locus from join response', async () => {
225
+ const syncedLocus = {url: 'http://locus-url.com', participants: []};
226
+ const onLocusSynced = sinon.stub();
227
+
228
+ await locusInfo.initialSetup(
229
+ {
230
+ trigger: 'join-response',
231
+ locus: syncedLocus,
232
+ },
233
+ onLocusSynced
234
+ );
235
+
236
+ assert.calledOnceWithExactly(onLocusSynced, syncedLocus);
237
+ });
238
+
239
+ it('swallows onLocusSynced callback errors and logs warn', async () => {
240
+ const syncedLocus = {url: 'http://locus-url.com', participants: []};
241
+ const callbackError = new Error('onLocusSynced failed');
242
+ const onLocusSynced = sinon.stub().throws(callbackError);
243
+ const loggerWarnStub = LoggerProxy.logger.warn?.isSinonProxy
244
+ ? LoggerProxy.logger.warn
245
+ : sinon.stub(LoggerProxy.logger, 'warn');
246
+
247
+ loggerWarnStub.resetHistory();
248
+
249
+ await locusInfo.initialSetup(
250
+ {
251
+ trigger: 'join-response',
252
+ locus: syncedLocus,
253
+ },
254
+ onLocusSynced
255
+ );
256
+
257
+ assert.calledOnceWithExactly(onLocusSynced, syncedLocus);
258
+ assert.calledOnce(loggerWarnStub);
259
+ assert.match(
260
+ loggerWarnStub.firstCall.args[0],
261
+ /Locus-info:index#initialSetup --> onLocusSynced callback failed/
262
+ );
263
+ });
264
+
210
265
  it('should initialize the hash tree parser correctly when triggered from a get loci response containing visible datasets', async () => {
211
266
  const visibleDataSets = ['dataset1', 'dataset2'];
212
267
  const locus = createLocusWithVisibleDataSets(visibleDataSets);
@@ -220,12 +275,13 @@ describe('plugin-meetings', () => {
220
275
  HashTreeParserStub,
221
276
  sinon.match({
222
277
  initialLocus: {
223
- locus: {self: {visibleDataSets}},
278
+ locus: null,
224
279
  dataSets: [],
225
280
  },
226
281
  webexRequest: sinon.match.func,
227
282
  locusInfoUpdateCallback: sinon.match.func,
228
283
  debugId: sinon.match.string,
284
+ metadata: null,
229
285
  })
230
286
  );
231
287
  assert.calledOnceWithExactly(mockHashTreeParser.initializeFromGetLociResponse, locus);
@@ -249,9 +305,34 @@ describe('plugin-meetings', () => {
249
305
  assert.isTrue(locusInfo.emitChange);
250
306
  });
251
307
 
308
+ it('throws if called with "locus-message" and Metadata object without visibleDataSets', async () => {
309
+ const hashTreeMessage = {
310
+ locusStateElements: [
311
+ {
312
+ htMeta: {elementId: {type: 'Metadata'}},
313
+ data: {},
314
+ },
315
+ ],
316
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
317
+ };
318
+ try {
319
+ await locusInfo.initialSetup({
320
+ trigger: 'locus-message',
321
+ hashTreeMessage,
322
+ });
323
+ assert.fail('should have thrown an error');
324
+ } catch (error) {
325
+ assert.equal(
326
+ error.message,
327
+ 'Metadata object with visibleDataSets is missing in the message'
328
+ );
329
+ }
330
+ });
331
+
252
332
  describe('should setup correct locusInfoUpdateCallback when creating HashTreeParser', () => {
253
333
  const OBJECTS_UPDATED = HashTreeParserModule.LocusInfoUpdateType.OBJECTS_UPDATED;
254
334
  const MEETING_ENDED = HashTreeParserModule.LocusInfoUpdateType.MEETING_ENDED;
335
+ const LOCUS_NOT_FOUND = HashTreeParserModule.LocusInfoUpdateType.LOCUS_NOT_FOUND;
255
336
 
256
337
  let locusInfoUpdateCallback;
257
338
  let onDeltaLocusStub;
@@ -263,10 +344,11 @@ describe('plugin-meetings', () => {
263
344
  await locusInfo.initialSetup({
264
345
  trigger: 'locus-message',
265
346
  hashTreeMessage: {
347
+ locusUrl: 'fake-locus-url',
266
348
  locusStateElements: [
267
349
  {
268
- htMeta: {elementId: {type: 'self'}},
269
- data: {visibleDataSets: ['dataset1']},
350
+ htMeta: {elementId: {type: 'Metadata'}},
351
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
270
352
  },
271
353
  ],
272
354
  dataSets: [{name: 'dataset1', url: 'test-url'}],
@@ -293,6 +375,16 @@ describe('plugin-meetings', () => {
293
375
  htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-2', version: 1}},
294
376
  },
295
377
  ];
378
+ locusInfo.embeddedApps = [
379
+ {
380
+ id: 'fake-embedded-app-1',
381
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-1', version: 1}},
382
+ },
383
+ {
384
+ id: 'fake-embedded-app-2',
385
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2', version: 1}},
386
+ },
387
+ ];
296
388
  locusInfo.meetings = {id: 'fake-meetings'};
297
389
  locusInfo.participants = [
298
390
  {id: 'fake-participant-1', name: 'Participant One'},
@@ -311,6 +403,13 @@ describe('plugin-meetings', () => {
311
403
  locusInfo.url = 'fake-locus-url';
312
404
  locusInfo.htMeta = {elementId: {type: 'locus', id: 'fake-ht-locus-id', version: 1}};
313
405
 
406
+ const createdHashTreeParser = locusInfo.hashTreeParsers.get('fake-locus-url');
407
+
408
+ assert.isDefined(createdHashTreeParser);
409
+ // this flag would have been set to true on the first callback triggered by initialSetup() wa called earlier
410
+ // it's not because we're mocking HashTreeParser, so we have to set it manually here
411
+ createdHashTreeParser.initializedFromHashTree = true;
412
+
314
413
  // setup the default expected locus info state that each test builds upon
315
414
  expectedLocusInfo = {
316
415
  controls: {id: 'fake-controls'},
@@ -328,8 +427,18 @@ describe('plugin-meetings', () => {
328
427
  htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-2', version: 1}},
329
428
  },
330
429
  ],
430
+ embeddedApps: [
431
+ {
432
+ id: 'fake-embedded-app-1',
433
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-1', version: 1}},
434
+ },
435
+ {
436
+ id: 'fake-embedded-app-2',
437
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2', version: 1}},
438
+ },
439
+ ],
331
440
  meetings: {id: 'fake-meetings'},
332
- jsSdkMeta: {removedParticipantIds: []},
441
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false},
333
442
  participants: [], // empty means there were no participant updates
334
443
  replaces: {id: 'fake-replaces'},
335
444
  self: {id: 'fake-self'},
@@ -347,14 +456,138 @@ describe('plugin-meetings', () => {
347
456
  };
348
457
 
349
458
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
350
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
459
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
460
+ updatedObjects: [{htMeta: {elementId: {type: 'self'}}, data: newSelf}],
461
+ });
462
+
463
+ // check onDeltaLocus() was called with correctly updated locus info
464
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
465
+ ...expectedLocusInfo,
466
+ self: newSelf,
467
+ });
468
+ });
469
+
470
+ it('should process locus update correctly when called with updated SELF (webinar non-attendee)', () => {
471
+ const newSelf = {
472
+ id: 'new-self',
473
+ visibleDataSets: ['dataset1', 'dataset2'],
474
+ controls: {
475
+ role: {
476
+ roles: [
477
+ {type: 'PANELIST', hasRole: true},
478
+ {type: 'ATTENDEE', hasRole: false},
479
+ ],
480
+ },
481
+ },
482
+ };
483
+ locusInfo.info.isWebinar = true;
484
+
485
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
486
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
487
+ updatedObjects: [{htMeta: {elementId: {type: 'self'}}, data: newSelf}],
488
+ });
489
+
490
+ // check onDeltaLocus() was called with correctly updated locus info
491
+ // without any participant generated
492
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
493
+ ...expectedLocusInfo,
494
+ info: {
495
+ ...expectedLocusInfo.info,
496
+ isWebinar: true,
497
+ },
498
+ self: newSelf,
499
+ });
500
+ });
501
+
502
+ it('should generate a participant when called with updated SELF for webinar attendee', () => {
503
+ const newSelf = {
504
+ id: 'new-self',
505
+ visibleDataSets: ['dataset1', 'dataset2'],
506
+ controls: {
507
+ role: {
508
+ roles: [
509
+ {type: 'something else - should be ignored', hasRole: true},
510
+ {type: 'ATTENDEE', hasRole: true},
511
+ ],
512
+ },
513
+ },
514
+ };
515
+
516
+ locusInfo.info.isWebinar = true;
517
+
518
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
519
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
351
520
  updatedObjects: [{htMeta: {elementId: {type: 'self'}}, data: newSelf}],
352
521
  });
353
522
 
354
523
  // check onDeltaLocus() was called with correctly updated locus info
524
+ // that contains a participant created from self
355
525
  assert.calledOnceWithExactly(onDeltaLocusStub, {
356
526
  ...expectedLocusInfo,
527
+ info: {
528
+ ...expectedLocusInfo.info,
529
+ isWebinar: true,
530
+ },
357
531
  self: newSelf,
532
+ participants: [
533
+ {
534
+ ...newSelf,
535
+ },
536
+ ],
537
+ });
538
+ });
539
+
540
+ it('should process locus update correctly when called with updated fullState', () => {
541
+ const newFullState = {
542
+ id: 'new-fullState',
543
+ visibleDataSets: ['dataset1', 'dataset2'],
544
+ };
545
+
546
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
547
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
548
+ updatedObjects: [{htMeta: {elementId: {type: 'fullState'}}, data: newFullState}],
549
+ });
550
+
551
+ // check onDeltaLocus() was called with correctly updated locus info
552
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
553
+ ...expectedLocusInfo,
554
+ fullState: newFullState,
555
+ });
556
+ });
557
+
558
+ it('should process locus update correctly when called with updated info', () => {
559
+ const newInfo = {
560
+ id: 'new-info',
561
+ visibleDataSets: ['dataset1', 'dataset2'],
562
+ };
563
+
564
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
565
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
566
+ updatedObjects: [{htMeta: {elementId: {type: 'info'}}, data: newInfo}],
567
+ });
568
+
569
+ // check onDeltaLocus() was called with correctly updated locus info
570
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
571
+ ...expectedLocusInfo,
572
+ info: newInfo,
573
+ });
574
+ });
575
+
576
+ it('should process locus update correctly when called with updated links', () => {
577
+ const newLinks = {
578
+ id: 'new-links',
579
+ visibleDataSets: ['dataset1', 'dataset2'],
580
+ };
581
+
582
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
583
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
584
+ updatedObjects: [{htMeta: {elementId: {type: 'links'}}, data: newLinks}],
585
+ });
586
+
587
+ // check onDeltaLocus() was called with correctly updated locus info
588
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
589
+ ...expectedLocusInfo,
590
+ links: newLinks,
358
591
  });
359
592
  });
360
593
 
@@ -362,22 +595,78 @@ describe('plugin-meetings', () => {
362
595
  // setup new updated locus that has many things missing
363
596
  const newLocusHtMeta = {elementId: {type: 'locus', version: 42}};
364
597
  const newLocus = {
365
- conntrols: 'new-controls',
366
598
  host: 'new-host',
367
599
  htMeta: newLocusHtMeta,
368
600
  };
369
601
 
370
602
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
371
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
603
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
372
604
  updatedObjects: [{htMeta: newLocusHtMeta, data: newLocus}],
373
605
  });
374
606
 
375
607
  // check onDeltaLocus() was called with correctly updated locus info
376
608
  assert.calledOnceWithExactly(onDeltaLocusStub, {
609
+ // these fields are not part of Locus object, so should keep their old values:
610
+ controls: {id: 'fake-controls'},
611
+ info: {id: 'fake-info'},
612
+ fullState: {id: 'fake-full-state'},
613
+ self: {id: 'fake-self'},
614
+ links: {id: 'fake-links'},
615
+ mediaShares: expectedLocusInfo.mediaShares,
616
+ embeddedApps: expectedLocusInfo.embeddedApps,
617
+ // and now the new fields
377
618
  ...newLocus,
378
619
  htMeta: newLocusHtMeta,
379
620
  participants: [], // empty means there were no participant updates
380
- jsSdkMeta: {removedParticipantIds: []}, // no participants were removed
621
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false}, // no participants were removed
622
+ });
623
+ });
624
+
625
+ // this test is checking that we cope with an edge case if Locus
626
+ // sends us something that they shouldn't
627
+ it('should process locus update correctly when called with updated LOCUS object that contains info/fullState/self/participants etc', () => {
628
+ // setup new updated locus that has many things missing
629
+ const newLocusHtMeta = {elementId: {type: 'locus', version: 42}};
630
+ const newLocus = {
631
+ host: 'new-host',
632
+ htMeta: newLocusHtMeta,
633
+ };
634
+
635
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
636
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
637
+ updatedObjects: [
638
+ {
639
+ htMeta: newLocusHtMeta,
640
+ data: {
641
+ ...newLocus,
642
+ // all these fields below should be ignored and not override the existing ones in our "old" Locus
643
+ controls: {id: 'new-controls'},
644
+ info: 'new-info',
645
+ fullState: 'new-fullState',
646
+ self: 'new-self',
647
+ participants: 'new-participants',
648
+ mediaShares: 'new-mediaShares',
649
+ embeddedApps: 'new-embeddedApps',
650
+ },
651
+ },
652
+ ],
653
+ });
654
+
655
+ // check onDeltaLocus() was called with correctly updated locus info
656
+ // with old values for the fields that should be ignored (like "info" or "fullState")
657
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
658
+ // these fields have the "old" values:
659
+ controls: {id: 'fake-controls'},
660
+ info: {id: 'fake-info'},
661
+ fullState: {id: 'fake-full-state'},
662
+ self: {id: 'fake-self'},
663
+ links: {id: 'fake-links'},
664
+ mediaShares: expectedLocusInfo.mediaShares,
665
+ embeddedApps: expectedLocusInfo.embeddedApps,
666
+ participants: [], // empty means there were no participant updates
667
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false}, // no participants were removed
668
+ ...newLocus,
669
+ htMeta: newLocusHtMeta,
381
670
  });
382
671
  });
383
672
 
@@ -391,7 +680,7 @@ describe('plugin-meetings', () => {
391
680
  };
392
681
 
393
682
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
394
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
683
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
395
684
  updatedObjects: [
396
685
  // first, a removal of LOCUS object
397
686
  {htMeta: {elementId: {type: 'locus'}}, data: null},
@@ -402,10 +691,19 @@ describe('plugin-meetings', () => {
402
691
 
403
692
  // check onDeltaLocus() was called with correctly updated locus info
404
693
  assert.calledOnceWithExactly(onDeltaLocusStub, {
694
+ // these fields are not part of Locus object, so should keep their old values:
695
+ controls: {id: 'fake-controls'},
696
+ info: {id: 'fake-info'},
697
+ fullState: {id: 'fake-full-state'},
698
+ self: {id: 'fake-self'},
699
+ links: {id: 'fake-links'},
700
+ mediaShares: expectedLocusInfo.mediaShares,
701
+ embeddedApps: expectedLocusInfo.embeddedApps,
702
+ // and now the new fields
405
703
  ...newLocus,
406
704
  htMeta: newLocusHtMeta,
407
705
  participants: [], // empty means there were no participant updates
408
- jsSdkMeta: {removedParticipantIds: []}, // no participants were removed
706
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false}, // no participants were removed
409
707
  });
410
708
  });
411
709
 
@@ -416,7 +714,7 @@ describe('plugin-meetings', () => {
416
714
  const newLocusHtMeta = {elementId: {type: 'locus', version: 99}};
417
715
 
418
716
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
419
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
717
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
420
718
  updatedObjects: [
421
719
  // first, an update
422
720
  {htMeta: newLocusHtMeta, data: newLocus},
@@ -445,7 +743,7 @@ describe('plugin-meetings', () => {
445
743
  };
446
744
 
447
745
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
448
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
746
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
449
747
  updatedObjects: [
450
748
  // first, an update
451
749
  {htMeta: {elementId: {type: 'locus'}}, data: newLocus1},
@@ -475,7 +773,7 @@ describe('plugin-meetings', () => {
475
773
  };
476
774
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
477
775
  // with 1 participant added, 1 updated, and 1 removed
478
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
776
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
479
777
  updatedObjects: [
480
778
  {htMeta: {elementId: {type: 'participant', id: 'fake-ht-participant-1'}}, data: null},
481
779
  {
@@ -493,7 +791,7 @@ describe('plugin-meetings', () => {
493
791
  assert.calledOnceWithExactly(onDeltaLocusStub, {
494
792
  ...expectedLocusInfo,
495
793
  participants: [newParticipant, updatedParticipant2],
496
- jsSdkMeta: {removedParticipantIds: ['fake-participant-1']},
794
+ jsSdkMeta: {removedParticipantIds: ['fake-participant-1'], forceReplaceMembers: false},
497
795
  });
498
796
  // and that the hashTreeObjectId2ParticipantId map was updated correctly
499
797
  assert.isUndefined(locusInfo.hashTreeObjectId2ParticipantId.get('fake-ht-participant-1'));
@@ -519,7 +817,7 @@ describe('plugin-meetings', () => {
519
817
  };
520
818
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
521
819
  // with 1 participant added, 1 updated, and 1 removed
522
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
820
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
523
821
  updatedObjects: [
524
822
  {htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-1'}}, data: null},
525
823
  {
@@ -540,6 +838,39 @@ describe('plugin-meetings', () => {
540
838
  });
541
839
  });
542
840
 
841
+ it('should process locus update correctly when called with updated EMBEDDEDAPP objects', () => {
842
+ const newEmbeddedApp = {
843
+ id: 'new-embedded-app-3',
844
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-3', version: 100}},
845
+ };
846
+ const updatedEmbeddedApp2 = {
847
+ id: 'fake-embedded-app-2',
848
+ someNewProp: 'newValue',
849
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2', version: 100}},
850
+ };
851
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
852
+ // with 1 embedded app added, 1 updated, and 1 removed
853
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
854
+ updatedObjects: [
855
+ {htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-1'}}, data: null},
856
+ {
857
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2'}},
858
+ data: updatedEmbeddedApp2,
859
+ },
860
+ {
861
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-3'}},
862
+ data: newEmbeddedApp,
863
+ },
864
+ ],
865
+ });
866
+
867
+ // check onDeltaLocus() was called with correctly updated locus info
868
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
869
+ ...expectedLocusInfo,
870
+ embeddedApps: [updatedEmbeddedApp2, newEmbeddedApp],
871
+ });
872
+ });
873
+
543
874
  it('should process locus update correctly when called with a combination of various updated objects', () => {
544
875
  const newSelf = {
545
876
  id: 'new-self',
@@ -556,7 +887,7 @@ describe('plugin-meetings', () => {
556
887
  };
557
888
 
558
889
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
559
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
890
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
560
891
  updatedObjects: [
561
892
  {
562
893
  htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-2'}},
@@ -585,6 +916,60 @@ describe('plugin-meetings', () => {
585
916
  });
586
917
  });
587
918
 
919
+ it('should process locus update correctly when called with multiple CONTROL object updates', () => {
920
+ const firstControl = {
921
+ muteOnEntry: {enabled: true},
922
+ lock: {locked: true, meta: {lastModified: 'YESTERDAY', modifiedBy: 'John Doe'}},
923
+ };
924
+ const secondControl = {
925
+ reactions: {enabled: true},
926
+ };
927
+
928
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
929
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
930
+ updatedObjects: [
931
+ {
932
+ htMeta: {elementId: {type: 'controlentry', id: 'control-1'}},
933
+ data: firstControl,
934
+ },
935
+ {
936
+ htMeta: {elementId: {type: 'controlentry', id: 'control-2'}},
937
+ data: secondControl,
938
+ },
939
+ ],
940
+ });
941
+
942
+ // check onDeltaLocus() was called with correctly updated locus info
943
+ // all keys from both controls should be merged into the controls object
944
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
945
+ ...expectedLocusInfo,
946
+ controls: {
947
+ id: 'fake-controls',
948
+ muteOnEntry: {enabled: true},
949
+ lock: {locked: true, meta: {lastModified: 'YESTERDAY', modifiedBy: 'John Doe'}},
950
+ reactions: {enabled: true},
951
+ },
952
+ });
953
+ });
954
+
955
+ it('should process locus update correctly when CONTROL object is received with no data', () => {
956
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
957
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
958
+ updatedObjects: [
959
+ {
960
+ htMeta: {elementId: {type: 'controlentry', id: 'some-control-id'}},
961
+ data: null,
962
+ },
963
+ ],
964
+ });
965
+
966
+ // check onDeltaLocus() was called with correctly updated locus info
967
+ // when data is null, it should be ignored and not change the controls
968
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
969
+ ...expectedLocusInfo,
970
+ });
971
+ });
972
+
588
973
  it('should handle MEETING_ENDED correctly', () => {
589
974
  const fakeMeeting = {id: 'fake-meeting-from-collection'};
590
975
  const collectionGetStub = sinon
@@ -593,7 +978,7 @@ describe('plugin-meetings', () => {
593
978
  const destroyStub = sinon.stub(locusInfo.webex.meetings, 'destroy');
594
979
 
595
980
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
596
- locusInfoUpdateCallback(MEETING_ENDED);
981
+ locusInfoUpdateCallback({updateType: MEETING_ENDED});
597
982
 
598
983
  assert.calledOnceWithExactly(collectionGetStub, locusInfo.meetingId);
599
984
  assert.calledOnceWithExactly(
@@ -602,50 +987,153 @@ describe('plugin-meetings', () => {
602
987
  MEETING_REMOVED_REASON.SELF_REMOVED
603
988
  );
604
989
  });
605
- });
606
- });
607
990
 
608
- describe('#updateControls', () => {
609
- let newControls;
991
+ // this could happen if meeting gets destroyed while we're doing some async hash tree operation like a sync
992
+ it('should handle MEETING_ENDED correctly when meeting is not found in the collection', () => {
993
+ const collectionGetStub = sinon
994
+ .stub(locusInfo.webex.meetings.meetingCollection, 'get')
995
+ .returns(null);
996
+ const destroyStub = sinon.stub(locusInfo.webex.meetings, 'destroy');
610
997
 
611
- beforeEach('setup new controls', () => {
612
- newControls = {
613
- disallowUnmute: {enabled: true},
614
- lock: {},
615
- meetingFull: {meetingFull: false, meetingPanelistFull: true},
616
- muteOnEntry: {enabled: true},
617
- raiseHand: {enabled: true},
618
- reactions: {enabled: true, showDisplayNameWithReactions: true},
619
- record: {
620
- recording: false,
621
- paused: false,
622
- meta: {
623
- lastModified: 'TODAY',
624
- modifiedBy: 'George Kittle',
625
- },
626
- },
627
- shareControl: {control: 'example-value'},
628
- transcribe: {},
629
- viewTheParticipantList: {enabled: true, panelistEnabled: true, attendeeCount: false},
630
- meetingContainer: {
631
- meetingContainerUrl: 'http://new-url.com',
632
- },
633
- entryExitTone: {enabled: true, mode: 'foo'},
634
- video: {enabled: true},
635
- videoLayout: {
636
- overrideDefault: true,
637
- lockAttendeeViewOnStageOnly: false,
638
- stageParameters: {},
639
- },
640
- webcastControl: {streaming: false},
641
- practiceSession: {enabled: true},
642
- annotationControl: {enabled: true},
643
- rdcControl: {enabled: true},
644
- };
645
- });
998
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
999
+ locusInfoUpdateCallback({updateType: MEETING_ENDED});
646
1000
 
647
- afterEach(() => {
648
- newControls = null;
1001
+ assert.calledOnceWithExactly(collectionGetStub, locusInfo.meetingId);
1002
+ assert.notCalled(destroyStub);
1003
+ });
1004
+
1005
+ it('should handle LOCUS_NOT_FOUND by calling syncMeetings with skipHashTreeSync', () => {
1006
+ const syncMeetingsStub = sinon.stub(locusInfo.webex.meetings, 'syncMeetings').resolves();
1007
+
1008
+ locusInfoUpdateCallback({updateType: LOCUS_NOT_FOUND});
1009
+
1010
+ assert.calledOnceWithExactly(syncMeetingsStub, {keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1011
+ });
1012
+
1013
+ it('should handle LOCUS_NOT_FOUND and log error if syncMeetings fails', async () => {
1014
+ const syncError = new Error('sync failed');
1015
+ const syncMeetingsStub = sinon.stub(locusInfo.webex.meetings, 'syncMeetings').rejects(syncError);
1016
+ const logErrorStub = LoggerProxy.logger.error?.isSinonProxy
1017
+ ? LoggerProxy.logger.error
1018
+ : sinon.stub(LoggerProxy.logger, 'error');
1019
+
1020
+ logErrorStub.resetHistory();
1021
+
1022
+ locusInfoUpdateCallback({updateType: LOCUS_NOT_FOUND});
1023
+
1024
+ assert.calledOnceWithExactly(syncMeetingsStub, {keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1025
+
1026
+ // wait for the promise rejection to be handled
1027
+ await testUtils.flushPromises();
1028
+
1029
+ assert.calledOnce(logErrorStub);
1030
+ assert.match(
1031
+ logErrorStub.firstCall.args[0],
1032
+ /syncMeetings failed after LOCUS_NOT_FOUND/
1033
+ );
1034
+ });
1035
+
1036
+ it('should set forceReplaceMembers to true on the first update for a locusUrl (initializedFromHashTree is false)', () => {
1037
+ const createdHashTreeParser = locusInfo.hashTreeParsers.get('fake-locus-url');
1038
+ createdHashTreeParser.initializedFromHashTree = false;
1039
+
1040
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
1041
+ updatedObjects: [
1042
+ {
1043
+ htMeta: {elementId: {type: 'self'}},
1044
+ data: {id: 'new-self'},
1045
+ },
1046
+ ],
1047
+ });
1048
+
1049
+ assert.calledOnce(onDeltaLocusStub);
1050
+ assert.equal(onDeltaLocusStub.firstCall.args[0].jsSdkMeta.forceReplaceMembers, true);
1051
+ assert.isTrue(createdHashTreeParser.initializedFromHashTree);
1052
+ });
1053
+
1054
+ it('should set forceReplaceMembers to false on subsequent updates (initializedFromHashTree is true)', () => {
1055
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
1056
+ updatedObjects: [
1057
+ {
1058
+ htMeta: {elementId: {type: 'self'}},
1059
+ data: {id: 'new-self'},
1060
+ },
1061
+ ],
1062
+ });
1063
+
1064
+ assert.calledOnce(onDeltaLocusStub);
1065
+ assert.equal(onDeltaLocusStub.firstCall.args[0].jsSdkMeta.forceReplaceMembers, false);
1066
+ });
1067
+
1068
+ it('should copy participant data to self when participant matches self identity and state is LEFT with reason MOVED', () => {
1069
+ locusInfo.self = {id: 'fake-self', identity: 'user-123'};
1070
+
1071
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
1072
+ updatedObjects: [
1073
+ {
1074
+ htMeta: {elementId: {type: 'participant', id: 99}},
1075
+ data: {
1076
+ id: 'participant-matching-self',
1077
+ identity: 'user-123',
1078
+ state: 'LEFT',
1079
+ reason: 'MOVED',
1080
+ roles: ['MODERATOR'],
1081
+ },
1082
+ },
1083
+ ],
1084
+ });
1085
+
1086
+ assert.calledOnce(onDeltaLocusStub);
1087
+ const passedLocus = onDeltaLocusStub.firstCall.args[0];
1088
+
1089
+ assert.equal(passedLocus.self.identity, 'user-123');
1090
+ assert.equal(passedLocus.self.state, 'LEFT');
1091
+ assert.equal(passedLocus.self.reason, 'MOVED');
1092
+ });
1093
+ });
1094
+ });
1095
+
1096
+ describe('#updateControls', () => {
1097
+ let newControls;
1098
+
1099
+ beforeEach('setup new controls', () => {
1100
+ newControls = {
1101
+ disallowUnmute: {enabled: true},
1102
+ lock: {},
1103
+ meetingFull: {meetingFull: false, meetingPanelistFull: true},
1104
+ muteOnEntry: {enabled: true},
1105
+ raiseHand: {enabled: true},
1106
+ reactions: {enabled: true, showDisplayNameWithReactions: true},
1107
+ record: {
1108
+ recording: false,
1109
+ paused: false,
1110
+ meta: {
1111
+ lastModified: 'TODAY',
1112
+ modifiedBy: 'George Kittle',
1113
+ },
1114
+ },
1115
+ shareControl: {control: 'example-value'},
1116
+ transcribe: {},
1117
+ viewTheParticipantList: {enabled: true, panelistEnabled: true, attendeeCount: false},
1118
+ meetingContainer: {
1119
+ meetingContainerUrl: 'http://new-url.com',
1120
+ },
1121
+ entryExitTone: {enabled: true, mode: 'foo'},
1122
+ video: {enabled: true},
1123
+ videoLayout: {
1124
+ overrideDefault: true,
1125
+ lockAttendeeViewOnStageOnly: false,
1126
+ stageParameters: {},
1127
+ },
1128
+ webcastControl: {streaming: false},
1129
+ practiceSession: {enabled: true},
1130
+ annotationControl: {enabled: true},
1131
+ rdcControl: {enabled: true},
1132
+ };
1133
+ });
1134
+
1135
+ afterEach(() => {
1136
+ newControls = null;
649
1137
  });
650
1138
 
651
1139
  it('should update the controls object', () => {
@@ -837,7 +1325,7 @@ describe('plugin-meetings', () => {
837
1325
  it('should trigger the CONTROLS_POLLING_QA_CHANGED event when necessary', () => {
838
1326
  locusInfo.controls = {};
839
1327
  locusInfo.emitScoped = sinon.stub();
840
- newControls.pollingQAControl = { enabled: true };
1328
+ newControls.pollingQAControl = {enabled: true};
841
1329
  locusInfo.updateControls(newControls);
842
1330
 
843
1331
  assert.calledWith(
@@ -875,6 +1363,8 @@ describe('plugin-meetings', () => {
875
1363
  state: RECORDING_STATE.IDLE,
876
1364
  modifiedBy: 'George Kittle',
877
1365
  lastModified: 'TODAY',
1366
+ modifiedByServiceAppName: undefined,
1367
+ modifiedByServiceAppId: undefined,
878
1368
  }
879
1369
  );
880
1370
  });
@@ -909,6 +1399,8 @@ describe('plugin-meetings', () => {
909
1399
  state: RECORDING_STATE.RECORDING,
910
1400
  modifiedBy: 'George Kittle',
911
1401
  lastModified: 'TODAY',
1402
+ modifiedByServiceAppName: undefined,
1403
+ modifiedByServiceAppId: undefined,
912
1404
  }
913
1405
  );
914
1406
  });
@@ -944,6 +1436,8 @@ describe('plugin-meetings', () => {
944
1436
  state: RECORDING_STATE.PAUSED,
945
1437
  modifiedBy: 'George Kittle',
946
1438
  lastModified: 'TODAY',
1439
+ modifiedByServiceAppName: undefined,
1440
+ modifiedByServiceAppId: undefined,
947
1441
  }
948
1442
  );
949
1443
  });
@@ -980,6 +1474,8 @@ describe('plugin-meetings', () => {
980
1474
  state: RECORDING_STATE.RESUMED,
981
1475
  modifiedBy: 'George Kittle',
982
1476
  lastModified: 'TODAY',
1477
+ modifiedByServiceAppName: undefined,
1478
+ modifiedByServiceAppId: undefined,
983
1479
  }
984
1480
  );
985
1481
  });
@@ -1015,6 +1511,44 @@ describe('plugin-meetings', () => {
1015
1511
  state: RECORDING_STATE.IDLE,
1016
1512
  modifiedBy: 'George Kittle',
1017
1513
  lastModified: 'TODAY',
1514
+ modifiedByServiceAppName: undefined,
1515
+ modifiedByServiceAppId: undefined,
1516
+ }
1517
+ );
1518
+ });
1519
+
1520
+ it('should include service app fields in the recording event when present', () => {
1521
+ locusInfo.controls = {
1522
+ record: {
1523
+ recording: false,
1524
+ paused: false,
1525
+ meta: {
1526
+ lastModified: 'TODAY',
1527
+ modifiedBy: 'George Kittle',
1528
+ },
1529
+ },
1530
+ shareControl: {},
1531
+ transcribe: {},
1532
+ };
1533
+ newControls.record.recording = true;
1534
+ newControls.record.meta.modifiedByServiceAppName = 'My Bot';
1535
+ newControls.record.meta.modifiedByServiceAppId = 'app-id-123';
1536
+ locusInfo.emitScoped = sinon.stub();
1537
+ locusInfo.updateControls(newControls);
1538
+
1539
+ assert.calledWith(
1540
+ locusInfo.emitScoped,
1541
+ {
1542
+ file: 'locus-info',
1543
+ function: 'updateControls',
1544
+ },
1545
+ LOCUSINFO.EVENTS.CONTROLS_RECORDING_UPDATED,
1546
+ {
1547
+ state: RECORDING_STATE.RECORDING,
1548
+ modifiedBy: 'George Kittle',
1549
+ lastModified: 'TODAY',
1550
+ modifiedByServiceAppName: 'My Bot',
1551
+ modifiedByServiceAppId: 'app-id-123',
1018
1552
  }
1019
1553
  );
1020
1554
  });
@@ -1099,6 +1633,62 @@ describe('plugin-meetings', () => {
1099
1633
  );
1100
1634
  });
1101
1635
 
1636
+ it('should update the hesiod llm id', () => {
1637
+ locusInfo.emitScoped = sinon.stub();
1638
+ locusInfo.controls = {
1639
+ transcribe: {
1640
+ transcribing: false,
1641
+ caption: true,
1642
+ hesiodLlmId: '123a-456b-789c',
1643
+ },
1644
+ };
1645
+ newControls.transcribe.transcribing = false;
1646
+ newControls.transcribe.caption = true;
1647
+ newControls.transcribe.hesiodLlmId = '789d-456e-123f';
1648
+
1649
+ locusInfo.updateControls(newControls);
1650
+
1651
+ assert.calledWith(
1652
+ locusInfo.emitScoped,
1653
+ {
1654
+ file: 'locus-info',
1655
+ function: 'updateControls',
1656
+ },
1657
+ LOCUSINFO.EVENTS.CONTROLS_MEETING_HESIOD_LLM_ID_UPDATED,
1658
+ {
1659
+ hesiodLlmId: '789d-456e-123f',
1660
+ }
1661
+ );
1662
+ });
1663
+
1664
+ it('should emit CONTROLS_AI_SUMMARY_NOTIFICATION_UPDATED when aiSummaryNotification changes', () => {
1665
+ locusInfo.emitScoped = sinon.stub();
1666
+ locusInfo.controls = {
1667
+ transcribe: {
1668
+ transcribing: false,
1669
+ caption: false,
1670
+ aiSummaryNotification: false,
1671
+ },
1672
+ };
1673
+ newControls.transcribe.transcribing = false;
1674
+ newControls.transcribe.caption = false;
1675
+ newControls.transcribe.aiSummaryNotification = true;
1676
+
1677
+ locusInfo.updateControls(newControls);
1678
+
1679
+ assert.calledWith(
1680
+ locusInfo.emitScoped,
1681
+ {
1682
+ file: 'locus-info',
1683
+ function: 'updateControls',
1684
+ },
1685
+ LOCUSINFO.EVENTS.CONTROLS_AI_SUMMARY_NOTIFICATION_UPDATED,
1686
+ {
1687
+ aiSummaryNotification: true,
1688
+ }
1689
+ );
1690
+ });
1691
+
1102
1692
  it('should update the transcribe spoken language', () => {
1103
1693
  locusInfo.emitScoped = sinon.stub();
1104
1694
  locusInfo.controls = {
@@ -1364,7 +1954,6 @@ describe('plugin-meetings', () => {
1364
1954
  );
1365
1955
  });
1366
1956
 
1367
-
1368
1957
  it('should call with participant display name', () => {
1369
1958
  const failureParticipant = [
1370
1959
  {
@@ -1389,7 +1978,7 @@ describe('plugin-meetings', () => {
1389
1978
  displayName: 'Test User',
1390
1979
  }
1391
1980
  );
1392
- })
1981
+ });
1393
1982
  });
1394
1983
 
1395
1984
  describe('#updateSelf', () => {
@@ -1555,7 +2144,7 @@ describe('plugin-meetings', () => {
1555
2144
  function: 'updateSelf',
1556
2145
  },
1557
2146
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1558
- {muted: true, unmuteAllowed: true}
2147
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
1559
2148
  );
1560
2149
 
1561
2150
  // but sometimes "previous self" is defined, but without controls.audio.muted, so we test this here:
@@ -1570,7 +2159,7 @@ describe('plugin-meetings', () => {
1570
2159
  function: 'updateSelf',
1571
2160
  },
1572
2161
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1573
- {muted: true, unmuteAllowed: true}
2162
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
1574
2163
  );
1575
2164
  });
1576
2165
 
@@ -1629,7 +2218,7 @@ describe('plugin-meetings', () => {
1629
2218
  function: 'updateSelf',
1630
2219
  },
1631
2220
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1632
- {muted: true, unmuteAllowed: true}
2221
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
1633
2222
  );
1634
2223
  });
1635
2224
 
@@ -1768,7 +2357,7 @@ describe('plugin-meetings', () => {
1768
2357
  function: 'updateSelf',
1769
2358
  },
1770
2359
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1771
- {muted: true, unmuteAllowed: false}
2360
+ {muted: true, unmuteAllowed: false, modifiedBy: null}
1772
2361
  );
1773
2362
 
1774
2363
  // now change only disallowUnmute
@@ -1786,7 +2375,28 @@ describe('plugin-meetings', () => {
1786
2375
  function: 'updateSelf',
1787
2376
  },
1788
2377
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1789
- {muted: true, unmuteAllowed: true}
2378
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
2379
+ );
2380
+ });
2381
+
2382
+ it('should include modifiedBy in payload when muted by host', () => {
2383
+ locusInfo.webex.internal.device.url = self.deviceUrl;
2384
+ locusInfo.updateSelf(self);
2385
+ const newSelf = cloneDeep(self);
2386
+ newSelf.controls.audio.muted = true;
2387
+ newSelf.controls.audio.meta = {modifiedBy: 'host-uuid-123'};
2388
+
2389
+ locusInfo.emitScoped = sinon.stub();
2390
+ locusInfo.updateSelf(newSelf);
2391
+
2392
+ assert.calledWith(
2393
+ locusInfo.emitScoped,
2394
+ {
2395
+ file: 'locus-info',
2396
+ function: 'updateSelf',
2397
+ },
2398
+ LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
2399
+ {muted: true, unmuteAllowed: true, modifiedBy: 'host-uuid-123'}
1790
2400
  );
1791
2401
  });
1792
2402
 
@@ -2190,8 +2800,8 @@ describe('plugin-meetings', () => {
2190
2800
  {
2191
2801
  isInitializing: !self,
2192
2802
  }
2193
- );
2194
- });
2803
+ );
2804
+ });
2195
2805
 
2196
2806
  const checkMeetingInfoUpdatedCalled = (expected, payload) => {
2197
2807
  const expectedArgs = [
@@ -2236,6 +2846,10 @@ describe('plugin-meetings', () => {
2236
2846
 
2237
2847
  let expectedMeeting;
2238
2848
 
2849
+ // simulate that updateSelf has been called previously (as happens in production)
2850
+ // so that parsedLocus.self reflects the joined state
2851
+ locusInfo.parsedLocus.self = {state: 'JOINED'};
2852
+
2239
2853
  /*
2240
2854
  When the event is triggered, it is required that the meeting has already
2241
2855
  been updated. This is why the meeting is being checked within the stubbed event emitter
@@ -2246,6 +2860,7 @@ describe('plugin-meetings', () => {
2246
2860
 
2247
2861
  // set the info initially as locusInfo.info starts as undefined
2248
2862
  expectedMeeting = {
2863
+ attendee: {},
2249
2864
  coHost: {
2250
2865
  LOWER_SOMEONE_ELSES_HAND: true,
2251
2866
  },
@@ -2254,10 +2869,12 @@ describe('plugin-meetings', () => {
2254
2869
  moderator: {
2255
2870
  LOWER_SOMEONE_ELSES_HAND: true,
2256
2871
  },
2872
+ panelist: {},
2257
2873
  policy: {
2258
2874
  LOCK_STATUS_UNLOCKED: true,
2259
2875
  ROSTER_IN_MEETING: true,
2260
2876
  },
2877
+ presenter: {},
2261
2878
  userDisplayHints: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED'],
2262
2879
  };
2263
2880
  locusInfo.updateMeetingInfo(initialInfo, self);
@@ -2272,6 +2889,7 @@ describe('plugin-meetings', () => {
2272
2889
 
2273
2890
  // Updating with different info should trigger the event
2274
2891
  expectedMeeting = {
2892
+ attendee: {},
2275
2893
  coHost: {
2276
2894
  LOWER_SOMEONE_ELSES_HAND: true,
2277
2895
  LOCK_CONTROL_LOCK: true,
@@ -2281,10 +2899,12 @@ describe('plugin-meetings', () => {
2281
2899
  moderator: {
2282
2900
  LOWER_SOMEONE_ELSES_HAND: true,
2283
2901
  },
2902
+ panelist: {},
2284
2903
  policy: {
2285
2904
  LOCK_STATUS_UNLOCKED: true,
2286
2905
  ROSTER_IN_MEETING: true,
2287
2906
  },
2907
+ presenter: {},
2288
2908
  userDisplayHints: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED'],
2289
2909
  };
2290
2910
  locusInfo.updateMeetingInfo(newInfo, self);
@@ -2293,6 +2913,7 @@ describe('plugin-meetings', () => {
2293
2913
 
2294
2914
  // update it with the same info
2295
2915
  expectedMeeting = {
2916
+ attendee: {},
2296
2917
  coHost: {
2297
2918
  LOWER_SOMEONE_ELSES_HAND: true,
2298
2919
  LOCK_CONTROL_LOCK: true,
@@ -2302,10 +2923,12 @@ describe('plugin-meetings', () => {
2302
2923
  moderator: {
2303
2924
  LOWER_SOMEONE_ELSES_HAND: true,
2304
2925
  },
2926
+ panelist: {},
2305
2927
  policy: {
2306
2928
  LOCK_STATUS_UNLOCKED: true,
2307
2929
  ROSTER_IN_MEETING: true,
2308
2930
  },
2931
+ presenter: {},
2309
2932
  userDisplayHints: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED'],
2310
2933
  };
2311
2934
  locusInfo.updateMeetingInfo(newInfo, self);
@@ -2320,6 +2943,7 @@ describe('plugin-meetings', () => {
2320
2943
  hasRole: true,
2321
2944
  });
2322
2945
  expectedMeeting = {
2946
+ attendee: {},
2323
2947
  coHost: {
2324
2948
  LOWER_SOMEONE_ELSES_HAND: true,
2325
2949
  LOCK_CONTROL_LOCK: true,
@@ -2329,10 +2953,12 @@ describe('plugin-meetings', () => {
2329
2953
  moderator: {
2330
2954
  LOWER_SOMEONE_ELSES_HAND: true,
2331
2955
  },
2956
+ panelist: {},
2332
2957
  policy: {
2333
2958
  LOCK_STATUS_UNLOCKED: true,
2334
2959
  ROSTER_IN_MEETING: true,
2335
2960
  },
2961
+ presenter: {},
2336
2962
  userDisplayHints: [
2337
2963
  'ROSTER_IN_MEETING',
2338
2964
  'LOCK_STATUS_UNLOCKED',
@@ -2375,6 +3001,46 @@ describe('plugin-meetings', () => {
2375
3001
  // since self is not passed to updateMeetingInfo, MEETING_INFO_UPDATED should be triggered with isIntializing: true
2376
3002
  checkMeetingInfoUpdatedCalledForRoles(true, {isInitializing: true});
2377
3003
  });
3004
+
3005
+ // joined-section hints (like ROSTER_IN_MEETING) are filtered out while not joined, so they
3006
+ // are a good proxy for verifying that userDisplayHints get recomputed on a join transition
3007
+ [
3008
+ {
3009
+ name: 'the JOINED delta carries the info section',
3010
+ getSecondInfo: (info) => info,
3011
+ },
3012
+ {
3013
+ name: 'the JOINED delta omits the info section (falls back to stored info)',
3014
+ getSecondInfo: () => undefined,
3015
+ },
3016
+ ].forEach(({name, getSecondInfo}) => {
3017
+ it(`recomputes userDisplayHints when self transitions to JOINED with unchanged roles and ${name}`, () => {
3018
+ const info = cloneDeep(meetingInfo); // joined: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED']
3019
+
3020
+ const notJoinedSelf = cloneDeep(self);
3021
+ notJoinedSelf.state = 'IDLE';
3022
+ notJoinedSelf.controls.role.roles = [];
3023
+
3024
+ const joinedSelf = cloneDeep(self);
3025
+ joinedSelf.state = 'JOINED';
3026
+ joinedSelf.controls.role.roles = [];
3027
+
3028
+ sinon.stub(locusInfo, 'emitScoped');
3029
+
3030
+ // first update while not joined: joined-section hints are filtered out
3031
+ locusInfo.updateMeetingInfo(info, notJoinedSelf);
3032
+ assert.notInclude(locusInfo.parsedLocus.info.userDisplayHints, 'ROSTER_IN_MEETING');
3033
+ assert.notInclude(locusInfo.parsedLocus.info.userDisplayHints, 'LOCK_STATUS_UNLOCKED');
3034
+
3035
+ // self transitions to JOINED - info and roles are unchanged
3036
+ locusInfo.updateMeetingInfo(getSecondInfo(info), joinedSelf);
3037
+
3038
+ // the hints must be recomputed with the new joined state
3039
+ assert.include(locusInfo.parsedLocus.info.userDisplayHints, 'ROSTER_IN_MEETING');
3040
+ assert.include(locusInfo.parsedLocus.info.userDisplayHints, 'LOCK_STATUS_UNLOCKED');
3041
+ checkMeetingInfoUpdatedCalled(true, {isInitializing: false});
3042
+ });
3043
+ });
2378
3044
  });
2379
3045
 
2380
3046
  describe('#updateMediaShares', () => {
@@ -2568,6 +3234,379 @@ describe('plugin-meetings', () => {
2568
3234
  });
2569
3235
  });
2570
3236
 
3237
+ describe('#createHashTreeParser', () => {
3238
+ let HashTreeParserStub;
3239
+
3240
+ beforeEach(() => {
3241
+ HashTreeParserStub = sinon
3242
+ .stub(HashTreeParserModule, 'default')
3243
+ .returns({
3244
+ initializeFromMessage: sinon.stub().resolves(),
3245
+ initializeFromGetLociResponse: sinon.stub().resolves(),
3246
+ state: 'active',
3247
+ stop: sinon.stub(),
3248
+ handleMessage: sinon.stub(),
3249
+ });
3250
+ });
3251
+
3252
+ const setupParserViaInitialSetup = async (locusUrl = 'http://locus-url-A.com') => {
3253
+ await locusInfo.initialSetup({
3254
+ trigger: 'locus-message',
3255
+ hashTreeMessage: {
3256
+ locusUrl,
3257
+ locusStateElements: [
3258
+ {
3259
+ htMeta: {elementId: {type: 'Metadata'}},
3260
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
3261
+ },
3262
+ ],
3263
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3264
+ },
3265
+ });
3266
+ };
3267
+
3268
+ it('should stop existing active parsers when creating a new one', async () => {
3269
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3270
+
3271
+ const firstParser = locusInfo.hashTreeParsers.get('http://locus-url-A.com').parser;
3272
+
3273
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3274
+
3275
+ assert.calledOnce(firstParser.stop);
3276
+ });
3277
+
3278
+ it('should set replacedAt on existing entries when replacedAt is provided', async () => {
3279
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3280
+
3281
+ // Call createHashTreeParser with replacedAt via parse -> handleHashTreeParserSwitch
3282
+ // which calls createHashTreeParser with replacedAt from the self element
3283
+ locusInfo.webex.internal.device.url = 'http://device-url.com';
3284
+ const message = {
3285
+ locusUrl: 'http://locus-url-B.com',
3286
+ locusStateElements: [
3287
+ {
3288
+ htMeta: {elementId: {type: 'Metadata'}},
3289
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
3290
+ },
3291
+ {
3292
+ htMeta: {elementId: {type: 'Self'}},
3293
+ data: {
3294
+ devices: [{url: 'http://device-url.com', replaces: [{locusUrl: 'http://locus-url-A.com', replacedAt: '2026-01-01T00:00:00Z'}]}],
3295
+ },
3296
+ },
3297
+ ],
3298
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3299
+ };
3300
+
3301
+ locusInfo.parse(mockMeeting, {
3302
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3303
+ stateElementsMessage: message,
3304
+ });
3305
+
3306
+ assert.equal(locusInfo.hashTreeParsers.get('http://locus-url-A.com').replacedAt, '2026-01-01T00:00:00Z');
3307
+ });
3308
+
3309
+ it('should not set replacedAt on existing entries when replacedAt is not provided', async () => {
3310
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3311
+
3312
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3313
+
3314
+ assert.isUndefined(locusInfo.hashTreeParsers.get('http://locus-url-A.com').replacedAt);
3315
+ });
3316
+
3317
+ it('should store the new parser in hashTreeParsers map with the correct locusUrl key', async () => {
3318
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3319
+
3320
+ assert.isTrue(locusInfo.hashTreeParsers.has('http://locus-url-A.com'));
3321
+ assert.isDefined(locusInfo.hashTreeParsers.get('http://locus-url-A.com').parser);
3322
+ });
3323
+
3324
+ it('should clear hashTreeObjectId2ParticipantId when creating a new parser', async () => {
3325
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3326
+ locusInfo.hashTreeObjectId2ParticipantId.set(1, 'participant-1');
3327
+
3328
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3329
+
3330
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.size, 0);
3331
+ });
3332
+
3333
+ it('should not stop already stopped parsers', async () => {
3334
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3335
+ const firstParser = locusInfo.hashTreeParsers.get('http://locus-url-A.com').parser;
3336
+ firstParser.state = 'stopped';
3337
+
3338
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3339
+
3340
+ assert.notCalled(firstParser.stop);
3341
+ });
3342
+ });
3343
+
3344
+ describe('#handleHashTreeParserSwitch', () => {
3345
+ const deviceUrl = 'http://device-url.com';
3346
+ const locusUrlA = 'http://locus-url-A.com';
3347
+ const locusUrlB = 'http://locus-url-B.com';
3348
+
3349
+ let HashTreeParserStub;
3350
+
3351
+ const createMockParser = (state = 'active') => ({
3352
+ state,
3353
+ stop: sinon.stub(),
3354
+ resumeFromMessage: sinon.stub(),
3355
+ handleMessage: sinon.stub(),
3356
+ });
3357
+
3358
+ const createSelfElementWithReplaces = (replacedLocusUrl, replacedAt) => ({
3359
+ htMeta: {elementId: {type: 'Self'}},
3360
+ data: {
3361
+ deviceUrl,
3362
+ devices: [{url: deviceUrl, replaces: [{locusUrl: replacedLocusUrl, replacedAt}]}],
3363
+ },
3364
+ });
3365
+
3366
+ const createMetadataElement = () => ({
3367
+ htMeta: {elementId: {type: 'Metadata'}},
3368
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
3369
+ });
3370
+
3371
+ beforeEach(() => {
3372
+ locusInfo.webex.internal.device.url = deviceUrl;
3373
+ HashTreeParserStub = sinon
3374
+ .stub(HashTreeParserModule, 'default')
3375
+ .returns(createMockParser());
3376
+ });
3377
+
3378
+ it('should create a new parser when no entry exists for locusUrl and metadata has visibleDataSets', () => {
3379
+ // set up an existing parser for a different url
3380
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockParser(), initializedFromHashTree: true});
3381
+
3382
+ const message = {
3383
+ locusUrl: locusUrlB,
3384
+ locusStateElements: [createMetadataElement()],
3385
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3386
+ };
3387
+
3388
+ locusInfo.parse(mockMeeting, {
3389
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3390
+ stateElementsMessage: message,
3391
+ });
3392
+
3393
+ assert.isTrue(locusInfo.hashTreeParsers.has(locusUrlB));
3394
+ });
3395
+
3396
+ it('should return true when no entry exists even if no metadata is available', () => {
3397
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockParser(), initializedFromHashTree: true});
3398
+ const parserA = locusInfo.hashTreeParsers.get(locusUrlA).parser;
3399
+
3400
+ const message = {
3401
+ locusUrl: locusUrlB,
3402
+ locusStateElements: [],
3403
+ dataSets: [],
3404
+ };
3405
+
3406
+ locusInfo.parse(mockMeeting, {
3407
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3408
+ stateElementsMessage: message,
3409
+ });
3410
+
3411
+ // no new parser created since no metadata
3412
+ assert.isFalse(locusInfo.hashTreeParsers.has(locusUrlB));
3413
+ // the existing parser's handleMessage should NOT have been called
3414
+ assert.notCalled(parserA.handleMessage);
3415
+ });
3416
+
3417
+ it('should resume a stopped parser when replaces info is newer', () => {
3418
+ const parserA = createMockParser('stopped');
3419
+ const parserB = createMockParser('active');
3420
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-01-01T00:00:00Z', initializedFromHashTree: true});
3421
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3422
+
3423
+ const message = {
3424
+ locusUrl: locusUrlA,
3425
+ locusStateElements: [
3426
+ createSelfElementWithReplaces(locusUrlB, '2026-02-01T00:00:00Z'),
3427
+ createMetadataElement(),
3428
+ ],
3429
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3430
+ };
3431
+
3432
+ locusInfo.parse(mockMeeting, {
3433
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3434
+ stateElementsMessage: message,
3435
+ });
3436
+
3437
+ assert.calledOnce(parserA.resumeFromMessage);
3438
+ assert.calledOnce(parserB.stop);
3439
+ });
3440
+
3441
+ it('should not resume a stopped parser when replaces info is not newer', () => {
3442
+ const parserA = createMockParser('stopped');
3443
+ const parserB = createMockParser('active');
3444
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-03-01T00:00:00Z', initializedFromHashTree: true});
3445
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3446
+
3447
+ const message = {
3448
+ locusUrl: locusUrlA,
3449
+ locusStateElements: [
3450
+ createSelfElementWithReplaces(locusUrlB, '2026-01-01T00:00:00Z'),
3451
+ ],
3452
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3453
+ };
3454
+
3455
+ locusInfo.parse(mockMeeting, {
3456
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3457
+ stateElementsMessage: message,
3458
+ });
3459
+
3460
+ assert.notCalled(parserA.resumeFromMessage);
3461
+ assert.notCalled(parserB.stop);
3462
+ });
3463
+
3464
+ it('should return true for a stopped parser with no replaces info', () => {
3465
+ const parserA = createMockParser('stopped');
3466
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3467
+
3468
+ const message = {
3469
+ locusUrl: locusUrlA,
3470
+ locusStateElements: [],
3471
+ dataSets: [],
3472
+ };
3473
+
3474
+ locusInfo.parse(mockMeeting, {
3475
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3476
+ stateElementsMessage: message,
3477
+ });
3478
+
3479
+ assert.notCalled(parserA.resumeFromMessage);
3480
+ assert.notCalled(parserA.handleMessage);
3481
+ });
3482
+
3483
+ it('should return false when the entry exists and parser is active', () => {
3484
+ const parserA = createMockParser('active');
3485
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3486
+
3487
+ const message = {
3488
+ locusUrl: locusUrlA,
3489
+ locusStateElements: [],
3490
+ dataSets: [],
3491
+ };
3492
+
3493
+ locusInfo.parse(mockMeeting, {
3494
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3495
+ stateElementsMessage: message,
3496
+ });
3497
+
3498
+ assert.calledOnceWithExactly(parserA.handleMessage, message);
3499
+ });
3500
+
3501
+ it('should pass replacedAt from replaces to createHashTreeParser when creating a new parser', () => {
3502
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockParser(), initializedFromHashTree: true});
3503
+
3504
+ const message = {
3505
+ locusUrl: locusUrlB,
3506
+ locusStateElements: [
3507
+ createMetadataElement(),
3508
+ createSelfElementWithReplaces(locusUrlA, '2026-05-01T00:00:00Z'),
3509
+ ],
3510
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3511
+ };
3512
+
3513
+ locusInfo.parse(mockMeeting, {
3514
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3515
+ stateElementsMessage: message,
3516
+ });
3517
+
3518
+ assert.isTrue(locusInfo.hashTreeParsers.has(locusUrlB));
3519
+ assert.equal(locusInfo.hashTreeParsers.get(locusUrlA).replacedAt, '2026-05-01T00:00:00Z');
3520
+ });
3521
+ });
3522
+
3523
+ describe('#handleHashTreeMessage', () => {
3524
+ it('should call handleHashTreeParserSwitch and not call handleMessage if parser was switched', () => {
3525
+ const locusUrlA = 'http://locus-url-A.com';
3526
+ const locusUrlB = 'http://locus-url-B.com';
3527
+ const parserA = {state: 'stopped', handleMessage: sinon.stub(), resume: sinon.stub(), stop: sinon.stub()};
3528
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3529
+
3530
+ // message for a stopped parser without replaces -> handleHashTreeParserSwitch returns true
3531
+ const message = {
3532
+ locusUrl: locusUrlA,
3533
+ locusStateElements: [],
3534
+ dataSets: [],
3535
+ };
3536
+
3537
+ locusInfo.parse(mockMeeting, {
3538
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3539
+ stateElementsMessage: message,
3540
+ });
3541
+
3542
+ assert.notCalled(parserA.handleMessage);
3543
+ });
3544
+
3545
+ it('should call handleMessage on the correct parser when no switch occurs', () => {
3546
+ const locusUrlA = 'http://locus-url-A.com';
3547
+ const parserA = {state: 'active', handleMessage: sinon.stub()};
3548
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3549
+
3550
+ const message = {
3551
+ locusUrl: locusUrlA,
3552
+ locusStateElements: [],
3553
+ dataSets: [],
3554
+ };
3555
+
3556
+ locusInfo.parse(mockMeeting, {
3557
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3558
+ stateElementsMessage: message,
3559
+ });
3560
+
3561
+ assert.calledOnceWithExactly(parserA.handleMessage, message);
3562
+ });
3563
+
3564
+ it('should send mismatch metric when eventType is not HASH_TREE_DATA_UPDATED', () => {
3565
+ const locusUrlA = 'http://locus-url-A.com';
3566
+ const parserA = {state: 'active', handleMessage: sinon.stub()};
3567
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3568
+
3569
+ locusInfo.parse(mockMeeting, {
3570
+ eventType: LOCUSEVENT.SELF_CHANGED,
3571
+ stateElementsMessage: {locusUrl: locusUrlA, locusStateElements: [], dataSets: []},
3572
+ });
3573
+
3574
+ assert.calledOnceWithExactly(
3575
+ sendBehavioralMetricStub,
3576
+ 'js_sdk_locus_classic_vs_hash_tree_mismatch',
3577
+ {
3578
+ correlationId: mockMeeting.correlationId,
3579
+ message: `got ${LOCUSEVENT.SELF_CHANGED}, expected ${LOCUSEVENT.HASH_TREE_DATA_UPDATED}`,
3580
+ }
3581
+ );
3582
+ assert.notCalled(parserA.handleMessage);
3583
+ });
3584
+ });
3585
+
3586
+ describe('#sendClassicVsHashTreeMismatchMetric', () => {
3587
+ it('should send the metric when called for the first time', () => {
3588
+ locusInfo.sendClassicVsHashTreeMismatchMetric(mockMeeting, 'some mismatch');
3589
+
3590
+ assert.calledOnceWithExactly(
3591
+ sendBehavioralMetricStub,
3592
+ 'js_sdk_locus_classic_vs_hash_tree_mismatch',
3593
+ {
3594
+ correlationId: mockMeeting.correlationId,
3595
+ message: 'some mismatch',
3596
+ }
3597
+ );
3598
+ });
3599
+
3600
+ it('should send the metric up to 5 times and stop after that', () => {
3601
+ for (let i = 0; i < 7; i += 1) {
3602
+ locusInfo.sendClassicVsHashTreeMismatchMetric(mockMeeting, `mismatch ${i}`);
3603
+ }
3604
+
3605
+ assert.callCount(sendBehavioralMetricStub, 5);
3606
+ assert.equal(locusInfo.classicVsHashTreeMismatchMetricCounter, 5);
3607
+ });
3608
+ });
3609
+
2571
3610
  describe('#handleLocusAPIResponse', () => {
2572
3611
  it('calls handleLocusDelta when we are not using hash trees', () => {
2573
3612
  const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE};
@@ -2578,8 +3617,8 @@ describe('plugin-meetings', () => {
2578
3617
 
2579
3618
  assert.calledWith(locusInfo.handleLocusDelta, fakeLocus, mockMeeting);
2580
3619
  });
2581
- it('does nothing when we are using hash trees', () => {
2582
- const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE};
3620
+ it('calls hash tree parser when we are using hash trees', () => {
3621
+ const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE, url: 'http://locus-url.com'};
2583
3622
  const fakeDataSets = [{name: 'dataset1', url: 'http://test.com'}];
2584
3623
  const responseBody = {locus: fakeLocus, dataSets: fakeDataSets};
2585
3624
 
@@ -2587,14 +3626,220 @@ describe('plugin-meetings', () => {
2587
3626
  const mockHashTreeParser = {
2588
3627
  handleLocusUpdate: sinon.stub(),
2589
3628
  };
2590
- locusInfo.hashTreeParser = mockHashTreeParser;
3629
+ locusInfo.hashTreeParsers.set(fakeLocus.url, {
3630
+ parser: mockHashTreeParser,
3631
+ initializedFromHashTree: true,
3632
+ });
2591
3633
 
2592
3634
  sinon.stub(locusInfo, 'onDeltaLocus');
2593
3635
 
2594
3636
  locusInfo.handleLocusAPIResponse(mockMeeting, responseBody);
2595
3637
 
2596
- assert.notCalled(mockHashTreeParser.handleLocusUpdate);
2597
- assert.notCalled(locusInfo.onDeltaLocus);
3638
+ assert.calledOnceWithExactly(mockHashTreeParser.handleLocusUpdate, responseBody);
3639
+ });
3640
+
3641
+ it('should handle unwrapped LocusDTO (without locus wrapper) when hash tree parser exists', () => {
3642
+ const fakeLocus = {url: 'http://locus-url.com', fullState: {state: 'ACTIVE'}};
3643
+ const mockHashTreeParser = {handleLocusUpdate: sinon.stub()};
3644
+ locusInfo.hashTreeParsers.set(fakeLocus.url, {
3645
+ parser: mockHashTreeParser,
3646
+ initializedFromHashTree: true,
3647
+ });
3648
+
3649
+ locusInfo.handleLocusAPIResponse(mockMeeting, fakeLocus);
3650
+
3651
+ assert.calledOnceWithExactly(mockHashTreeParser.handleLocusUpdate, {locus: fakeLocus});
3652
+ });
3653
+
3654
+ it('should handle unwrapped LocusDTO in classic mode (no hash tree parser)', () => {
3655
+ const fakeLocus = {url: 'http://locus-url.com', fullState: {state: 'ACTIVE'}};
3656
+ sinon.stub(locusInfo, 'handleLocusDelta');
3657
+
3658
+ locusInfo.handleLocusAPIResponse(mockMeeting, fakeLocus);
3659
+
3660
+ assert.calledOnceWithExactly(locusInfo.handleLocusDelta, fakeLocus, mockMeeting);
3661
+ });
3662
+
3663
+ it('should send mismatch metric in classic mode when wrapped response has dataSets', () => {
3664
+ const fakeLocus = {url: 'http://locus-url.com'};
3665
+ sinon.stub(locusInfo, 'handleLocusDelta');
3666
+
3667
+ locusInfo.handleLocusAPIResponse(mockMeeting, {
3668
+ locus: fakeLocus,
3669
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3670
+ });
3671
+
3672
+ assert.calledOnceWithExactly(
3673
+ sendBehavioralMetricStub,
3674
+ 'js_sdk_locus_classic_vs_hash_tree_mismatch',
3675
+ {
3676
+ correlationId: mockMeeting.correlationId,
3677
+ message: 'unexpected hash tree dataSets in API response',
3678
+ }
3679
+ );
3680
+ assert.calledOnce(locusInfo.handleLocusDelta);
3681
+ });
3682
+
3683
+ describe('parser switch via API response', () => {
3684
+ const deviceUrl = 'http://device-url.com';
3685
+ const locusUrlA = 'http://locus-url-A.com';
3686
+ const locusUrlB = 'http://locus-url-B.com';
3687
+
3688
+ let HashTreeParserStub;
3689
+
3690
+ const createMockApiParser = (state = 'active') => ({
3691
+ state,
3692
+ stop: sinon.stub(),
3693
+ resumeFromApiResponse: sinon.stub(),
3694
+ handleLocusUpdate: sinon.stub(),
3695
+ initializeFromGetLociResponse: sinon.stub(),
3696
+ });
3697
+
3698
+ const createLocusWithReplaces = (url, replacedLocusUrl, replacedAt) => ({
3699
+ url,
3700
+ self: {
3701
+ devices: [{url: deviceUrl, replaces: [{locusUrl: replacedLocusUrl, replacedAt}]}],
3702
+ },
3703
+ });
3704
+
3705
+ const createLocusWithoutReplaces = (url) => ({
3706
+ url,
3707
+ self: {devices: [{url: deviceUrl}]},
3708
+ });
3709
+
3710
+ beforeEach(() => {
3711
+ locusInfo.webex.internal.device.url = deviceUrl;
3712
+ HashTreeParserStub = sinon
3713
+ .stub(HashTreeParserModule, 'default')
3714
+ .returns(createMockApiParser());
3715
+ });
3716
+
3717
+ it('should create a new parser and initialize it when no entry exists for the locusUrl', () => {
3718
+ // existing parser for a different url so hashTreeParsers.size > 0
3719
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockApiParser(), initializedFromHashTree: true});
3720
+
3721
+ const locus = createLocusWithReplaces(locusUrlB, locusUrlA, '2026-01-01T00:00:00Z');
3722
+ sinon.stub(locusInfo, 'handleLocusDelta');
3723
+
3724
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3725
+
3726
+ assert.isTrue(locusInfo.hashTreeParsers.has(locusUrlB));
3727
+ const newEntry = locusInfo.hashTreeParsers.get(locusUrlB);
3728
+ assert.isFalse(newEntry.initializedFromHashTree);
3729
+
3730
+ // the stub returns the mock, so initializeFromGetLociResponse should be called on it
3731
+ const createdParser = HashTreeParserStub.returnValues[0];
3732
+ assert.calledOnceWithExactly(createdParser.initializeFromGetLociResponse, locus);
3733
+ assert.notCalled(locusInfo.handleLocusDelta);
3734
+ });
3735
+
3736
+ it('should reactivate a stopped parser when replaces info is newer', () => {
3737
+ const parserA = createMockApiParser('stopped');
3738
+ const parserB = createMockApiParser('active');
3739
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-01-01T00:00:00Z', initializedFromHashTree: true});
3740
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3741
+
3742
+ const locus = createLocusWithReplaces(locusUrlA, locusUrlB, '2026-02-01T00:00:00Z');
3743
+
3744
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3745
+
3746
+ assert.calledOnce(parserA.resumeFromApiResponse);
3747
+ assert.calledWithExactly(parserA.resumeFromApiResponse, locus);
3748
+ assert.calledOnce(parserB.stop);
3749
+ assert.equal(locusInfo.hashTreeParsers.get(locusUrlB).replacedAt, '2026-02-01T00:00:00Z');
3750
+ assert.isFalse(locusInfo.hashTreeParsers.get(locusUrlA).initializedFromHashTree);
3751
+ });
3752
+
3753
+ it('should not reactivate a stopped parser when replaces info is not newer', () => {
3754
+ const parserA = createMockApiParser('stopped');
3755
+ const parserB = createMockApiParser('active');
3756
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-03-01T00:00:00Z', initializedFromHashTree: true});
3757
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3758
+
3759
+ const locus = createLocusWithReplaces(locusUrlA, locusUrlB, '2026-01-01T00:00:00Z');
3760
+
3761
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3762
+
3763
+ assert.notCalled(parserA.resumeFromApiResponse);
3764
+ assert.notCalled(parserB.stop);
3765
+ });
3766
+
3767
+ it('should not reactivate a stopped parser when no replaces info is available', () => {
3768
+ const parserA = createMockApiParser('stopped');
3769
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3770
+
3771
+ const locus = createLocusWithoutReplaces(locusUrlA);
3772
+
3773
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3774
+
3775
+ assert.notCalled(parserA.resumeFromApiResponse);
3776
+ });
3777
+ });
3778
+ });
3779
+
3780
+ describe('#syncAllHashTreeDatasets', () => {
3781
+ it('should call syncAllDatasets on each parser that has an entry', async () => {
3782
+ const parser1 = {syncAllDatasets: sinon.stub().resolves()};
3783
+ const parser2 = {syncAllDatasets: sinon.stub().resolves()};
3784
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3785
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2});
3786
+
3787
+ await locusInfo.syncAllHashTreeDatasets();
3788
+
3789
+ assert.calledOnce(parser1.syncAllDatasets);
3790
+ assert.calledOnce(parser2.syncAllDatasets);
3791
+ });
3792
+
3793
+ it('should skip parser entries without a parser object', async () => {
3794
+ const parser1 = {syncAllDatasets: sinon.stub().resolves()};
3795
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3796
+ locusInfo.hashTreeParsers.set('url2', {parser: undefined});
3797
+
3798
+ await locusInfo.syncAllHashTreeDatasets();
3799
+
3800
+ assert.calledOnce(parser1.syncAllDatasets);
3801
+ });
3802
+
3803
+ it('should forward options to each parser syncAllDatasets', async () => {
3804
+ const parser1 = {syncAllDatasets: sinon.stub().resolves()};
3805
+ const parser2 = {syncAllDatasets: sinon.stub().resolves()};
3806
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3807
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2});
3808
+
3809
+ await locusInfo.syncAllHashTreeDatasets({onlyLLM: true});
3810
+
3811
+ assert.calledOnceWithExactly(parser1.syncAllDatasets, {onlyLLM: true});
3812
+ assert.calledOnceWithExactly(parser2.syncAllDatasets, {onlyLLM: true});
3813
+ });
3814
+
3815
+ it('should await each parsers syncAllDatasets sequentially', async () => {
3816
+ const callOrder = [];
3817
+ const parser1 = {syncAllDatasets: sinon.stub().callsFake(() => {
3818
+ callOrder.push('start1');
3819
+ return new Promise((resolve) => {
3820
+ setTimeout(() => {
3821
+ callOrder.push('end1');
3822
+ resolve();
3823
+ }, 100);
3824
+ });
3825
+ })};
3826
+ const parser2 = {syncAllDatasets: sinon.stub().callsFake(() => {
3827
+ callOrder.push('start2');
3828
+ return Promise.resolve();
3829
+ })};
3830
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3831
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2});
3832
+
3833
+ const clock = sinon.useFakeTimers();
3834
+ const promise = locusInfo.syncAllHashTreeDatasets();
3835
+ // parser1 started but parser2 not yet
3836
+ assert.deepEqual(callOrder, ['start1']);
3837
+
3838
+ await clock.tickAsync(100);
3839
+ await promise;
3840
+ // parser1 finished, then parser2 started and finished
3841
+ assert.deepEqual(callOrder, ['start1', 'end1', 'start2']);
3842
+ clock.restore();
2598
3843
  });
2599
3844
  });
2600
3845
 
@@ -2657,31 +3902,28 @@ describe('plugin-meetings', () => {
2657
3902
  assert.isFunction(locusParser.onDeltaAction);
2658
3903
  });
2659
3904
 
2660
- it("#updateLocusInfo invokes updateLocusUrl before updateMeetingInfo", () => {
3905
+ it('#updateLocusInfo invokes updateLocusUrl before updateMeetingInfo', () => {
2661
3906
  const callOrder = [];
2662
- sinon.stub(locusInfo, "updateControls");
2663
- sinon.stub(locusInfo, "updateConversationUrl");
2664
- sinon.stub(locusInfo, "updateCreated");
2665
- sinon.stub(locusInfo, "updateFullState");
2666
- sinon.stub(locusInfo, "updateHostInfo");
2667
- sinon.stub(locusInfo, "updateMeetingInfo").callsFake(() => {
2668
- callOrder.push("updateMeetingInfo");
2669
- });
2670
- sinon.stub(locusInfo, "updateMediaShares");
2671
- sinon.stub(locusInfo, "updateParticipantsUrl");
2672
- sinon.stub(locusInfo, "updateReplace");
2673
- sinon.stub(locusInfo, "updateSelf");
2674
- sinon.stub(locusInfo, "updateLocusUrl").callsFake(() => {
2675
- callOrder.push("updateLocusUrl");
2676
- });
2677
- sinon.stub(locusInfo, "updateAclUrl");
2678
- sinon.stub(locusInfo, "updateBasequence");
2679
- sinon.stub(locusInfo, "updateSequence");
2680
- sinon.stub(locusInfo, "updateMemberShip");
2681
- sinon.stub(locusInfo, "updateIdentifiers");
2682
- sinon.stub(locusInfo, "updateEmbeddedApps");
2683
- sinon.stub(locusInfo, "updateResources");
2684
- sinon.stub(locusInfo, "compareAndUpdate");
3907
+ sinon.stub(locusInfo, 'updateControls');
3908
+ sinon.stub(locusInfo, 'updateConversationUrl');
3909
+ sinon.stub(locusInfo, 'updateCreated');
3910
+ sinon.stub(locusInfo, 'updateFullState');
3911
+ sinon.stub(locusInfo, 'updateHostInfo');
3912
+ sinon.stub(locusInfo, 'updateMeetingInfo').callsFake(() => {
3913
+ callOrder.push('updateMeetingInfo');
3914
+ });
3915
+ sinon.stub(locusInfo, 'updateMediaShares');
3916
+ sinon.stub(locusInfo, 'updateReplaces');
3917
+ sinon.stub(locusInfo, 'updateSelf');
3918
+ sinon.stub(locusInfo, 'updateLocusUrl').callsFake(() => {
3919
+ callOrder.push('updateLocusUrl');
3920
+ });
3921
+ sinon.stub(locusInfo, 'updateAclUrl');
3922
+ sinon.stub(locusInfo, 'updateBasequence');
3923
+ sinon.stub(locusInfo, 'updateSequence');
3924
+ sinon.stub(locusInfo, 'updateEmbeddedApps');
3925
+ sinon.stub(locusInfo, 'updateLinks');
3926
+ sinon.stub(locusInfo, 'compareAndUpdate');
2685
3927
 
2686
3928
  locusInfo.updateLocusInfo(locus);
2687
3929
 
@@ -2689,59 +3931,58 @@ describe('plugin-meetings', () => {
2689
3931
  assert.deepEqual(callOrder, ['updateLocusUrl', 'updateMeetingInfo']);
2690
3932
  });
2691
3933
 
2692
- it('#updateLocusInfo ignores breakout LEFT message', () => {
3934
+ it('#updateLocusInfo ignores locus when isSelfMovedOrBreakoutEnded returns true', () => {
3935
+ const newLocus = {self: {state: 'JOINED'}};
3936
+
3937
+ sinon.stub(MeetingsUtil, 'isSelfMovedOrBreakoutEnded').returns(true);
3938
+
3939
+ locusInfo.updateControls = sinon.stub();
3940
+ locusInfo.updateFullState = sinon.stub();
3941
+ locusInfo.updateSelf = sinon.stub();
3942
+
3943
+ locusInfo.updateLocusInfo(newLocus);
3944
+
3945
+ assert.calledOnceWithExactly(MeetingsUtil.isSelfMovedOrBreakoutEnded, newLocus);
3946
+ assert.notCalled(locusInfo.updateControls);
3947
+ assert.notCalled(locusInfo.updateFullState);
3948
+ assert.notCalled(locusInfo.updateSelf);
3949
+
3950
+ MeetingsUtil.isSelfMovedOrBreakoutEnded.restore();
3951
+ });
3952
+
3953
+ it('#updateLocusInfo puts the Locus DTO top level properties at the right place in LocusInfo class', () => {
3954
+ // this test verifies that the top-level properties of Locus DTO are copied
3955
+ // into LocusInfo class and set as top level properties too
3956
+ // this is important, because the code handling Locus hash trees relies on it, see updateFromHashTree()
3957
+ const info = {id: 'info id'};
3958
+ const fullState = {id: 'fullState id'};
3959
+ const links = {services: {id: 'service links'}, resources: {id: 'resource links'}};
3960
+ const self = {id: 'self id'};
3961
+ const mediaShares = [{id: 'fake media share'}];
3962
+
3963
+ sinon.stub(SelfUtils, 'getSelves').returns({
3964
+ current: {},
3965
+ previous: {},
3966
+ updates: {},
3967
+ });
3968
+
2693
3969
  const newLocus = {
2694
- self: {
2695
- reason: 'MOVED',
2696
- state: 'LEFT',
2697
- },
3970
+ info,
3971
+ fullState,
3972
+ links,
3973
+ self,
3974
+ mediaShares,
2698
3975
  };
2699
3976
 
2700
- locusInfo.updateControls = sinon.stub();
2701
- locusInfo.updateConversationUrl = sinon.stub();
2702
- locusInfo.updateCreated = sinon.stub();
2703
- locusInfo.updateFullState = sinon.stub();
2704
- locusInfo.updateHostInfo = sinon.stub();
2705
- locusInfo.updateMeetingInfo = sinon.stub();
2706
- locusInfo.updateMediaShares = sinon.stub();
2707
- locusInfo.updateParticipantsUrl = sinon.stub();
2708
- locusInfo.updateReplace = sinon.stub();
2709
- locusInfo.updateSelf = sinon.stub();
2710
- locusInfo.updateLocusUrl = sinon.stub();
2711
- locusInfo.updateAclUrl = sinon.stub();
2712
- locusInfo.updateBasequence = sinon.stub();
2713
- locusInfo.updateSequence = sinon.stub();
2714
- locusInfo.updateMemberShip = sinon.stub();
2715
- locusInfo.updateIdentifiers = sinon.stub();
2716
- locusInfo.updateEmbeddedApps = sinon.stub();
2717
- locusInfo.updateResources = sinon.stub();
2718
- locusInfo.compareAndUpdate = sinon.stub();
2719
-
2720
3977
  locusInfo.updateLocusInfo(newLocus);
2721
3978
 
2722
- assert.notCalled(locusInfo.updateControls);
2723
- assert.notCalled(locusInfo.updateConversationUrl);
2724
- assert.notCalled(locusInfo.updateCreated);
2725
- assert.notCalled(locusInfo.updateFullState);
2726
- assert.notCalled(locusInfo.updateHostInfo);
2727
- assert.notCalled(locusInfo.updateMeetingInfo);
2728
- assert.notCalled(locusInfo.updateMediaShares);
2729
- assert.notCalled(locusInfo.updateParticipantsUrl);
2730
- assert.notCalled(locusInfo.updateReplace);
2731
- assert.notCalled(locusInfo.updateSelf);
2732
- assert.notCalled(locusInfo.updateLocusUrl);
2733
- assert.notCalled(locusInfo.updateAclUrl);
2734
- assert.notCalled(locusInfo.updateBasequence);
2735
- assert.notCalled(locusInfo.updateSequence);
2736
- assert.notCalled(locusInfo.updateMemberShip);
2737
- assert.notCalled(locusInfo.updateIdentifiers);
2738
- assert.notCalled(locusInfo.updateEmbeddedApps);
2739
- assert.notCalled(locusInfo.updateResources);
2740
- assert.notCalled(locusInfo.compareAndUpdate);
3979
+ assert.deepEqual(locusInfo.info, newLocus.info);
3980
+ assert.deepEqual(locusInfo.fullState, newLocus.fullState);
3981
+ assert.deepEqual(locusInfo.links, newLocus.links);
3982
+ assert.deepEqual(locusInfo.self, newLocus.self);
3983
+ assert.deepEqual(locusInfo.mediaShares, newLocus.mediaShares);
2741
3984
  });
2742
3985
 
2743
-
2744
-
2745
3986
  it('onFullLocus() updates the working-copy of locus parser', () => {
2746
3987
  const eventType = 'fakeEvent';
2747
3988
 
@@ -2751,7 +3992,7 @@ describe('plugin-meetings', () => {
2751
3992
  sandbox.stub(locusInfo, 'handleOneOnOneEvent');
2752
3993
  sandbox.stub(locusParser, 'isNewFullLocus').returns(true);
2753
3994
 
2754
- locusInfo.onFullLocus(fakeLocus, eventType);
3995
+ locusInfo.onFullLocus('test', fakeLocus, eventType);
2755
3996
 
2756
3997
  assert.equal(fakeLocus, locusParser.workingCopy);
2757
3998
  });
@@ -2772,7 +4013,7 @@ describe('plugin-meetings', () => {
2772
4013
 
2773
4014
  sandbox.stub(locusParser, 'isNewFullLocus').returns(false);
2774
4015
 
2775
- locusInfo.onFullLocus(fakeLocus, eventType);
4016
+ locusInfo.onFullLocus('test', fakeLocus, eventType);
2776
4017
 
2777
4018
  spies.forEach((spy) => {
2778
4019
  assert.notCalled(spy);
@@ -2922,7 +4163,11 @@ describe('plugin-meetings', () => {
2922
4163
  }).then(() => {
2923
4164
  assert.calledOnceWithExactly(meeting.meetingRequest.getLocusDTO, {url: 'oldLocusUrl'});
2924
4165
 
2925
- assert.calledOnceWithExactly(meeting.locusInfo.onFullLocus, fakeFullLocusDto);
4166
+ assert.calledOnceWithExactly(
4167
+ meeting.locusInfo.onFullLocus,
4168
+ 'classic Locus sync',
4169
+ fakeFullLocusDto
4170
+ );
2926
4171
  assert.calledOnce(locusInfo.locusParser.resume);
2927
4172
  });
2928
4173
  });
@@ -3020,7 +4265,11 @@ describe('plugin-meetings', () => {
3020
4265
  });
3021
4266
 
3022
4267
  assert.notCalled(meeting.locusInfo.handleLocusDelta);
3023
- assert.calledOnceWithExactly(meeting.locusInfo.onFullLocus, fakeFullLocusDto);
4268
+ assert.calledOnceWithExactly(
4269
+ meeting.locusInfo.onFullLocus,
4270
+ 'classic Locus sync',
4271
+ fakeFullLocusDto
4272
+ );
3024
4273
  assert.calledOnce(locusInfo.locusParser.resume);
3025
4274
  });
3026
4275
  });
@@ -3196,7 +4445,11 @@ describe('plugin-meetings', () => {
3196
4445
  url: 'fake locus DELTA url',
3197
4446
  });
3198
4447
  assert.notCalled(meeting.locusInfo.handleLocusDelta);
3199
- assert.calledOnceWithExactly(meeting.locusInfo.onFullLocus, fakeFullLocusDto);
4448
+ assert.calledOnceWithExactly(
4449
+ meeting.locusInfo.onFullLocus,
4450
+ 'classic Locus sync',
4451
+ fakeFullLocusDto
4452
+ );
3200
4453
  assert.calledOnce(locusInfo.locusParser.resume);
3201
4454
  });
3202
4455
  });
@@ -3217,6 +4470,137 @@ describe('plugin-meetings', () => {
3217
4470
 
3218
4471
  assert.isNull(locusInfo.mainSessionLocusCache);
3219
4472
  });
4473
+
4474
+ it('should map participant with htMeta.elementId.id of 0 (falsy number) to hashTreeObjectId2ParticipantId', () => {
4475
+ const locus = {
4476
+ url: 'url',
4477
+ participants: [
4478
+ {
4479
+ id: 'participant-zero',
4480
+ htMeta: {elementId: {id: 0}},
4481
+ },
4482
+ ],
4483
+ };
4484
+
4485
+ sinon.stub(locusInfo.locusParser, 'isNewFullLocus').returns(true);
4486
+ sinon.stub(locusInfo, 'updateLocusInfo');
4487
+ sinon.stub(locusInfo, 'updateParticipants');
4488
+ sinon.stub(locusInfo, 'isMeetingActive');
4489
+ sinon.stub(locusInfo, 'handleOneOnOneEvent');
4490
+ sinon.stub(locusInfo, 'updateEmbeddedApps');
4491
+ locusInfo.locusParser.workingCopy = null;
4492
+
4493
+ locusInfo.onFullLocus('test', locus);
4494
+
4495
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.get(0), 'participant-zero');
4496
+ });
4497
+ });
4498
+
4499
+ describe('#onDeltaLocus', () => {
4500
+ it('should use forceReplaceMembers from jsSdkMeta when it is defined', () => {
4501
+ sinon.stub(locusInfo, 'mergeParticipants');
4502
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(true);
4503
+ sinon.stub(locusInfo, 'updateParticipants');
4504
+ sinon.stub(locusInfo, 'isMeetingActive');
4505
+
4506
+ locusInfo.onDeltaLocus({
4507
+ participants: [],
4508
+ jsSdkMeta: {forceReplaceMembers: true, removedParticipantIds: []},
4509
+ });
4510
+
4511
+ assert.calledOnceWithExactly(locusInfo.updateParticipants, [], [], true);
4512
+ });
4513
+
4514
+ it('should fall back to isNeedReplaceMembers when forceReplaceMembers is not in jsSdkMeta', () => {
4515
+ sinon.stub(locusInfo, 'mergeParticipants');
4516
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(true);
4517
+ sinon.stub(locusInfo, 'updateParticipants');
4518
+ sinon.stub(locusInfo, 'isMeetingActive');
4519
+
4520
+ locusInfo.onDeltaLocus({participants: []});
4521
+
4522
+ // without jsSdkMeta.forceReplaceMembers, uses ControlsUtils.isNeedReplaceMembers result (false by default)
4523
+ assert.calledOnceWithExactly(locusInfo.updateParticipants, [], undefined, false);
4524
+ });
4525
+
4526
+ it('should not call updateParticipants when updateLocusInfo returns false', () => {
4527
+ sinon.stub(locusInfo, 'mergeParticipants');
4528
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(false);
4529
+ sinon.stub(locusInfo, 'updateParticipants');
4530
+ sinon.stub(locusInfo, 'isMeetingActive');
4531
+
4532
+ locusInfo.onDeltaLocus({participants: [], self: {state: 'LEFT', reason: 'MOVED'}});
4533
+
4534
+ assert.notCalled(locusInfo.updateParticipants);
4535
+ });
4536
+
4537
+ it('should call updateParticipants when updateLocusInfo returns true', () => {
4538
+ sinon.stub(locusInfo, 'mergeParticipants');
4539
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(true);
4540
+ sinon.stub(locusInfo, 'updateParticipants');
4541
+ sinon.stub(locusInfo, 'isMeetingActive');
4542
+
4543
+ locusInfo.onDeltaLocus({participants: [{id: 'p1'}]});
4544
+
4545
+ assert.calledOnce(locusInfo.updateParticipants);
4546
+ });
4547
+
4548
+ [
4549
+ {forceReplaceMembers: true, selfInParticipants: false, expectedSelfCopied: true},
4550
+ {forceReplaceMembers: true, selfInParticipants: true, expectedSelfCopied: false},
4551
+ {forceReplaceMembers: false, selfInParticipants: false, expectedSelfCopied: false},
4552
+ {forceReplaceMembers: false, selfInParticipants: true, expectedSelfCopied: false},
4553
+ ].forEach(({forceReplaceMembers, selfInParticipants, expectedSelfCopied}) => {
4554
+ it(`should ${expectedSelfCopied ? '' : 'not '}copy self into participants when forceReplaceMembers=${forceReplaceMembers} and self ${selfInParticipants ? 'is' : 'is not'} in participants`, () => {
4555
+ const self = {identity: 'selfId', state: 'JOINED', devices: [], status: {}};
4556
+ const participant = {identity: selfInParticipants ? 'selfId' : 'other'};
4557
+ const locus = {
4558
+ participants: [participant],
4559
+ self,
4560
+ jsSdkMeta: {forceReplaceMembers, removedParticipantIds: []},
4561
+ };
4562
+
4563
+ locusInfo.onDeltaLocus(locus);
4564
+
4565
+ const expectedParticipants = expectedSelfCopied ? [participant, self] : [participant];
4566
+ assert.deepEqual(locus.participants, expectedParticipants);
4567
+ });
4568
+ });
4569
+ });
4570
+
4571
+ describe('#updateLocusInfo', () => {
4572
+ it('should return false when self.reason is MOVED and self.state is LEFT', () => {
4573
+ sinon.stub(locusInfo, 'updateControls');
4574
+
4575
+ const result = locusInfo.updateLocusInfo({self: {reason: 'MOVED', state: 'LEFT'}});
4576
+
4577
+ assert.isFalse(result);
4578
+ assert.notCalled(locusInfo.updateControls);
4579
+ });
4580
+
4581
+ it('should return true when self is not in MOVED/LEFT state', () => {
4582
+ sinon.stub(locusInfo, 'updateControls');
4583
+ sinon.stub(locusInfo, 'updateConversationUrl');
4584
+ sinon.stub(locusInfo, 'updateCreated');
4585
+ sinon.stub(locusInfo, 'updateFullState');
4586
+ sinon.stub(locusInfo, 'updateHostInfo');
4587
+ sinon.stub(locusInfo, 'updateLocusUrl');
4588
+ sinon.stub(locusInfo, 'updateMeetingInfo');
4589
+ sinon.stub(locusInfo, 'updateMediaShares');
4590
+ sinon.stub(locusInfo, 'updateReplaces');
4591
+ sinon.stub(locusInfo, 'updateSelf');
4592
+ sinon.stub(locusInfo, 'updateAclUrl');
4593
+ sinon.stub(locusInfo, 'updateBasequence');
4594
+ sinon.stub(locusInfo, 'updateSequence');
4595
+ sinon.stub(locusInfo, 'updateEmbeddedApps');
4596
+ sinon.stub(locusInfo, 'updateLinks');
4597
+ sinon.stub(locusInfo, 'compareAndUpdate');
4598
+
4599
+ const result = locusInfo.updateLocusInfo({self: {state: 'JOINED'}});
4600
+
4601
+ assert.isTrue(result);
4602
+ assert.calledOnce(locusInfo.updateControls);
4603
+ });
3220
4604
  });
3221
4605
 
3222
4606
  describe('#getTheLocusToUpdate', () => {
@@ -3413,6 +4797,31 @@ describe('plugin-meetings', () => {
3413
4797
  });
3414
4798
  });
3415
4799
 
4800
+ describe('#cleanUp', () => {
4801
+ it('calls cleanUp on all hash tree parsers and clears maps', () => {
4802
+ const parser1 = {cleanUp: sinon.stub()};
4803
+ const parser2 = {cleanUp: sinon.stub()};
4804
+
4805
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1, initializedFromHashTree: true});
4806
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2, initializedFromHashTree: true});
4807
+ locusInfo.hashTreeObjectId2ParticipantId.set(1, 'participant1');
4808
+
4809
+ locusInfo.cleanUp();
4810
+
4811
+ assert.calledOnce(parser1.cleanUp);
4812
+ assert.calledOnce(parser2.cleanUp);
4813
+ assert.equal(locusInfo.hashTreeParsers.size, 0);
4814
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.size, 0);
4815
+ });
4816
+
4817
+ it('works when there are no hash tree parsers', () => {
4818
+ locusInfo.cleanUp();
4819
+
4820
+ assert.equal(locusInfo.hashTreeParsers.size, 0);
4821
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.size, 0);
4822
+ });
4823
+ });
4824
+
3416
4825
  describe('#handleOneonOneEvent', () => {
3417
4826
  beforeEach(() => {
3418
4827
  locusInfo.emitScoped = sinon.stub();
@@ -3455,6 +4864,9 @@ describe('plugin-meetings', () => {
3455
4864
  });
3456
4865
 
3457
4866
  describe('#isMeetingActive', () => {
4867
+ beforeEach(() => {
4868
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
4869
+ });
3458
4870
  forEach([_CALL_, _SIP_BRIDGE_, _SPACE_SHARE_], (type) => {
3459
4871
  describe(`type = ${type}`, () => {
3460
4872
  it('sends client event correctly for state = inactive', () => {
@@ -3521,7 +4933,7 @@ describe('plugin-meetings', () => {
3521
4933
  });
3522
4934
  });
3523
4935
 
3524
- it('sends client event correctly for state = MEETING_INACTIVE_TERMINATING', () => {
4936
+ it('sends client event correctly for state = MEETING_INACTIVE', () => {
3525
4937
  locusInfo.getLocusPartner = sinon.stub().returns({state: MEETING_STATE.STATES.LEFT});
3526
4938
  locusInfo.parsedLocus = {
3527
4939
  fullState: {
@@ -3543,7 +4955,7 @@ describe('plugin-meetings', () => {
3543
4955
  });
3544
4956
  });
3545
4957
 
3546
- it('sends client event correctly for state = FULLSTATE_REMOVED', () => {
4958
+ it('does not send client event when state = INACTIVE and endMeetingReason = BREAKOUT_ENDED', () => {
3547
4959
  locusInfo.getLocusPartner = sinon.stub().returns({state: MEETING_STATE.STATES.LEFT});
3548
4960
  locusInfo.parsedLocus = {
3549
4961
  fullState: {
@@ -3552,23 +4964,47 @@ describe('plugin-meetings', () => {
3552
4964
  };
3553
4965
 
3554
4966
  locusInfo.fullState = {
3555
- removed: true,
4967
+ state: LOCUS.STATE.INACTIVE,
4968
+ endMeetingReason: 'BREAKOUT_ENDED',
3556
4969
  };
3557
4970
 
3558
4971
  locusInfo.isMeetingActive();
3559
4972
 
3560
- assert.calledWith(webex.internal.newMetrics.submitClientEvent, {
3561
- name: 'client.call.remote-ended',
3562
- options: {
3563
- meetingId: locusInfo.meetingId,
4973
+ assert.notCalled(webex.internal.newMetrics.submitClientEvent);
4974
+ });
4975
+
4976
+ it('sends client event correctly for state self removed', () => {
4977
+ locusInfo.emitScoped = sinon.stub();
4978
+ locusInfo.parsedLocus = {
4979
+ fullState: {
4980
+ type: _MEETING_,
3564
4981
  },
3565
- });
4982
+ self: {
4983
+ removed: true,
4984
+ }
4985
+ };
4986
+
4987
+ locusInfo.isMeetingActive();
4988
+
4989
+ assert.notCalled(webex.internal.newMetrics.submitClientEvent);
4990
+ assert.calledOnceWithExactly(
4991
+ locusInfo.emitScoped,
4992
+ {
4993
+ file: 'locus-info',
4994
+ function: 'isMeetingActive',
4995
+ },
4996
+ EVENTS.DESTROY_MEETING,
4997
+ {
4998
+ reason: MEETING_REMOVED_REASON.SELF_REMOVED,
4999
+ shouldLeave: false,
5000
+ }
5001
+ );
3566
5002
  });
3567
5003
  });
3568
5004
 
3569
5005
  describe('#updateLocusUrl', () => {
3570
5006
  it('trigger LOCUS_INFO_UPDATE_URL event with isMainLocus is true as default', () => {
3571
- const fakeUrl = "https://fake.com/locus";
5007
+ const fakeUrl = 'https://fake.com/locus';
3572
5008
  locusInfo.emitScoped = sinon.stub();
3573
5009
  locusInfo.updateLocusUrl(fakeUrl);
3574
5010
 
@@ -3581,12 +5017,12 @@ describe('plugin-meetings', () => {
3581
5017
  EVENTS.LOCUS_INFO_UPDATE_URL,
3582
5018
  {
3583
5019
  url: fakeUrl,
3584
- isMainLocus: true
3585
- },
5020
+ isMainLocus: true,
5021
+ }
3586
5022
  );
3587
5023
  });
3588
5024
  it('trigger LOCUS_INFO_UPDATE_URL event with isMainLocus is false', () => {
3589
- const fakeUrl = "https://fake.com/locus";
5025
+ const fakeUrl = 'https://fake.com/locus';
3590
5026
  locusInfo.emitScoped = sinon.stub();
3591
5027
  locusInfo.updateLocusUrl(fakeUrl, false);
3592
5028
 
@@ -3599,8 +5035,8 @@ describe('plugin-meetings', () => {
3599
5035
  EVENTS.LOCUS_INFO_UPDATE_URL,
3600
5036
  {
3601
5037
  url: fakeUrl,
3602
- isMainLocus: false
3603
- },
5038
+ isMainLocus: false,
5039
+ }
3604
5040
  );
3605
5041
  });
3606
5042
  });
@@ -3652,8 +5088,8 @@ describe('plugin-meetings', () => {
3652
5088
 
3653
5089
  sinon.stub(locusInfo, 'updateParticipants');
3654
5090
  sinon.stub(locusInfo, 'isMeetingActive');
3655
- sinon.stub(locusInfo, 'handleOneOnOneEvent');
3656
- (updateLocusInfoStub = sinon.stub(locusInfo, 'updateLocusInfo'));
5091
+ sinon.stub(locusInfo, 'handleOneOnOneEvent');
5092
+ updateLocusInfoStub = sinon.stub(locusInfo, 'updateLocusInfo');
3657
5093
  syncRequestStub = sinon.stub().resolves({body: {}});
3658
5094
 
3659
5095
  mockMeeting.locusInfo = locusInfo;
@@ -3662,7 +5098,7 @@ describe('plugin-meetings', () => {
3662
5098
  getLocusDTO: syncRequestStub,
3663
5099
  };
3664
5100
 
3665
- locusInfo.onFullLocus({
5101
+ locusInfo.onFullLocus('test', {
3666
5102
  sequence: {
3667
5103
  rangeStart: 0,
3668
5104
  rangeEnd: 0,
@@ -3900,7 +5336,9 @@ describe('plugin-meetings', () => {
3900
5336
 
3901
5337
  describe('#parse', () => {
3902
5338
  it('handles hash tree messages correctly', () => {
5339
+ const fakeLocusUrl = 'http://locus-url.com';
3903
5340
  const fakeHashTreeMessage = {
5341
+ locusUrl: fakeLocusUrl,
3904
5342
  locusStateElements: [
3905
5343
  {
3906
5344
  htMeta: {elementId: {type: 'self'}},
@@ -3919,12 +5357,403 @@ describe('plugin-meetings', () => {
3919
5357
  const mockHashTreeParser = {
3920
5358
  handleMessage: sinon.stub(),
3921
5359
  };
3922
- locusInfo.hashTreeParser = mockHashTreeParser;
5360
+ locusInfo.hashTreeParsers.set(fakeLocusUrl, {
5361
+ parser: mockHashTreeParser,
5362
+ initializedFromHashTree: true,
5363
+ });
3923
5364
 
3924
5365
  locusInfo.parse(mockMeeting, data);
3925
5366
 
3926
5367
  assert.calledOnceWithExactly(mockHashTreeParser.handleMessage, fakeHashTreeMessage);
3927
5368
  });
5369
+
5370
+ it('ignores hash tree event when hashTreeParser is not created yet', () => {
5371
+ const data = {
5372
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
5373
+ stateElementsMessage: {
5374
+ locusStateElements: [],
5375
+ dataSets: [],
5376
+ },
5377
+ };
5378
+
5379
+ const loggerSpy = sinon.spy(LoggerProxy.logger, 'info');
5380
+ const getTheLocusToUpdateStub = sinon.stub(locusInfo, 'getTheLocusToUpdate');
5381
+
5382
+ // Ensure we're not using hash trees
5383
+ assert.equal(locusInfo.hashTreeParsers.size, 0);
5384
+
5385
+ locusInfo.parse(mockMeeting, data);
5386
+
5387
+ assert.calledWith(
5388
+ loggerSpy,
5389
+ 'Locus-info:index#parse --> received locus hash tree event before hashTreeParser is created'
5390
+ );
5391
+ assert.notCalled(getTheLocusToUpdateStub);
5392
+ });
5393
+
5394
+ it('should call handleLocusAPIResponse for SDK_LOCUS_FROM_SYNC_MEETINGS when hash tree parsers exist', () => {
5395
+ const fakeLocusUrl = 'http://locus-url.com';
5396
+ const fakeLocus = {url: fakeLocusUrl, fullState: {state: 'ACTIVE'}};
5397
+ const mockHashTreeParser = {
5398
+ handleMessage: sinon.stub(),
5399
+ handleLocusUpdate: sinon.stub(),
5400
+ };
5401
+ locusInfo.hashTreeParsers.set(fakeLocusUrl, {
5402
+ parser: mockHashTreeParser,
5403
+ initializedFromHashTree: true,
5404
+ });
5405
+
5406
+ sinon.stub(locusInfo, 'handleLocusDelta');
5407
+
5408
+ locusInfo.parse(mockMeeting, {
5409
+ eventType: LOCUSEVENT.SDK_LOCUS_FROM_SYNC_MEETINGS,
5410
+ locus: fakeLocus,
5411
+ });
5412
+
5413
+ // should route through handleLocusAPIResponse which passes unwrapped LocusDTO to parser
5414
+ assert.calledOnce(mockHashTreeParser.handleLocusUpdate);
5415
+ assert.notCalled(mockHashTreeParser.handleMessage);
5416
+ assert.notCalled(locusInfo.handleLocusDelta);
5417
+ });
5418
+ });
5419
+ });
5420
+
5421
+ describe('#createLocusFromHashTreeMessage', () => {
5422
+ const LOCUS_URL = 'https://locus.example.com/loci/abc-123';
5423
+
5424
+ const createElement = (type, data) => ({
5425
+ htMeta: {elementId: {type, id: 1, version: 1}},
5426
+ data,
5427
+ });
5428
+
5429
+ it('returns locus with url and empty participants when no locusStateElements', () => {
5430
+ const result = createLocusFromHashTreeMessage({locusUrl: LOCUS_URL});
5431
+
5432
+ assert.deepEqual(result.locus, {participants: [], url: LOCUS_URL});
5433
+ assert.isUndefined(result.metadata);
5434
+ });
5435
+
5436
+ it('skips elements without data', () => {
5437
+ const result = createLocusFromHashTreeMessage({
5438
+ locusUrl: LOCUS_URL,
5439
+ locusStateElements: [{htMeta: {elementId: {type: 'Self', id: 1, version: 1}}, data: null}],
5440
+ });
5441
+
5442
+ assert.deepEqual(result.locus, {participants: [], url: LOCUS_URL});
5443
+ });
5444
+
5445
+ [
5446
+ {type: 'Self', locusKey: 'self', data: {id: 'self-1', state: 'JOINED'}},
5447
+ {type: 'Info', locusKey: 'info', data: {webExMeetingId: '123'}},
5448
+ {type: 'FullState', locusKey: 'fullState', data: {state: 'ACTIVE'}},
5449
+ {type: 'Links', locusKey: 'links', data: {resources: {}}},
5450
+ ].forEach(({type, locusKey, data}) => {
5451
+ it(`maps ${type} element to locus.${locusKey}`, () => {
5452
+ const result = createLocusFromHashTreeMessage({
5453
+ locusUrl: LOCUS_URL,
5454
+ locusStateElements: [createElement(type, data)],
5455
+ });
5456
+
5457
+ assert.deepEqual(result.locus[locusKey], data);
5458
+ });
5459
+ });
5460
+
5461
+ it('pushes Participant elements to locus.participants', () => {
5462
+ const p1 = {id: 'p1', state: 'JOINED'};
5463
+ const p2 = {id: 'p2', state: 'LEFT'};
5464
+
5465
+ const result = createLocusFromHashTreeMessage({
5466
+ locusUrl: LOCUS_URL,
5467
+ locusStateElements: [createElement('Participant', p1), createElement('Participant', p2)],
5468
+ });
5469
+
5470
+ assert.deepEqual(result.locus.participants, [p1, p2]);
5471
+ });
5472
+
5473
+ it('pushes MediaShare elements to locus.mediaShares array', () => {
5474
+ const share1 = {name: 'whiteboard'};
5475
+ const share2 = {name: 'content'};
5476
+
5477
+ const result = createLocusFromHashTreeMessage({
5478
+ locusUrl: LOCUS_URL,
5479
+ locusStateElements: [
5480
+ createElement('MediaShare', share1),
5481
+ createElement('MediaShare', share2),
5482
+ ],
5483
+ });
5484
+
5485
+ assert.deepEqual(result.locus.mediaShares, [share1, share2]);
5486
+ });
5487
+
5488
+ it('pushes EmbeddedApp elements to locus.embeddedApps array', () => {
5489
+ const app = {appId: 'app-1', state: 'STARTED'};
5490
+
5491
+ const result = createLocusFromHashTreeMessage({
5492
+ locusUrl: LOCUS_URL,
5493
+ locusStateElements: [createElement('EmbeddedApp', app)],
5494
+ });
5495
+
5496
+ assert.deepEqual(result.locus.embeddedApps, [app]);
5497
+ });
5498
+
5499
+ it('merges ControlEntry elements into locus.controls', () => {
5500
+ const control1 = {record: {recording: true}};
5501
+ const control2 = {lock: {locked: false}};
5502
+
5503
+ const result = createLocusFromHashTreeMessage({
5504
+ locusUrl: LOCUS_URL,
5505
+ locusStateElements: [
5506
+ createElement('ControlEntry', control1),
5507
+ createElement('ControlEntry', control2),
5508
+ ],
5509
+ });
5510
+
5511
+ assert.deepEqual(result.locus.controls, {record: {recording: true}, lock: {locked: false}});
5512
+ });
5513
+
5514
+ it('spreads Locus element data onto top level but removes managed keys', () => {
5515
+ const locusData = {
5516
+ url: 'should-be-overridden',
5517
+ someTopLevelField: 'value',
5518
+ // these are managed by other ObjectTypes and should be removed
5519
+ links: {should: 'be removed'},
5520
+ info: {should: 'be removed'},
5521
+ fullState: {should: 'be removed'},
5522
+ self: {should: 'be removed'},
5523
+ participants: [{should: 'be removed'}],
5524
+ mediaShares: [{should: 'be removed'}],
5525
+ controls: {should: 'be removed'},
5526
+ embeddedApps: [{should: 'be removed'}],
5527
+ };
5528
+
5529
+ const result = createLocusFromHashTreeMessage({
5530
+ locusUrl: LOCUS_URL,
5531
+ locusStateElements: [createElement('Locus', locusData)],
5532
+ });
5533
+
5534
+ assert.equal(result.locus.someTopLevelField, 'value');
5535
+ assert.deepEqual(result.locus.participants, []);
5536
+ assert.isUndefined(result.locus.links);
5537
+ assert.isUndefined(result.locus.info);
5538
+ assert.isUndefined(result.locus.fullState);
5539
+ assert.isUndefined(result.locus.self);
5540
+ assert.isUndefined(result.locus.mediaShares);
5541
+ assert.isUndefined(result.locus.controls);
5542
+ assert.isUndefined(result.locus.embeddedApps);
5543
+ });
5544
+
5545
+ it('extracts Metadata element as metadata in the result', () => {
5546
+ const metadataData = {visibleDataSets: [{name: 'ds1', url: 'http://ds1.url'}]};
5547
+ const htMeta = {elementId: {type: 'Metadata', id: 99, version: 3}};
5548
+
5549
+ const result = createLocusFromHashTreeMessage({
5550
+ locusUrl: LOCUS_URL,
5551
+ locusStateElements: [{htMeta, data: metadataData}],
5552
+ });
5553
+
5554
+ assert.deepEqual(result.metadata, {...metadataData, htMeta});
5555
+ assert.isUndefined(result.locus.metadata);
5556
+ });
5557
+
5558
+ it('handles a message with multiple element types', () => {
5559
+ const selfData = {id: 'self-1'};
5560
+ const participantData = {id: 'p1'};
5561
+ const infoData = {webExMeetingId: '456'};
5562
+
5563
+ const result = createLocusFromHashTreeMessage({
5564
+ locusUrl: LOCUS_URL,
5565
+ locusStateElements: [
5566
+ createElement('Self', selfData),
5567
+ createElement('Participant', participantData),
5568
+ createElement('Info', infoData),
5569
+ ],
5570
+ });
5571
+
5572
+ assert.deepEqual(result.locus.self, selfData);
5573
+ assert.deepEqual(result.locus.participants, [participantData]);
5574
+ assert.deepEqual(result.locus.info, infoData);
5575
+ assert.equal(result.locus.url, LOCUS_URL);
5576
+ });
5577
+
5578
+ it('ignores unknown element types', () => {
5579
+ const result = createLocusFromHashTreeMessage({
5580
+ locusUrl: LOCUS_URL,
5581
+ locusStateElements: [createElement('UnknownType', {foo: 'bar'})],
5582
+ });
5583
+
5584
+ assert.deepEqual(result.locus, {participants: [], url: LOCUS_URL});
5585
+ });
5586
+ });
5587
+
5588
+ describe('findMeetingForHashTreeMessage', () => {
5589
+ const deviceUrl = 'https://devices.example.com/device1';
5590
+
5591
+ function createMockMeetingCollection(meetings) {
5592
+ return {
5593
+ getAll: () => meetings,
5594
+ };
5595
+ }
5596
+
5597
+ function createMockMeeting(id, hashTreeParsersMap) {
5598
+ return {
5599
+ id,
5600
+ locusInfo: {
5601
+ hashTreeParsers: hashTreeParsersMap,
5602
+ },
5603
+ };
5604
+ }
5605
+
5606
+ function createSelfElement(devices) {
5607
+ return {
5608
+ htMeta: {elementId: {type: 'Self'}},
5609
+ data: {
5610
+ deviceUrl,
5611
+ devices,
5612
+ },
5613
+ };
5614
+ }
5615
+
5616
+ it('returns the meeting when locusUrl matches a hashTreeParser directly', () => {
5617
+ const locusUrl = 'https://locus.example.com/loci/abc123';
5618
+ const parsersMap = new Map([[locusUrl, {state: 'active'}]]);
5619
+ const meeting = createMockMeeting('meeting1', parsersMap);
5620
+ const collection = createMockMeetingCollection({meeting1: meeting});
5621
+
5622
+ const message = {locusUrl, locusStateElements: []};
5623
+
5624
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5625
+
5626
+ assert.equal(result, meeting);
5627
+ });
5628
+
5629
+ it('returns undefined when no meeting matches and message has no locusStateElements', () => {
5630
+ const locusUrl = 'https://locus.example.com/loci/unknown';
5631
+ const parsersMap = new Map([['https://locus.example.com/loci/other', {state: 'active'}]]);
5632
+ const meeting = createMockMeeting('meeting1', parsersMap);
5633
+ const collection = createMockMeetingCollection({meeting1: meeting});
5634
+
5635
+ const message = {locusUrl};
5636
+
5637
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5638
+
5639
+ assert.isUndefined(result);
5640
+ });
5641
+
5642
+ it('returns undefined when no meeting matches and self element has no replaces', () => {
5643
+ const locusUrl = 'https://locus.example.com/loci/unknown';
5644
+ const parsersMap = new Map([['https://locus.example.com/loci/other', {state: 'active'}]]);
5645
+ const meeting = createMockMeeting('meeting1', parsersMap);
5646
+ const collection = createMockMeetingCollection({meeting1: meeting});
5647
+
5648
+ const selfElement = createSelfElement([{url: deviceUrl}]);
5649
+ const message = {locusUrl, locusStateElements: [selfElement]};
5650
+
5651
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5652
+
5653
+ assert.isUndefined(result);
5654
+ });
5655
+
5656
+ it('returns the meeting when locusUrl from replaces matches a hashTreeParser', () => {
5657
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5658
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5659
+ const parsersMap = new Map([[oldLocusUrl, {state: 'active'}]]);
5660
+ const meeting = createMockMeeting('meeting1', parsersMap);
5661
+ const collection = createMockMeetingCollection({meeting1: meeting});
5662
+
5663
+ const selfElement = createSelfElement([
5664
+ {url: deviceUrl, replaces: [{locusUrl: oldLocusUrl}]},
5665
+ ]);
5666
+ const message = {locusUrl: newLocusUrl, locusStateElements: [selfElement]};
5667
+
5668
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5669
+
5670
+ assert.equal(result, meeting);
5671
+ });
5672
+
5673
+ it('returns undefined when replaces locusUrl does not match any hashTreeParser', () => {
5674
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5675
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5676
+ const parsersMap = new Map([
5677
+ ['https://locus.example.com/loci/something-else', {state: 'active'}],
5678
+ ]);
5679
+ const meeting = createMockMeeting('meeting1', parsersMap);
5680
+ const collection = createMockMeetingCollection({meeting1: meeting});
5681
+
5682
+ const selfElement = createSelfElement([
5683
+ {url: deviceUrl, replaces: [{locusUrl: oldLocusUrl}]},
5684
+ ]);
5685
+ const message = {locusUrl: newLocusUrl, locusStateElements: [selfElement]};
5686
+
5687
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5688
+
5689
+ assert.isUndefined(result);
5690
+ });
5691
+
5692
+ it('returns undefined when meetingCollection is empty', () => {
5693
+ const collection = createMockMeetingCollection({});
5694
+ const message = {locusUrl: 'https://locus.example.com/loci/abc', locusStateElements: []};
5695
+
5696
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5697
+
5698
+ assert.isUndefined(result);
5699
+ });
5700
+
5701
+ it('checks multiple meetings and returns the correct one', () => {
5702
+ const targetLocusUrl = 'https://locus.example.com/loci/target';
5703
+ const meeting1 = createMockMeeting(
5704
+ 'meeting1',
5705
+ new Map([['https://locus.example.com/loci/other', {state: 'active'}]])
5706
+ );
5707
+ const meeting2 = createMockMeeting(
5708
+ 'meeting2',
5709
+ new Map([[targetLocusUrl, {state: 'active'}]])
5710
+ );
5711
+ const collection = createMockMeetingCollection({meeting1, meeting2});
5712
+
5713
+ const message = {locusUrl: targetLocusUrl, locusStateElements: []};
5714
+
5715
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5716
+
5717
+ assert.equal(result, meeting2);
5718
+ });
5719
+
5720
+ it('ignores devices that do not match deviceUrl when looking for replaces', () => {
5721
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5722
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5723
+ const parsersMap = new Map([[oldLocusUrl, {state: 'active'}]]);
5724
+ const meeting = createMockMeeting('meeting1', parsersMap);
5725
+ const collection = createMockMeetingCollection({meeting1: meeting});
5726
+
5727
+ // self element has replaces, but on a different device
5728
+ const selfElement = createSelfElement([
5729
+ {url: 'https://devices.example.com/other-device', replaces: [{locusUrl: oldLocusUrl}]},
5730
+ ]);
5731
+ const message = {locusUrl: newLocusUrl, locusStateElements: [selfElement]};
5732
+
5733
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5734
+
5735
+ assert.isUndefined(result);
5736
+ });
5737
+
5738
+ it('does not use self element if it is not of type Self', () => {
5739
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5740
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5741
+ const parsersMap = new Map([[oldLocusUrl, {state: 'active'}]]);
5742
+ const meeting = createMockMeeting('meeting1', parsersMap);
5743
+ const collection = createMockMeetingCollection({meeting1: meeting});
5744
+
5745
+ // element has replaces data but is not of type Self
5746
+ const nonSelfElement = {
5747
+ htMeta: {elementId: {type: 'Participant'}},
5748
+ data: {
5749
+ devices: [{url: deviceUrl, replaces: [{locusUrl: oldLocusUrl}]}],
5750
+ },
5751
+ };
5752
+ const message = {locusUrl: newLocusUrl, locusStateElements: [nonSelfElement]};
5753
+
5754
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5755
+
5756
+ assert.isUndefined(result);
3928
5757
  });
3929
5758
  });
3930
5759
  });