@webex/plugin-meetings 3.11.0 → 3.12.0-metrics-init-fix-3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) 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/events.js +29 -14
  11. package/dist/breakouts/events.js.map +1 -1
  12. package/dist/breakouts/index.js +90 -3
  13. package/dist/breakouts/index.js.map +1 -1
  14. package/dist/common/errors/webex-errors.js +49 -5
  15. package/dist/common/errors/webex-errors.js.map +1 -1
  16. package/dist/config.js +8 -3
  17. package/dist/config.js.map +1 -1
  18. package/dist/constants.js +60 -11
  19. package/dist/constants.js.map +1 -1
  20. package/dist/controls-options-manager/constants.js +11 -1
  21. package/dist/controls-options-manager/constants.js.map +1 -1
  22. package/dist/controls-options-manager/index.js +67 -29
  23. package/dist/controls-options-manager/index.js.map +1 -1
  24. package/dist/controls-options-manager/util.js +91 -0
  25. package/dist/controls-options-manager/util.js.map +1 -1
  26. package/dist/hashTree/constants.js +16 -2
  27. package/dist/hashTree/constants.js.map +1 -1
  28. package/dist/hashTree/hashTree.js +18 -0
  29. package/dist/hashTree/hashTree.js.map +1 -1
  30. package/dist/hashTree/hashTreeParser.js +1655 -538
  31. package/dist/hashTree/hashTreeParser.js.map +1 -1
  32. package/dist/hashTree/types.js +4 -2
  33. package/dist/hashTree/types.js.map +1 -1
  34. package/dist/hashTree/utils.js +52 -0
  35. package/dist/hashTree/utils.js.map +1 -1
  36. package/dist/index.js +18 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/interceptors/constant.js +12 -0
  39. package/dist/interceptors/constant.js.map +1 -0
  40. package/dist/interceptors/dataChannelAuthToken.js +350 -0
  41. package/dist/interceptors/dataChannelAuthToken.js.map +1 -0
  42. package/dist/interceptors/index.js +7 -0
  43. package/dist/interceptors/index.js.map +1 -1
  44. package/dist/interceptors/locusRetry.js +23 -8
  45. package/dist/interceptors/locusRetry.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 +9 -4
  54. package/dist/locus-info/controlsUtils.js.map +1 -1
  55. package/dist/locus-info/index.js +911 -211
  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 +8 -7
  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 +2276 -1067
  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 -162
  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 +116 -18
  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 +12 -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.map +1 -1
  114. package/dist/reachability/index.js +139 -93
  115. package/dist/reachability/index.js.map +1 -1
  116. package/dist/reachability/reachability.types.js +2 -0
  117. package/dist/reachability/reachability.types.js.map +1 -1
  118. package/dist/reachability/util.js +45 -0
  119. package/dist/reachability/util.js.map +1 -1
  120. package/dist/reactions/reactions.type.js.map +1 -1
  121. package/dist/reconnection-manager/index.js +0 -1
  122. package/dist/reconnection-manager/index.js.map +1 -1
  123. package/dist/recording-controller/index.js +1 -3
  124. package/dist/recording-controller/index.js.map +1 -1
  125. package/dist/roap/turnDiscovery.js +8 -1
  126. package/dist/roap/turnDiscovery.js.map +1 -1
  127. package/dist/types/aiEnableRequest/index.d.ts +5 -0
  128. package/dist/types/aiEnableRequest/utils.d.ts +2 -0
  129. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  130. package/dist/types/config.d.ts +6 -2
  131. package/dist/types/constants.d.ts +35 -1
  132. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  133. package/dist/types/controls-options-manager/index.d.ts +16 -0
  134. package/dist/types/hashTree/constants.d.ts +3 -0
  135. package/dist/types/hashTree/hashTree.d.ts +7 -0
  136. package/dist/types/hashTree/hashTreeParser.d.ts +315 -30
  137. package/dist/types/hashTree/types.d.ts +3 -0
  138. package/dist/types/hashTree/utils.d.ts +24 -0
  139. package/dist/types/index.d.ts +4 -0
  140. package/dist/types/interceptors/constant.d.ts +5 -0
  141. package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
  142. package/dist/types/interceptors/index.d.ts +2 -1
  143. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  144. package/dist/types/interceptors/utils.d.ts +1 -0
  145. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  146. package/dist/types/locus-info/index.d.ts +126 -15
  147. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  148. package/dist/types/locus-info/types.d.ts +28 -1
  149. package/dist/types/media/MediaConnectionAwaiter.d.ts +20 -2
  150. package/dist/types/media/properties.d.ts +8 -3
  151. package/dist/types/meeting/in-meeting-actions.d.ts +10 -0
  152. package/dist/types/meeting/index.d.ts +245 -16
  153. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  154. package/dist/types/meeting/request.d.ts +17 -1
  155. package/dist/types/meeting/request.type.d.ts +5 -0
  156. package/dist/types/meeting/util.d.ts +40 -0
  157. package/dist/types/meetings/index.d.ts +42 -20
  158. package/dist/types/meetings/meetings.types.d.ts +15 -0
  159. package/dist/types/meetings/request.d.ts +14 -0
  160. package/dist/types/member/index.d.ts +2 -0
  161. package/dist/types/member/types.d.ts +1 -0
  162. package/dist/types/member/util.d.ts +14 -0
  163. package/dist/types/members/index.d.ts +15 -2
  164. package/dist/types/members/util.d.ts +1 -5
  165. package/dist/types/metrics/constants.d.ts +11 -0
  166. package/dist/types/multistream/codec/constants.d.ts +7 -0
  167. package/dist/types/multistream/mediaRequestManager.d.ts +20 -26
  168. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  169. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  170. package/dist/types/reachability/index.d.ts +10 -3
  171. package/dist/types/reachability/reachability.types.d.ts +7 -0
  172. package/dist/types/reachability/util.d.ts +17 -0
  173. package/dist/types/reactions/reactions.type.d.ts +4 -0
  174. package/dist/types/webinar/utils.d.ts +6 -0
  175. package/dist/webinar/index.js +585 -164
  176. package/dist/webinar/index.js.map +1 -1
  177. package/dist/webinar/utils.js +25 -0
  178. package/dist/webinar/utils.js.map +1 -0
  179. package/package.json +24 -23
  180. package/src/aiEnableRequest/README.md +84 -0
  181. package/src/aiEnableRequest/index.ts +186 -0
  182. package/src/aiEnableRequest/utils.ts +25 -0
  183. package/src/annotation/index.ts +27 -7
  184. package/src/breakouts/breakout.ts +3 -1
  185. package/src/breakouts/events.ts +33 -11
  186. package/src/breakouts/index.ts +110 -1
  187. package/src/common/errors/webex-errors.ts +50 -3
  188. package/src/config.ts +6 -2
  189. package/src/constants.ts +49 -3
  190. package/src/controls-options-manager/constants.ts +14 -1
  191. package/src/controls-options-manager/index.ts +87 -28
  192. package/src/controls-options-manager/util.ts +81 -1
  193. package/src/hashTree/constants.ts +17 -0
  194. package/src/hashTree/hashTree.ts +17 -0
  195. package/src/hashTree/hashTreeParser.ts +1482 -361
  196. package/src/hashTree/types.ts +4 -0
  197. package/src/hashTree/utils.ts +45 -0
  198. package/src/index.ts +14 -1
  199. package/src/interceptors/constant.ts +6 -0
  200. package/src/interceptors/dataChannelAuthToken.ts +246 -0
  201. package/src/interceptors/index.ts +2 -1
  202. package/src/interceptors/locusRetry.ts +25 -4
  203. package/src/interceptors/utils.ts +16 -0
  204. package/src/interpretation/index.ts +29 -11
  205. package/src/interpretation/interpretation.types.ts +11 -0
  206. package/src/locus-info/controlsUtils.ts +14 -1
  207. package/src/locus-info/index.ts +975 -203
  208. package/src/locus-info/infoUtils.ts +41 -6
  209. package/src/locus-info/selfUtils.ts +1 -0
  210. package/src/locus-info/types.ts +33 -1
  211. package/src/media/MediaConnectionAwaiter.ts +62 -5
  212. package/src/media/index.ts +10 -1
  213. package/src/media/properties.ts +11 -4
  214. package/src/meeting/in-meeting-actions.ts +20 -0
  215. package/src/meeting/index.ts +1272 -164
  216. package/src/meeting/locusMediaRequest.ts +106 -6
  217. package/src/meeting/muteState.ts +10 -1
  218. package/src/meeting/request.ts +53 -0
  219. package/src/meeting/request.type.ts +6 -0
  220. package/src/meeting/util.ts +207 -7
  221. package/src/meeting-info/meeting-info-v2.ts +4 -2
  222. package/src/meetings/index.ts +319 -117
  223. package/src/meetings/meetings.types.ts +19 -0
  224. package/src/meetings/request.ts +43 -0
  225. package/src/meetings/util.ts +117 -4
  226. package/src/member/index.ts +20 -0
  227. package/src/member/types.ts +1 -0
  228. package/src/member/util.ts +41 -0
  229. package/src/members/index.ts +70 -7
  230. package/src/members/util.ts +12 -4
  231. package/src/metrics/constants.ts +12 -0
  232. package/src/multistream/codec/constants.ts +58 -0
  233. package/src/multistream/mediaRequestManager.ts +117 -76
  234. package/src/multistream/receiveSlot.ts +18 -0
  235. package/src/multistream/remoteMediaManager.ts +13 -0
  236. package/src/multistream/sendSlotManager.ts +97 -3
  237. package/src/reachability/clusterReachability.ts +3 -2
  238. package/src/reachability/index.ts +56 -16
  239. package/src/reachability/reachability.types.ts +11 -0
  240. package/src/reachability/util.ts +36 -0
  241. package/src/reactions/reactions.type.ts +4 -0
  242. package/src/reconnection-manager/index.ts +0 -1
  243. package/src/recording-controller/index.ts +1 -2
  244. package/src/roap/turnDiscovery.ts +9 -1
  245. package/src/webinar/index.ts +448 -11
  246. package/src/webinar/utils.ts +16 -0
  247. package/test/unit/spec/aiEnableRequest/index.ts +1067 -0
  248. package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
  249. package/test/unit/spec/annotation/index.ts +69 -7
  250. package/test/unit/spec/breakouts/breakout.ts +9 -3
  251. package/test/unit/spec/breakouts/events.ts +120 -2
  252. package/test/unit/spec/breakouts/index.ts +191 -2
  253. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  254. package/test/unit/spec/controls-options-manager/index.js +244 -29
  255. package/test/unit/spec/controls-options-manager/util.js +165 -0
  256. package/test/unit/spec/hashTree/hashTree.ts +66 -0
  257. package/test/unit/spec/hashTree/hashTreeParser.ts +4528 -171
  258. package/test/unit/spec/hashTree/utils.ts +125 -1
  259. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +406 -0
  260. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  261. package/test/unit/spec/interceptors/utils.ts +75 -0
  262. package/test/unit/spec/interpretation/index.ts +26 -4
  263. package/test/unit/spec/locus-info/controlsUtils.js +200 -56
  264. package/test/unit/spec/locus-info/index.js +1848 -164
  265. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  266. package/test/unit/spec/media/MediaConnectionAwaiter.ts +96 -1
  267. package/test/unit/spec/media/index.ts +92 -0
  268. package/test/unit/spec/media/properties.ts +35 -26
  269. package/test/unit/spec/meeting/in-meeting-actions.ts +12 -2
  270. package/test/unit/spec/meeting/index.js +3706 -405
  271. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  272. package/test/unit/spec/meeting/muteState.js +81 -0
  273. package/test/unit/spec/meeting/request.js +82 -0
  274. package/test/unit/spec/meeting/utils.js +595 -27
  275. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  276. package/test/unit/spec/meetings/index.js +1138 -86
  277. package/test/unit/spec/meetings/request.js +141 -0
  278. package/test/unit/spec/meetings/utils.js +402 -51
  279. package/test/unit/spec/member/index.js +35 -4
  280. package/test/unit/spec/member/util.js +154 -27
  281. package/test/unit/spec/members/index.js +216 -0
  282. package/test/unit/spec/members/request.js +37 -1
  283. package/test/unit/spec/members/utils.js +63 -0
  284. package/test/unit/spec/multistream/mediaRequestManager.ts +503 -122
  285. package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
  286. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  287. package/test/unit/spec/reachability/index.ts +151 -46
  288. package/test/unit/spec/reachability/util.ts +31 -0
  289. package/test/unit/spec/reconnection-manager/index.js +4 -8
  290. package/test/unit/spec/recording-controller/index.js +9 -8
  291. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  292. package/test/unit/spec/webinar/index.ts +837 -39
  293. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -3,9 +3,10 @@ import sinon from 'sinon';
3
3
  import {cloneDeep, forEach} from 'lodash';
4
4
  import {assert} from '@webex/test-helper-chai';
5
5
  import MockWebex from '@webex/test-helper-mock-webex';
6
+ import {webexTrackingIdSequenceNumbers} from '@webex/webex-core';
6
7
  import testUtils from '../../../utils/testUtils';
7
8
  import Meetings from '@webex/plugin-meetings';
8
- import LocusInfo from '@webex/plugin-meetings/src/locus-info';
9
+ import LocusInfo, {createLocusFromHashTreeMessage, findMeetingForHashTreeMessage} from '@webex/plugin-meetings/src/locus-info';
9
10
  import SelfUtils from '@webex/plugin-meetings/src/locus-info/selfUtils';
10
11
  import InfoUtils from '@webex/plugin-meetings/src/locus-info/infoUtils';
11
12
  import EmbeddedAppsUtils from '@webex/plugin-meetings/src/locus-info/embeddedAppsUtils';
@@ -13,6 +14,7 @@ import MediaSharesUtils from '@webex/plugin-meetings/src/locus-info//mediaShares
13
14
  import LocusDeltaParser from '@webex/plugin-meetings/src/locus-info/parser';
14
15
  import Metrics from '@webex/plugin-meetings/src/metrics';
15
16
  import * as HashTreeParserModule from '@webex/plugin-meetings/src/hashTree/hashTreeParser';
17
+ import MeetingsUtil from '@webex/plugin-meetings/src/meetings/util';
16
18
 
17
19
  import {
18
20
  LOCUSINFO,
@@ -29,7 +31,9 @@ import {
29
31
  } from '../../../../src/constants';
30
32
 
31
33
  import {self, selfWithInactivity} from './selfConstant';
32
- import { MEETING_REMOVED_REASON } from '@webex/plugin-meetings/src/constants';
34
+ import {MEETING_REMOVED_REASON} from '@webex/plugin-meetings/src/constants';
35
+ import BEHAVIORAL_METRICS from '@webex/plugin-meetings/src/metrics/constants';
36
+ import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
33
37
 
34
38
  describe('plugin-meetings', () => {
35
39
  describe('LocusInfo index', () => {
@@ -54,7 +58,7 @@ describe('plugin-meetings', () => {
54
58
 
55
59
  beforeEach(() => {
56
60
  mockMeeting = {};
57
- locusInfo = new LocusInfo(updateMeeting, webex, meetingId);
61
+ locusInfo = new LocusInfo({updateMeeting}, webex, meetingId);
58
62
 
59
63
  locusInfo.init(locus);
60
64
 
@@ -104,9 +108,10 @@ describe('plugin-meetings', () => {
104
108
  });
105
109
 
106
110
  const createHashTreeMessage = (visibleDataSets) => ({
111
+ locusUrl: 'http://locus-url.com',
107
112
  locusStateElements: [
108
113
  {
109
- htMeta: {elementId: {type: 'self'}},
114
+ htMeta: {elementId: {type: 'metadata'}},
110
115
  data: {visibleDataSets},
111
116
  },
112
117
  ],
@@ -114,6 +119,7 @@ describe('plugin-meetings', () => {
114
119
  });
115
120
 
116
121
  const createLocusWithVisibleDataSets = (visibleDataSets) => ({
122
+ url: 'http://locus-url.com',
117
123
  self: {visibleDataSets},
118
124
  participants: [],
119
125
  links: {
@@ -136,11 +142,17 @@ describe('plugin-meetings', () => {
136
142
  HashTreeParserStub,
137
143
  sinon.match({
138
144
  initialLocus: {
139
- locus: {self: {visibleDataSets}},
140
- dataSets: [],
145
+ locus: null,
146
+ dataSets: hashTreeMessage.dataSets,
147
+ },
148
+ metadata: {
149
+ htMeta: hashTreeMessage.locusStateElements[0].htMeta,
150
+ visibleDataSets,
141
151
  },
142
152
  webexRequest: sinon.match.func,
143
- locusInfoUpdateCallback: sinon.match.func,
153
+ callbacks: sinon.match({
154
+ locusInfoUpdateCallback: sinon.match.func,
155
+ }),
144
156
  debugId: sinon.match.string,
145
157
  })
146
158
  );
@@ -150,6 +162,39 @@ describe('plugin-meetings', () => {
150
162
  assert.isTrue(locusInfo.emitChange);
151
163
  });
152
164
 
165
+ it('passes a generateTrackingId callback that reuses the tracking-id interceptor sequence', async () => {
166
+ webex.sessionId = 'test-session';
167
+ const hashTreeMessage = createHashTreeMessage(['dataset1']);
168
+
169
+ await locusInfo.initialSetup({trigger: 'locus-message', hashTreeMessage});
170
+
171
+ const {generateTrackingId} = HashTreeParserStub.firstCall.args[0].callbacks;
172
+
173
+ // The interceptor for this webex is present in the exposed map -> reuse its sequence.
174
+ const fakeInterceptor = {webex, sequence: 7};
175
+ webexTrackingIdSequenceNumbers.set(fakeInterceptor, 0);
176
+
177
+ try {
178
+ assert.equal(generateTrackingId(), 'test-session_7');
179
+ } finally {
180
+ webexTrackingIdSequenceNumbers.delete(fakeInterceptor);
181
+ }
182
+ });
183
+
184
+ it('passes a generateTrackingId callback that falls back to a uuid when no interceptor is registered', async () => {
185
+ webex.sessionId = 'test-session';
186
+ const hashTreeMessage = createHashTreeMessage(['dataset1']);
187
+
188
+ await locusInfo.initialSetup({trigger: 'locus-message', hashTreeMessage});
189
+
190
+ const {generateTrackingId} = HashTreeParserStub.firstCall.args[0].callbacks;
191
+
192
+ assert.match(
193
+ generateTrackingId(),
194
+ /^test-session_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
195
+ );
196
+ });
197
+
153
198
  it('should not initialize the hash tree when triggered from a non-hash tree locus message', async () => {
154
199
  const locus = {url: 'http://locus-url.com', participants: []};
155
200
 
@@ -169,11 +214,16 @@ describe('plugin-meetings', () => {
169
214
  const visibleDataSets = ['dataset1', 'dataset2'];
170
215
  const locus = createLocusWithVisibleDataSets(visibleDataSets);
171
216
  const dataSets = [{name: 'dataset1', url: 'http://dataset-url.com'}];
217
+ const metadata = {
218
+ htMeta: {elementId: {type: 'metadata'}},
219
+ visibleDataSets,
220
+ };
172
221
 
173
222
  await locusInfo.initialSetup({
174
223
  trigger: 'join-response',
175
224
  locus,
176
225
  dataSets,
226
+ metadata,
177
227
  });
178
228
 
179
229
  assert.calledOnceWithExactly(
@@ -183,8 +233,11 @@ describe('plugin-meetings', () => {
183
233
  locus,
184
234
  dataSets,
185
235
  },
236
+ metadata,
186
237
  webexRequest: sinon.match.func,
187
- locusInfoUpdateCallback: sinon.match.func,
238
+ callbacks: sinon.match({
239
+ locusInfoUpdateCallback: sinon.match.func,
240
+ }),
188
241
  debugId: sinon.match.string,
189
242
  })
190
243
  );
@@ -207,6 +260,47 @@ describe('plugin-meetings', () => {
207
260
  assert.isTrue(locusInfo.emitChange);
208
261
  });
209
262
 
263
+ it('calls onLocusSynced callback passed as second argument with full locus from join response', async () => {
264
+ const syncedLocus = {url: 'http://locus-url.com', participants: []};
265
+ const onLocusSynced = sinon.stub();
266
+
267
+ await locusInfo.initialSetup(
268
+ {
269
+ trigger: 'join-response',
270
+ locus: syncedLocus,
271
+ },
272
+ onLocusSynced
273
+ );
274
+
275
+ assert.calledOnceWithExactly(onLocusSynced, syncedLocus);
276
+ });
277
+
278
+ it('swallows onLocusSynced callback errors and logs warn', async () => {
279
+ const syncedLocus = {url: 'http://locus-url.com', participants: []};
280
+ const callbackError = new Error('onLocusSynced failed');
281
+ const onLocusSynced = sinon.stub().throws(callbackError);
282
+ const loggerWarnStub = LoggerProxy.logger.warn?.isSinonProxy
283
+ ? LoggerProxy.logger.warn
284
+ : sinon.stub(LoggerProxy.logger, 'warn');
285
+
286
+ loggerWarnStub.resetHistory();
287
+
288
+ await locusInfo.initialSetup(
289
+ {
290
+ trigger: 'join-response',
291
+ locus: syncedLocus,
292
+ },
293
+ onLocusSynced
294
+ );
295
+
296
+ assert.calledOnceWithExactly(onLocusSynced, syncedLocus);
297
+ assert.calledOnce(loggerWarnStub);
298
+ assert.match(
299
+ loggerWarnStub.firstCall.args[0],
300
+ /Locus-info:index#initialSetup --> onLocusSynced callback failed/
301
+ );
302
+ });
303
+
210
304
  it('should initialize the hash tree parser correctly when triggered from a get loci response containing visible datasets', async () => {
211
305
  const visibleDataSets = ['dataset1', 'dataset2'];
212
306
  const locus = createLocusWithVisibleDataSets(visibleDataSets);
@@ -220,12 +314,15 @@ describe('plugin-meetings', () => {
220
314
  HashTreeParserStub,
221
315
  sinon.match({
222
316
  initialLocus: {
223
- locus: {self: {visibleDataSets}},
317
+ locus: null,
224
318
  dataSets: [],
225
319
  },
226
320
  webexRequest: sinon.match.func,
227
- locusInfoUpdateCallback: sinon.match.func,
321
+ callbacks: sinon.match({
322
+ locusInfoUpdateCallback: sinon.match.func,
323
+ }),
228
324
  debugId: sinon.match.string,
325
+ metadata: null,
229
326
  })
230
327
  );
231
328
  assert.calledOnceWithExactly(mockHashTreeParser.initializeFromGetLociResponse, locus);
@@ -249,9 +346,34 @@ describe('plugin-meetings', () => {
249
346
  assert.isTrue(locusInfo.emitChange);
250
347
  });
251
348
 
349
+ it('throws if called with "locus-message" and Metadata object without visibleDataSets', async () => {
350
+ const hashTreeMessage = {
351
+ locusStateElements: [
352
+ {
353
+ htMeta: {elementId: {type: 'Metadata'}},
354
+ data: {},
355
+ },
356
+ ],
357
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
358
+ };
359
+ try {
360
+ await locusInfo.initialSetup({
361
+ trigger: 'locus-message',
362
+ hashTreeMessage,
363
+ });
364
+ assert.fail('should have thrown an error');
365
+ } catch (error) {
366
+ assert.equal(
367
+ error.message,
368
+ 'Metadata object with visibleDataSets is missing in the message'
369
+ );
370
+ }
371
+ });
372
+
252
373
  describe('should setup correct locusInfoUpdateCallback when creating HashTreeParser', () => {
253
374
  const OBJECTS_UPDATED = HashTreeParserModule.LocusInfoUpdateType.OBJECTS_UPDATED;
254
375
  const MEETING_ENDED = HashTreeParserModule.LocusInfoUpdateType.MEETING_ENDED;
376
+ const LOCUS_NOT_FOUND = HashTreeParserModule.LocusInfoUpdateType.LOCUS_NOT_FOUND;
255
377
 
256
378
  let locusInfoUpdateCallback;
257
379
  let onDeltaLocusStub;
@@ -263,17 +385,18 @@ describe('plugin-meetings', () => {
263
385
  await locusInfo.initialSetup({
264
386
  trigger: 'locus-message',
265
387
  hashTreeMessage: {
388
+ locusUrl: 'fake-locus-url',
266
389
  locusStateElements: [
267
390
  {
268
- htMeta: {elementId: {type: 'self'}},
269
- data: {visibleDataSets: ['dataset1']},
391
+ htMeta: {elementId: {type: 'Metadata'}},
392
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
270
393
  },
271
394
  ],
272
395
  dataSets: [{name: 'dataset1', url: 'test-url'}],
273
396
  },
274
397
  });
275
398
 
276
- locusInfoUpdateCallback = HashTreeParserStub.firstCall.args[0].locusInfoUpdateCallback;
399
+ locusInfoUpdateCallback = HashTreeParserStub.firstCall.args[0].callbacks.locusInfoUpdateCallback;
277
400
 
278
401
  assert.isDefined(locusInfoUpdateCallback);
279
402
 
@@ -293,6 +416,16 @@ describe('plugin-meetings', () => {
293
416
  htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-2', version: 1}},
294
417
  },
295
418
  ];
419
+ locusInfo.embeddedApps = [
420
+ {
421
+ id: 'fake-embedded-app-1',
422
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-1', version: 1}},
423
+ },
424
+ {
425
+ id: 'fake-embedded-app-2',
426
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2', version: 1}},
427
+ },
428
+ ];
296
429
  locusInfo.meetings = {id: 'fake-meetings'};
297
430
  locusInfo.participants = [
298
431
  {id: 'fake-participant-1', name: 'Participant One'},
@@ -311,6 +444,13 @@ describe('plugin-meetings', () => {
311
444
  locusInfo.url = 'fake-locus-url';
312
445
  locusInfo.htMeta = {elementId: {type: 'locus', id: 'fake-ht-locus-id', version: 1}};
313
446
 
447
+ const createdHashTreeParser = locusInfo.hashTreeParsers.get('fake-locus-url');
448
+
449
+ assert.isDefined(createdHashTreeParser);
450
+ // this flag would have been set to true on the first callback triggered by initialSetup() wa called earlier
451
+ // it's not because we're mocking HashTreeParser, so we have to set it manually here
452
+ createdHashTreeParser.initializedFromHashTree = true;
453
+
314
454
  // setup the default expected locus info state that each test builds upon
315
455
  expectedLocusInfo = {
316
456
  controls: {id: 'fake-controls'},
@@ -328,8 +468,18 @@ describe('plugin-meetings', () => {
328
468
  htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-2', version: 1}},
329
469
  },
330
470
  ],
471
+ embeddedApps: [
472
+ {
473
+ id: 'fake-embedded-app-1',
474
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-1', version: 1}},
475
+ },
476
+ {
477
+ id: 'fake-embedded-app-2',
478
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2', version: 1}},
479
+ },
480
+ ],
331
481
  meetings: {id: 'fake-meetings'},
332
- jsSdkMeta: {removedParticipantIds: []},
482
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false},
333
483
  participants: [], // empty means there were no participant updates
334
484
  replaces: {id: 'fake-replaces'},
335
485
  self: {id: 'fake-self'},
@@ -347,7 +497,7 @@ describe('plugin-meetings', () => {
347
497
  };
348
498
 
349
499
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
350
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
500
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
351
501
  updatedObjects: [{htMeta: {elementId: {type: 'self'}}, data: newSelf}],
352
502
  });
353
503
 
@@ -374,7 +524,7 @@ describe('plugin-meetings', () => {
374
524
  locusInfo.info.isWebinar = true;
375
525
 
376
526
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
377
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
527
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
378
528
  updatedObjects: [{htMeta: {elementId: {type: 'self'}}, data: newSelf}],
379
529
  });
380
530
 
@@ -407,7 +557,7 @@ describe('plugin-meetings', () => {
407
557
  locusInfo.info.isWebinar = true;
408
558
 
409
559
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
410
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
560
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
411
561
  updatedObjects: [{htMeta: {elementId: {type: 'self'}}, data: newSelf}],
412
562
  });
413
563
 
@@ -435,7 +585,7 @@ describe('plugin-meetings', () => {
435
585
  };
436
586
 
437
587
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
438
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
588
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
439
589
  updatedObjects: [{htMeta: {elementId: {type: 'fullState'}}, data: newFullState}],
440
590
  });
441
591
 
@@ -453,7 +603,7 @@ describe('plugin-meetings', () => {
453
603
  };
454
604
 
455
605
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
456
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
606
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
457
607
  updatedObjects: [{htMeta: {elementId: {type: 'info'}}, data: newInfo}],
458
608
  });
459
609
 
@@ -471,7 +621,7 @@ describe('plugin-meetings', () => {
471
621
  };
472
622
 
473
623
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
474
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
624
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
475
625
  updatedObjects: [{htMeta: {elementId: {type: 'links'}}, data: newLinks}],
476
626
  });
477
627
 
@@ -491,7 +641,7 @@ describe('plugin-meetings', () => {
491
641
  };
492
642
 
493
643
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
494
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
644
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
495
645
  updatedObjects: [{htMeta: newLocusHtMeta, data: newLocus}],
496
646
  });
497
647
 
@@ -504,11 +654,12 @@ describe('plugin-meetings', () => {
504
654
  self: {id: 'fake-self'},
505
655
  links: {id: 'fake-links'},
506
656
  mediaShares: expectedLocusInfo.mediaShares,
657
+ embeddedApps: expectedLocusInfo.embeddedApps,
507
658
  // and now the new fields
508
659
  ...newLocus,
509
660
  htMeta: newLocusHtMeta,
510
661
  participants: [], // empty means there were no participant updates
511
- jsSdkMeta: {removedParticipantIds: []}, // no participants were removed
662
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false}, // no participants were removed
512
663
  });
513
664
  });
514
665
 
@@ -523,7 +674,7 @@ describe('plugin-meetings', () => {
523
674
  };
524
675
 
525
676
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
526
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
677
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
527
678
  updatedObjects: [
528
679
  {
529
680
  htMeta: newLocusHtMeta,
@@ -536,6 +687,7 @@ describe('plugin-meetings', () => {
536
687
  self: 'new-self',
537
688
  participants: 'new-participants',
538
689
  mediaShares: 'new-mediaShares',
690
+ embeddedApps: 'new-embeddedApps',
539
691
  },
540
692
  },
541
693
  ],
@@ -551,8 +703,9 @@ describe('plugin-meetings', () => {
551
703
  self: {id: 'fake-self'},
552
704
  links: {id: 'fake-links'},
553
705
  mediaShares: expectedLocusInfo.mediaShares,
706
+ embeddedApps: expectedLocusInfo.embeddedApps,
554
707
  participants: [], // empty means there were no participant updates
555
- jsSdkMeta: {removedParticipantIds: []}, // no participants were removed
708
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false}, // no participants were removed
556
709
  ...newLocus,
557
710
  htMeta: newLocusHtMeta,
558
711
  });
@@ -568,7 +721,7 @@ describe('plugin-meetings', () => {
568
721
  };
569
722
 
570
723
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
571
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
724
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
572
725
  updatedObjects: [
573
726
  // first, a removal of LOCUS object
574
727
  {htMeta: {elementId: {type: 'locus'}}, data: null},
@@ -586,11 +739,12 @@ describe('plugin-meetings', () => {
586
739
  self: {id: 'fake-self'},
587
740
  links: {id: 'fake-links'},
588
741
  mediaShares: expectedLocusInfo.mediaShares,
742
+ embeddedApps: expectedLocusInfo.embeddedApps,
589
743
  // and now the new fields
590
744
  ...newLocus,
591
745
  htMeta: newLocusHtMeta,
592
746
  participants: [], // empty means there were no participant updates
593
- jsSdkMeta: {removedParticipantIds: []}, // no participants were removed
747
+ jsSdkMeta: {removedParticipantIds: [], forceReplaceMembers: false}, // no participants were removed
594
748
  });
595
749
  });
596
750
 
@@ -601,7 +755,7 @@ describe('plugin-meetings', () => {
601
755
  const newLocusHtMeta = {elementId: {type: 'locus', version: 99}};
602
756
 
603
757
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
604
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
758
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
605
759
  updatedObjects: [
606
760
  // first, an update
607
761
  {htMeta: newLocusHtMeta, data: newLocus},
@@ -630,7 +784,7 @@ describe('plugin-meetings', () => {
630
784
  };
631
785
 
632
786
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
633
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
787
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
634
788
  updatedObjects: [
635
789
  // first, an update
636
790
  {htMeta: {elementId: {type: 'locus'}}, data: newLocus1},
@@ -660,7 +814,7 @@ describe('plugin-meetings', () => {
660
814
  };
661
815
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
662
816
  // with 1 participant added, 1 updated, and 1 removed
663
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
817
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
664
818
  updatedObjects: [
665
819
  {htMeta: {elementId: {type: 'participant', id: 'fake-ht-participant-1'}}, data: null},
666
820
  {
@@ -678,7 +832,7 @@ describe('plugin-meetings', () => {
678
832
  assert.calledOnceWithExactly(onDeltaLocusStub, {
679
833
  ...expectedLocusInfo,
680
834
  participants: [newParticipant, updatedParticipant2],
681
- jsSdkMeta: {removedParticipantIds: ['fake-participant-1']},
835
+ jsSdkMeta: {removedParticipantIds: ['fake-participant-1'], forceReplaceMembers: false},
682
836
  });
683
837
  // and that the hashTreeObjectId2ParticipantId map was updated correctly
684
838
  assert.isUndefined(locusInfo.hashTreeObjectId2ParticipantId.get('fake-ht-participant-1'));
@@ -704,7 +858,7 @@ describe('plugin-meetings', () => {
704
858
  };
705
859
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
706
860
  // with 1 participant added, 1 updated, and 1 removed
707
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
861
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
708
862
  updatedObjects: [
709
863
  {htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-1'}}, data: null},
710
864
  {
@@ -725,6 +879,39 @@ describe('plugin-meetings', () => {
725
879
  });
726
880
  });
727
881
 
882
+ it('should process locus update correctly when called with updated EMBEDDEDAPP objects', () => {
883
+ const newEmbeddedApp = {
884
+ id: 'new-embedded-app-3',
885
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-3', version: 100}},
886
+ };
887
+ const updatedEmbeddedApp2 = {
888
+ id: 'fake-embedded-app-2',
889
+ someNewProp: 'newValue',
890
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2', version: 100}},
891
+ };
892
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
893
+ // with 1 embedded app added, 1 updated, and 1 removed
894
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
895
+ updatedObjects: [
896
+ {htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-1'}}, data: null},
897
+ {
898
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-2'}},
899
+ data: updatedEmbeddedApp2,
900
+ },
901
+ {
902
+ htMeta: {elementId: {type: 'embeddedapp', id: 'fake-ht-embeddedApp-3'}},
903
+ data: newEmbeddedApp,
904
+ },
905
+ ],
906
+ });
907
+
908
+ // check onDeltaLocus() was called with correctly updated locus info
909
+ assert.calledOnceWithExactly(onDeltaLocusStub, {
910
+ ...expectedLocusInfo,
911
+ embeddedApps: [updatedEmbeddedApp2, newEmbeddedApp],
912
+ });
913
+ });
914
+
728
915
  it('should process locus update correctly when called with a combination of various updated objects', () => {
729
916
  const newSelf = {
730
917
  id: 'new-self',
@@ -741,7 +928,7 @@ describe('plugin-meetings', () => {
741
928
  };
742
929
 
743
930
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
744
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
931
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
745
932
  updatedObjects: [
746
933
  {
747
934
  htMeta: {elementId: {type: 'mediashare', id: 'fake-ht-mediaShare-2'}},
@@ -780,7 +967,7 @@ describe('plugin-meetings', () => {
780
967
  };
781
968
 
782
969
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
783
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
970
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
784
971
  updatedObjects: [
785
972
  {
786
973
  htMeta: {elementId: {type: 'controlentry', id: 'control-1'}},
@@ -808,7 +995,7 @@ describe('plugin-meetings', () => {
808
995
 
809
996
  it('should process locus update correctly when CONTROL object is received with no data', () => {
810
997
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
811
- locusInfoUpdateCallback(OBJECTS_UPDATED, {
998
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
812
999
  updatedObjects: [
813
1000
  {
814
1001
  htMeta: {elementId: {type: 'controlentry', id: 'some-control-id'}},
@@ -832,7 +1019,7 @@ describe('plugin-meetings', () => {
832
1019
  const destroyStub = sinon.stub(locusInfo.webex.meetings, 'destroy');
833
1020
 
834
1021
  // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
835
- locusInfoUpdateCallback(MEETING_ENDED);
1022
+ locusInfoUpdateCallback({updateType: MEETING_ENDED});
836
1023
 
837
1024
  assert.calledOnceWithExactly(collectionGetStub, locusInfo.meetingId);
838
1025
  assert.calledOnceWithExactly(
@@ -841,6 +1028,109 @@ describe('plugin-meetings', () => {
841
1028
  MEETING_REMOVED_REASON.SELF_REMOVED
842
1029
  );
843
1030
  });
1031
+
1032
+ // this could happen if meeting gets destroyed while we're doing some async hash tree operation like a sync
1033
+ it('should handle MEETING_ENDED correctly when meeting is not found in the collection', () => {
1034
+ const collectionGetStub = sinon
1035
+ .stub(locusInfo.webex.meetings.meetingCollection, 'get')
1036
+ .returns(null);
1037
+ const destroyStub = sinon.stub(locusInfo.webex.meetings, 'destroy');
1038
+
1039
+ // simulate an update from the HashTreeParser (normally this would be triggered by incoming locus messages)
1040
+ locusInfoUpdateCallback({updateType: MEETING_ENDED});
1041
+
1042
+ assert.calledOnceWithExactly(collectionGetStub, locusInfo.meetingId);
1043
+ assert.notCalled(destroyStub);
1044
+ });
1045
+
1046
+ it('should handle LOCUS_NOT_FOUND by calling syncMeetings with skipHashTreeSync', () => {
1047
+ const syncMeetingsStub = sinon.stub(locusInfo.webex.meetings, 'syncMeetings').resolves();
1048
+
1049
+ locusInfoUpdateCallback({updateType: LOCUS_NOT_FOUND});
1050
+
1051
+ assert.calledOnceWithExactly(syncMeetingsStub, {keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1052
+ });
1053
+
1054
+ it('should handle LOCUS_NOT_FOUND and log error if syncMeetings fails', async () => {
1055
+ const syncError = new Error('sync failed');
1056
+ const syncMeetingsStub = sinon.stub(locusInfo.webex.meetings, 'syncMeetings').rejects(syncError);
1057
+ const logErrorStub = LoggerProxy.logger.error?.isSinonProxy
1058
+ ? LoggerProxy.logger.error
1059
+ : sinon.stub(LoggerProxy.logger, 'error');
1060
+
1061
+ logErrorStub.resetHistory();
1062
+
1063
+ locusInfoUpdateCallback({updateType: LOCUS_NOT_FOUND});
1064
+
1065
+ assert.calledOnceWithExactly(syncMeetingsStub, {keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1066
+
1067
+ // wait for the promise rejection to be handled
1068
+ await testUtils.flushPromises();
1069
+
1070
+ assert.calledOnce(logErrorStub);
1071
+ assert.match(
1072
+ logErrorStub.firstCall.args[0],
1073
+ /syncMeetings failed after LOCUS_NOT_FOUND/
1074
+ );
1075
+ });
1076
+
1077
+ it('should set forceReplaceMembers to true on the first update for a locusUrl (initializedFromHashTree is false)', () => {
1078
+ const createdHashTreeParser = locusInfo.hashTreeParsers.get('fake-locus-url');
1079
+ createdHashTreeParser.initializedFromHashTree = false;
1080
+
1081
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
1082
+ updatedObjects: [
1083
+ {
1084
+ htMeta: {elementId: {type: 'self'}},
1085
+ data: {id: 'new-self'},
1086
+ },
1087
+ ],
1088
+ });
1089
+
1090
+ assert.calledOnce(onDeltaLocusStub);
1091
+ assert.equal(onDeltaLocusStub.firstCall.args[0].jsSdkMeta.forceReplaceMembers, true);
1092
+ assert.isTrue(createdHashTreeParser.initializedFromHashTree);
1093
+ });
1094
+
1095
+ it('should set forceReplaceMembers to false on subsequent updates (initializedFromHashTree is true)', () => {
1096
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
1097
+ updatedObjects: [
1098
+ {
1099
+ htMeta: {elementId: {type: 'self'}},
1100
+ data: {id: 'new-self'},
1101
+ },
1102
+ ],
1103
+ });
1104
+
1105
+ assert.calledOnce(onDeltaLocusStub);
1106
+ assert.equal(onDeltaLocusStub.firstCall.args[0].jsSdkMeta.forceReplaceMembers, false);
1107
+ });
1108
+
1109
+ it('should copy participant data to self when participant matches self identity and state is LEFT with reason MOVED', () => {
1110
+ locusInfo.self = {id: 'fake-self', identity: 'user-123'};
1111
+
1112
+ locusInfoUpdateCallback({updateType: OBJECTS_UPDATED,
1113
+ updatedObjects: [
1114
+ {
1115
+ htMeta: {elementId: {type: 'participant', id: 99}},
1116
+ data: {
1117
+ id: 'participant-matching-self',
1118
+ identity: 'user-123',
1119
+ state: 'LEFT',
1120
+ reason: 'MOVED',
1121
+ roles: ['MODERATOR'],
1122
+ },
1123
+ },
1124
+ ],
1125
+ });
1126
+
1127
+ assert.calledOnce(onDeltaLocusStub);
1128
+ const passedLocus = onDeltaLocusStub.firstCall.args[0];
1129
+
1130
+ assert.equal(passedLocus.self.identity, 'user-123');
1131
+ assert.equal(passedLocus.self.state, 'LEFT');
1132
+ assert.equal(passedLocus.self.reason, 'MOVED');
1133
+ });
844
1134
  });
845
1135
  });
846
1136
 
@@ -1076,7 +1366,7 @@ describe('plugin-meetings', () => {
1076
1366
  it('should trigger the CONTROLS_POLLING_QA_CHANGED event when necessary', () => {
1077
1367
  locusInfo.controls = {};
1078
1368
  locusInfo.emitScoped = sinon.stub();
1079
- newControls.pollingQAControl = { enabled: true };
1369
+ newControls.pollingQAControl = {enabled: true};
1080
1370
  locusInfo.updateControls(newControls);
1081
1371
 
1082
1372
  assert.calledWith(
@@ -1114,6 +1404,8 @@ describe('plugin-meetings', () => {
1114
1404
  state: RECORDING_STATE.IDLE,
1115
1405
  modifiedBy: 'George Kittle',
1116
1406
  lastModified: 'TODAY',
1407
+ modifiedByServiceAppName: undefined,
1408
+ modifiedByServiceAppId: undefined,
1117
1409
  }
1118
1410
  );
1119
1411
  });
@@ -1148,6 +1440,8 @@ describe('plugin-meetings', () => {
1148
1440
  state: RECORDING_STATE.RECORDING,
1149
1441
  modifiedBy: 'George Kittle',
1150
1442
  lastModified: 'TODAY',
1443
+ modifiedByServiceAppName: undefined,
1444
+ modifiedByServiceAppId: undefined,
1151
1445
  }
1152
1446
  );
1153
1447
  });
@@ -1183,6 +1477,8 @@ describe('plugin-meetings', () => {
1183
1477
  state: RECORDING_STATE.PAUSED,
1184
1478
  modifiedBy: 'George Kittle',
1185
1479
  lastModified: 'TODAY',
1480
+ modifiedByServiceAppName: undefined,
1481
+ modifiedByServiceAppId: undefined,
1186
1482
  }
1187
1483
  );
1188
1484
  });
@@ -1219,6 +1515,8 @@ describe('plugin-meetings', () => {
1219
1515
  state: RECORDING_STATE.RESUMED,
1220
1516
  modifiedBy: 'George Kittle',
1221
1517
  lastModified: 'TODAY',
1518
+ modifiedByServiceAppName: undefined,
1519
+ modifiedByServiceAppId: undefined,
1222
1520
  }
1223
1521
  );
1224
1522
  });
@@ -1254,6 +1552,44 @@ describe('plugin-meetings', () => {
1254
1552
  state: RECORDING_STATE.IDLE,
1255
1553
  modifiedBy: 'George Kittle',
1256
1554
  lastModified: 'TODAY',
1555
+ modifiedByServiceAppName: undefined,
1556
+ modifiedByServiceAppId: undefined,
1557
+ }
1558
+ );
1559
+ });
1560
+
1561
+ it('should include service app fields in the recording event when present', () => {
1562
+ locusInfo.controls = {
1563
+ record: {
1564
+ recording: false,
1565
+ paused: false,
1566
+ meta: {
1567
+ lastModified: 'TODAY',
1568
+ modifiedBy: 'George Kittle',
1569
+ },
1570
+ },
1571
+ shareControl: {},
1572
+ transcribe: {},
1573
+ };
1574
+ newControls.record.recording = true;
1575
+ newControls.record.meta.modifiedByServiceAppName = 'My Bot';
1576
+ newControls.record.meta.modifiedByServiceAppId = 'app-id-123';
1577
+ locusInfo.emitScoped = sinon.stub();
1578
+ locusInfo.updateControls(newControls);
1579
+
1580
+ assert.calledWith(
1581
+ locusInfo.emitScoped,
1582
+ {
1583
+ file: 'locus-info',
1584
+ function: 'updateControls',
1585
+ },
1586
+ LOCUSINFO.EVENTS.CONTROLS_RECORDING_UPDATED,
1587
+ {
1588
+ state: RECORDING_STATE.RECORDING,
1589
+ modifiedBy: 'George Kittle',
1590
+ lastModified: 'TODAY',
1591
+ modifiedByServiceAppName: 'My Bot',
1592
+ modifiedByServiceAppId: 'app-id-123',
1257
1593
  }
1258
1594
  );
1259
1595
  });
@@ -1366,6 +1702,34 @@ describe('plugin-meetings', () => {
1366
1702
  );
1367
1703
  });
1368
1704
 
1705
+ it('should emit CONTROLS_AI_SUMMARY_NOTIFICATION_UPDATED when aiSummaryNotification changes', () => {
1706
+ locusInfo.emitScoped = sinon.stub();
1707
+ locusInfo.controls = {
1708
+ transcribe: {
1709
+ transcribing: false,
1710
+ caption: false,
1711
+ aiSummaryNotification: false,
1712
+ },
1713
+ };
1714
+ newControls.transcribe.transcribing = false;
1715
+ newControls.transcribe.caption = false;
1716
+ newControls.transcribe.aiSummaryNotification = true;
1717
+
1718
+ locusInfo.updateControls(newControls);
1719
+
1720
+ assert.calledWith(
1721
+ locusInfo.emitScoped,
1722
+ {
1723
+ file: 'locus-info',
1724
+ function: 'updateControls',
1725
+ },
1726
+ LOCUSINFO.EVENTS.CONTROLS_AI_SUMMARY_NOTIFICATION_UPDATED,
1727
+ {
1728
+ aiSummaryNotification: true,
1729
+ }
1730
+ );
1731
+ });
1732
+
1369
1733
  it('should update the transcribe spoken language', () => {
1370
1734
  locusInfo.emitScoped = sinon.stub();
1371
1735
  locusInfo.controls = {
@@ -1631,7 +1995,6 @@ describe('plugin-meetings', () => {
1631
1995
  );
1632
1996
  });
1633
1997
 
1634
-
1635
1998
  it('should call with participant display name', () => {
1636
1999
  const failureParticipant = [
1637
2000
  {
@@ -1656,7 +2019,7 @@ describe('plugin-meetings', () => {
1656
2019
  displayName: 'Test User',
1657
2020
  }
1658
2021
  );
1659
- })
2022
+ });
1660
2023
  });
1661
2024
 
1662
2025
  describe('#updateSelf', () => {
@@ -1822,7 +2185,7 @@ describe('plugin-meetings', () => {
1822
2185
  function: 'updateSelf',
1823
2186
  },
1824
2187
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1825
- {muted: true, unmuteAllowed: true}
2188
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
1826
2189
  );
1827
2190
 
1828
2191
  // but sometimes "previous self" is defined, but without controls.audio.muted, so we test this here:
@@ -1837,7 +2200,7 @@ describe('plugin-meetings', () => {
1837
2200
  function: 'updateSelf',
1838
2201
  },
1839
2202
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1840
- {muted: true, unmuteAllowed: true}
2203
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
1841
2204
  );
1842
2205
  });
1843
2206
 
@@ -1896,7 +2259,7 @@ describe('plugin-meetings', () => {
1896
2259
  function: 'updateSelf',
1897
2260
  },
1898
2261
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
1899
- {muted: true, unmuteAllowed: true}
2262
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
1900
2263
  );
1901
2264
  });
1902
2265
 
@@ -2035,7 +2398,7 @@ describe('plugin-meetings', () => {
2035
2398
  function: 'updateSelf',
2036
2399
  },
2037
2400
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
2038
- {muted: true, unmuteAllowed: false}
2401
+ {muted: true, unmuteAllowed: false, modifiedBy: null}
2039
2402
  );
2040
2403
 
2041
2404
  // now change only disallowUnmute
@@ -2053,7 +2416,28 @@ describe('plugin-meetings', () => {
2053
2416
  function: 'updateSelf',
2054
2417
  },
2055
2418
  LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
2056
- {muted: true, unmuteAllowed: true}
2419
+ {muted: true, unmuteAllowed: true, modifiedBy: null}
2420
+ );
2421
+ });
2422
+
2423
+ it('should include modifiedBy in payload when muted by host', () => {
2424
+ locusInfo.webex.internal.device.url = self.deviceUrl;
2425
+ locusInfo.updateSelf(self);
2426
+ const newSelf = cloneDeep(self);
2427
+ newSelf.controls.audio.muted = true;
2428
+ newSelf.controls.audio.meta = {modifiedBy: 'host-uuid-123'};
2429
+
2430
+ locusInfo.emitScoped = sinon.stub();
2431
+ locusInfo.updateSelf(newSelf);
2432
+
2433
+ assert.calledWith(
2434
+ locusInfo.emitScoped,
2435
+ {
2436
+ file: 'locus-info',
2437
+ function: 'updateSelf',
2438
+ },
2439
+ LOCUSINFO.EVENTS.SELF_REMOTE_MUTE_STATUS_UPDATED,
2440
+ {muted: true, unmuteAllowed: true, modifiedBy: 'host-uuid-123'}
2057
2441
  );
2058
2442
  });
2059
2443
 
@@ -2457,8 +2841,8 @@ describe('plugin-meetings', () => {
2457
2841
  {
2458
2842
  isInitializing: !self,
2459
2843
  }
2460
- );
2461
- });
2844
+ );
2845
+ });
2462
2846
 
2463
2847
  const checkMeetingInfoUpdatedCalled = (expected, payload) => {
2464
2848
  const expectedArgs = [
@@ -2503,6 +2887,10 @@ describe('plugin-meetings', () => {
2503
2887
 
2504
2888
  let expectedMeeting;
2505
2889
 
2890
+ // simulate that updateSelf has been called previously (as happens in production)
2891
+ // so that parsedLocus.self reflects the joined state
2892
+ locusInfo.parsedLocus.self = {state: 'JOINED'};
2893
+
2506
2894
  /*
2507
2895
  When the event is triggered, it is required that the meeting has already
2508
2896
  been updated. This is why the meeting is being checked within the stubbed event emitter
@@ -2513,6 +2901,7 @@ describe('plugin-meetings', () => {
2513
2901
 
2514
2902
  // set the info initially as locusInfo.info starts as undefined
2515
2903
  expectedMeeting = {
2904
+ attendee: {},
2516
2905
  coHost: {
2517
2906
  LOWER_SOMEONE_ELSES_HAND: true,
2518
2907
  },
@@ -2521,10 +2910,12 @@ describe('plugin-meetings', () => {
2521
2910
  moderator: {
2522
2911
  LOWER_SOMEONE_ELSES_HAND: true,
2523
2912
  },
2913
+ panelist: {},
2524
2914
  policy: {
2525
2915
  LOCK_STATUS_UNLOCKED: true,
2526
2916
  ROSTER_IN_MEETING: true,
2527
2917
  },
2918
+ presenter: {},
2528
2919
  userDisplayHints: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED'],
2529
2920
  };
2530
2921
  locusInfo.updateMeetingInfo(initialInfo, self);
@@ -2539,6 +2930,7 @@ describe('plugin-meetings', () => {
2539
2930
 
2540
2931
  // Updating with different info should trigger the event
2541
2932
  expectedMeeting = {
2933
+ attendee: {},
2542
2934
  coHost: {
2543
2935
  LOWER_SOMEONE_ELSES_HAND: true,
2544
2936
  LOCK_CONTROL_LOCK: true,
@@ -2548,10 +2940,12 @@ describe('plugin-meetings', () => {
2548
2940
  moderator: {
2549
2941
  LOWER_SOMEONE_ELSES_HAND: true,
2550
2942
  },
2943
+ panelist: {},
2551
2944
  policy: {
2552
2945
  LOCK_STATUS_UNLOCKED: true,
2553
2946
  ROSTER_IN_MEETING: true,
2554
2947
  },
2948
+ presenter: {},
2555
2949
  userDisplayHints: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED'],
2556
2950
  };
2557
2951
  locusInfo.updateMeetingInfo(newInfo, self);
@@ -2560,6 +2954,7 @@ describe('plugin-meetings', () => {
2560
2954
 
2561
2955
  // update it with the same info
2562
2956
  expectedMeeting = {
2957
+ attendee: {},
2563
2958
  coHost: {
2564
2959
  LOWER_SOMEONE_ELSES_HAND: true,
2565
2960
  LOCK_CONTROL_LOCK: true,
@@ -2569,10 +2964,12 @@ describe('plugin-meetings', () => {
2569
2964
  moderator: {
2570
2965
  LOWER_SOMEONE_ELSES_HAND: true,
2571
2966
  },
2967
+ panelist: {},
2572
2968
  policy: {
2573
2969
  LOCK_STATUS_UNLOCKED: true,
2574
2970
  ROSTER_IN_MEETING: true,
2575
2971
  },
2972
+ presenter: {},
2576
2973
  userDisplayHints: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED'],
2577
2974
  };
2578
2975
  locusInfo.updateMeetingInfo(newInfo, self);
@@ -2587,6 +2984,7 @@ describe('plugin-meetings', () => {
2587
2984
  hasRole: true,
2588
2985
  });
2589
2986
  expectedMeeting = {
2987
+ attendee: {},
2590
2988
  coHost: {
2591
2989
  LOWER_SOMEONE_ELSES_HAND: true,
2592
2990
  LOCK_CONTROL_LOCK: true,
@@ -2596,10 +2994,12 @@ describe('plugin-meetings', () => {
2596
2994
  moderator: {
2597
2995
  LOWER_SOMEONE_ELSES_HAND: true,
2598
2996
  },
2997
+ panelist: {},
2599
2998
  policy: {
2600
2999
  LOCK_STATUS_UNLOCKED: true,
2601
3000
  ROSTER_IN_MEETING: true,
2602
3001
  },
3002
+ presenter: {},
2603
3003
  userDisplayHints: [
2604
3004
  'ROSTER_IN_MEETING',
2605
3005
  'LOCK_STATUS_UNLOCKED',
@@ -2642,6 +3042,46 @@ describe('plugin-meetings', () => {
2642
3042
  // since self is not passed to updateMeetingInfo, MEETING_INFO_UPDATED should be triggered with isIntializing: true
2643
3043
  checkMeetingInfoUpdatedCalledForRoles(true, {isInitializing: true});
2644
3044
  });
3045
+
3046
+ // joined-section hints (like ROSTER_IN_MEETING) are filtered out while not joined, so they
3047
+ // are a good proxy for verifying that userDisplayHints get recomputed on a join transition
3048
+ [
3049
+ {
3050
+ name: 'the JOINED delta carries the info section',
3051
+ getSecondInfo: (info) => info,
3052
+ },
3053
+ {
3054
+ name: 'the JOINED delta omits the info section (falls back to stored info)',
3055
+ getSecondInfo: () => undefined,
3056
+ },
3057
+ ].forEach(({name, getSecondInfo}) => {
3058
+ it(`recomputes userDisplayHints when self transitions to JOINED with unchanged roles and ${name}`, () => {
3059
+ const info = cloneDeep(meetingInfo); // joined: ['ROSTER_IN_MEETING', 'LOCK_STATUS_UNLOCKED']
3060
+
3061
+ const notJoinedSelf = cloneDeep(self);
3062
+ notJoinedSelf.state = 'IDLE';
3063
+ notJoinedSelf.controls.role.roles = [];
3064
+
3065
+ const joinedSelf = cloneDeep(self);
3066
+ joinedSelf.state = 'JOINED';
3067
+ joinedSelf.controls.role.roles = [];
3068
+
3069
+ sinon.stub(locusInfo, 'emitScoped');
3070
+
3071
+ // first update while not joined: joined-section hints are filtered out
3072
+ locusInfo.updateMeetingInfo(info, notJoinedSelf);
3073
+ assert.notInclude(locusInfo.parsedLocus.info.userDisplayHints, 'ROSTER_IN_MEETING');
3074
+ assert.notInclude(locusInfo.parsedLocus.info.userDisplayHints, 'LOCK_STATUS_UNLOCKED');
3075
+
3076
+ // self transitions to JOINED - info and roles are unchanged
3077
+ locusInfo.updateMeetingInfo(getSecondInfo(info), joinedSelf);
3078
+
3079
+ // the hints must be recomputed with the new joined state
3080
+ assert.include(locusInfo.parsedLocus.info.userDisplayHints, 'ROSTER_IN_MEETING');
3081
+ assert.include(locusInfo.parsedLocus.info.userDisplayHints, 'LOCK_STATUS_UNLOCKED');
3082
+ checkMeetingInfoUpdatedCalled(true, {isInitializing: false});
3083
+ });
3084
+ });
2645
3085
  });
2646
3086
 
2647
3087
  describe('#updateMediaShares', () => {
@@ -2835,40 +3275,620 @@ describe('plugin-meetings', () => {
2835
3275
  });
2836
3276
  });
2837
3277
 
2838
- describe('#handleLocusAPIResponse', () => {
2839
- it('calls handleLocusDelta when we are not using hash trees', () => {
2840
- const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE};
2841
-
2842
- sinon.stub(locusInfo, 'handleLocusDelta');
2843
-
2844
- locusInfo.handleLocusAPIResponse(mockMeeting, {locus: fakeLocus});
3278
+ describe('#createHashTreeParser', () => {
3279
+ let HashTreeParserStub;
2845
3280
 
2846
- assert.calledWith(locusInfo.handleLocusDelta, fakeLocus, mockMeeting);
3281
+ beforeEach(() => {
3282
+ HashTreeParserStub = sinon
3283
+ .stub(HashTreeParserModule, 'default')
3284
+ .returns({
3285
+ initializeFromMessage: sinon.stub().resolves(),
3286
+ initializeFromGetLociResponse: sinon.stub().resolves(),
3287
+ state: 'active',
3288
+ stop: sinon.stub(),
3289
+ handleMessage: sinon.stub(),
3290
+ });
2847
3291
  });
2848
- it('calls hash tree parser when we are using hash trees', () => {
2849
- const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE};
2850
- const fakeDataSets = [{name: 'dataset1', url: 'http://test.com'}];
2851
- const responseBody = {locus: fakeLocus, dataSets: fakeDataSets};
2852
3292
 
2853
- // Create a mock hash tree parser
2854
- const mockHashTreeParser = {
2855
- handleLocusUpdate: sinon.stub(),
2856
- };
2857
- locusInfo.hashTreeParser = mockHashTreeParser;
3293
+ const setupParserViaInitialSetup = async (locusUrl = 'http://locus-url-A.com') => {
3294
+ await locusInfo.initialSetup({
3295
+ trigger: 'locus-message',
3296
+ hashTreeMessage: {
3297
+ locusUrl,
3298
+ locusStateElements: [
3299
+ {
3300
+ htMeta: {elementId: {type: 'Metadata'}},
3301
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
3302
+ },
3303
+ ],
3304
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3305
+ },
3306
+ });
3307
+ };
2858
3308
 
2859
- sinon.stub(locusInfo, 'onDeltaLocus');
3309
+ it('should stop existing active parsers when creating a new one', async () => {
3310
+ await setupParserViaInitialSetup('http://locus-url-A.com');
2860
3311
 
2861
- locusInfo.handleLocusAPIResponse(mockMeeting, responseBody);
3312
+ const firstParser = locusInfo.hashTreeParsers.get('http://locus-url-A.com').parser;
2862
3313
 
2863
- assert.calledOnceWithExactly(mockHashTreeParser.handleLocusUpdate, responseBody);
3314
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3315
+
3316
+ assert.calledOnce(firstParser.stop);
2864
3317
  });
2865
- });
2866
3318
 
2867
- describe('#LocusDeltaEvents', () => {
2868
- const fakeMeeting = 'fakeMeeting';
2869
- let sandbox = null;
2870
- let locusParser = null;
2871
- let fakeLocus = null;
3319
+ it('should set replacedAt on existing entries when replacedAt is provided', async () => {
3320
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3321
+
3322
+ // Call createHashTreeParser with replacedAt via parse -> handleHashTreeParserSwitch
3323
+ // which calls createHashTreeParser with replacedAt from the self element
3324
+ locusInfo.webex.internal.device.url = 'http://device-url.com';
3325
+ const message = {
3326
+ locusUrl: 'http://locus-url-B.com',
3327
+ locusStateElements: [
3328
+ {
3329
+ htMeta: {elementId: {type: 'Metadata'}},
3330
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
3331
+ },
3332
+ {
3333
+ htMeta: {elementId: {type: 'Self'}},
3334
+ data: {
3335
+ devices: [{url: 'http://device-url.com', replaces: [{locusUrl: 'http://locus-url-A.com', replacedAt: '2026-01-01T00:00:00Z'}]}],
3336
+ },
3337
+ },
3338
+ ],
3339
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3340
+ };
3341
+
3342
+ locusInfo.parse(mockMeeting, {
3343
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3344
+ stateElementsMessage: message,
3345
+ });
3346
+
3347
+ assert.equal(locusInfo.hashTreeParsers.get('http://locus-url-A.com').replacedAt, '2026-01-01T00:00:00Z');
3348
+ });
3349
+
3350
+ it('should not set replacedAt on existing entries when replacedAt is not provided', async () => {
3351
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3352
+
3353
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3354
+
3355
+ assert.isUndefined(locusInfo.hashTreeParsers.get('http://locus-url-A.com').replacedAt);
3356
+ });
3357
+
3358
+ it('should store the new parser in hashTreeParsers map with the correct locusUrl key', async () => {
3359
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3360
+
3361
+ assert.isTrue(locusInfo.hashTreeParsers.has('http://locus-url-A.com'));
3362
+ assert.isDefined(locusInfo.hashTreeParsers.get('http://locus-url-A.com').parser);
3363
+ });
3364
+
3365
+ it('should clear hashTreeObjectId2ParticipantId when creating a new parser', async () => {
3366
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3367
+ locusInfo.hashTreeObjectId2ParticipantId.set(1, 'participant-1');
3368
+
3369
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3370
+
3371
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.size, 0);
3372
+ });
3373
+
3374
+ it('should not stop already stopped parsers', async () => {
3375
+ await setupParserViaInitialSetup('http://locus-url-A.com');
3376
+ const firstParser = locusInfo.hashTreeParsers.get('http://locus-url-A.com').parser;
3377
+ firstParser.state = 'stopped';
3378
+
3379
+ await setupParserViaInitialSetup('http://locus-url-B.com');
3380
+
3381
+ assert.notCalled(firstParser.stop);
3382
+ });
3383
+ });
3384
+
3385
+ describe('#handleHashTreeParserSwitch', () => {
3386
+ const deviceUrl = 'http://device-url.com';
3387
+ const locusUrlA = 'http://locus-url-A.com';
3388
+ const locusUrlB = 'http://locus-url-B.com';
3389
+
3390
+ let HashTreeParserStub;
3391
+
3392
+ const createMockParser = (state = 'active') => ({
3393
+ state,
3394
+ stop: sinon.stub(),
3395
+ resumeFromMessage: sinon.stub(),
3396
+ handleMessage: sinon.stub(),
3397
+ });
3398
+
3399
+ const createSelfElementWithReplaces = (replacedLocusUrl, replacedAt) => ({
3400
+ htMeta: {elementId: {type: 'Self'}},
3401
+ data: {
3402
+ deviceUrl,
3403
+ devices: [{url: deviceUrl, replaces: [{locusUrl: replacedLocusUrl, replacedAt}]}],
3404
+ },
3405
+ });
3406
+
3407
+ const createMetadataElement = () => ({
3408
+ htMeta: {elementId: {type: 'Metadata'}},
3409
+ data: {visibleDataSets: [{name: 'dataset1', url: 'test-url'}]},
3410
+ });
3411
+
3412
+ beforeEach(() => {
3413
+ locusInfo.webex.internal.device.url = deviceUrl;
3414
+ HashTreeParserStub = sinon
3415
+ .stub(HashTreeParserModule, 'default')
3416
+ .returns(createMockParser());
3417
+ });
3418
+
3419
+ it('should create a new parser when no entry exists for locusUrl and metadata has visibleDataSets', () => {
3420
+ // set up an existing parser for a different url
3421
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockParser(), initializedFromHashTree: true});
3422
+
3423
+ const message = {
3424
+ locusUrl: locusUrlB,
3425
+ locusStateElements: [createMetadataElement()],
3426
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3427
+ };
3428
+
3429
+ locusInfo.parse(mockMeeting, {
3430
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3431
+ stateElementsMessage: message,
3432
+ });
3433
+
3434
+ assert.isTrue(locusInfo.hashTreeParsers.has(locusUrlB));
3435
+ });
3436
+
3437
+ it('should return true when no entry exists even if no metadata is available', () => {
3438
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockParser(), initializedFromHashTree: true});
3439
+ const parserA = locusInfo.hashTreeParsers.get(locusUrlA).parser;
3440
+
3441
+ const message = {
3442
+ locusUrl: locusUrlB,
3443
+ locusStateElements: [],
3444
+ dataSets: [],
3445
+ };
3446
+
3447
+ locusInfo.parse(mockMeeting, {
3448
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3449
+ stateElementsMessage: message,
3450
+ });
3451
+
3452
+ // no new parser created since no metadata
3453
+ assert.isFalse(locusInfo.hashTreeParsers.has(locusUrlB));
3454
+ // the existing parser's handleMessage should NOT have been called
3455
+ assert.notCalled(parserA.handleMessage);
3456
+ });
3457
+
3458
+ it('should resume a stopped parser when replaces info is newer', () => {
3459
+ const parserA = createMockParser('stopped');
3460
+ const parserB = createMockParser('active');
3461
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-01-01T00:00:00Z', initializedFromHashTree: true});
3462
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3463
+
3464
+ const message = {
3465
+ locusUrl: locusUrlA,
3466
+ locusStateElements: [
3467
+ createSelfElementWithReplaces(locusUrlB, '2026-02-01T00:00:00Z'),
3468
+ createMetadataElement(),
3469
+ ],
3470
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3471
+ };
3472
+
3473
+ locusInfo.parse(mockMeeting, {
3474
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3475
+ stateElementsMessage: message,
3476
+ });
3477
+
3478
+ assert.calledOnce(parserA.resumeFromMessage);
3479
+ assert.calledOnce(parserB.stop);
3480
+ });
3481
+
3482
+ it('should not resume a stopped parser when replaces info is not newer', () => {
3483
+ const parserA = createMockParser('stopped');
3484
+ const parserB = createMockParser('active');
3485
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-03-01T00:00:00Z', initializedFromHashTree: true});
3486
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3487
+
3488
+ const message = {
3489
+ locusUrl: locusUrlA,
3490
+ locusStateElements: [
3491
+ createSelfElementWithReplaces(locusUrlB, '2026-01-01T00:00:00Z'),
3492
+ ],
3493
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3494
+ };
3495
+
3496
+ locusInfo.parse(mockMeeting, {
3497
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3498
+ stateElementsMessage: message,
3499
+ });
3500
+
3501
+ assert.notCalled(parserA.resumeFromMessage);
3502
+ assert.notCalled(parserB.stop);
3503
+ });
3504
+
3505
+ it('should return true for a stopped parser with no replaces info', () => {
3506
+ const parserA = createMockParser('stopped');
3507
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3508
+
3509
+ const message = {
3510
+ locusUrl: locusUrlA,
3511
+ locusStateElements: [],
3512
+ dataSets: [],
3513
+ };
3514
+
3515
+ locusInfo.parse(mockMeeting, {
3516
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3517
+ stateElementsMessage: message,
3518
+ });
3519
+
3520
+ assert.notCalled(parserA.resumeFromMessage);
3521
+ assert.notCalled(parserA.handleMessage);
3522
+ });
3523
+
3524
+ it('should return false when the entry exists and parser is active', () => {
3525
+ const parserA = createMockParser('active');
3526
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3527
+
3528
+ const message = {
3529
+ locusUrl: locusUrlA,
3530
+ locusStateElements: [],
3531
+ dataSets: [],
3532
+ };
3533
+
3534
+ locusInfo.parse(mockMeeting, {
3535
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3536
+ stateElementsMessage: message,
3537
+ });
3538
+
3539
+ assert.calledOnceWithExactly(parserA.handleMessage, message);
3540
+ });
3541
+
3542
+ it('should pass replacedAt from replaces to createHashTreeParser when creating a new parser', () => {
3543
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockParser(), initializedFromHashTree: true});
3544
+
3545
+ const message = {
3546
+ locusUrl: locusUrlB,
3547
+ locusStateElements: [
3548
+ createMetadataElement(),
3549
+ createSelfElementWithReplaces(locusUrlA, '2026-05-01T00:00:00Z'),
3550
+ ],
3551
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3552
+ };
3553
+
3554
+ locusInfo.parse(mockMeeting, {
3555
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3556
+ stateElementsMessage: message,
3557
+ });
3558
+
3559
+ assert.isTrue(locusInfo.hashTreeParsers.has(locusUrlB));
3560
+ assert.equal(locusInfo.hashTreeParsers.get(locusUrlA).replacedAt, '2026-05-01T00:00:00Z');
3561
+ });
3562
+ });
3563
+
3564
+ describe('#handleHashTreeMessage', () => {
3565
+ it('should call handleHashTreeParserSwitch and not call handleMessage if parser was switched', () => {
3566
+ const locusUrlA = 'http://locus-url-A.com';
3567
+ const locusUrlB = 'http://locus-url-B.com';
3568
+ const parserA = {state: 'stopped', handleMessage: sinon.stub(), resume: sinon.stub(), stop: sinon.stub()};
3569
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3570
+
3571
+ // message for a stopped parser without replaces -> handleHashTreeParserSwitch returns true
3572
+ const message = {
3573
+ locusUrl: locusUrlA,
3574
+ locusStateElements: [],
3575
+ dataSets: [],
3576
+ };
3577
+
3578
+ locusInfo.parse(mockMeeting, {
3579
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3580
+ stateElementsMessage: message,
3581
+ });
3582
+
3583
+ assert.notCalled(parserA.handleMessage);
3584
+ });
3585
+
3586
+ it('should call handleMessage on the correct parser when no switch occurs', () => {
3587
+ const locusUrlA = 'http://locus-url-A.com';
3588
+ const parserA = {state: 'active', handleMessage: sinon.stub()};
3589
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3590
+
3591
+ const message = {
3592
+ locusUrl: locusUrlA,
3593
+ locusStateElements: [],
3594
+ dataSets: [],
3595
+ };
3596
+
3597
+ locusInfo.parse(mockMeeting, {
3598
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
3599
+ stateElementsMessage: message,
3600
+ });
3601
+
3602
+ assert.calledOnceWithExactly(parserA.handleMessage, message);
3603
+ });
3604
+
3605
+ it('should send mismatch metric when eventType is not HASH_TREE_DATA_UPDATED', () => {
3606
+ const locusUrlA = 'http://locus-url-A.com';
3607
+ const parserA = {state: 'active', handleMessage: sinon.stub()};
3608
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3609
+
3610
+ locusInfo.parse(mockMeeting, {
3611
+ eventType: LOCUSEVENT.SELF_CHANGED,
3612
+ stateElementsMessage: {locusUrl: locusUrlA, locusStateElements: [], dataSets: []},
3613
+ });
3614
+
3615
+ assert.calledOnceWithExactly(
3616
+ sendBehavioralMetricStub,
3617
+ 'js_sdk_locus_classic_vs_hash_tree_mismatch',
3618
+ {
3619
+ correlationId: mockMeeting.correlationId,
3620
+ message: `got ${LOCUSEVENT.SELF_CHANGED}, expected ${LOCUSEVENT.HASH_TREE_DATA_UPDATED}`,
3621
+ }
3622
+ );
3623
+ assert.notCalled(parserA.handleMessage);
3624
+ });
3625
+ });
3626
+
3627
+ describe('#sendClassicVsHashTreeMismatchMetric', () => {
3628
+ it('should send the metric when called for the first time', () => {
3629
+ locusInfo.sendClassicVsHashTreeMismatchMetric(mockMeeting, 'some mismatch');
3630
+
3631
+ assert.calledOnceWithExactly(
3632
+ sendBehavioralMetricStub,
3633
+ 'js_sdk_locus_classic_vs_hash_tree_mismatch',
3634
+ {
3635
+ correlationId: mockMeeting.correlationId,
3636
+ message: 'some mismatch',
3637
+ }
3638
+ );
3639
+ });
3640
+
3641
+ it('should send the metric up to 5 times and stop after that', () => {
3642
+ for (let i = 0; i < 7; i += 1) {
3643
+ locusInfo.sendClassicVsHashTreeMismatchMetric(mockMeeting, `mismatch ${i}`);
3644
+ }
3645
+
3646
+ assert.callCount(sendBehavioralMetricStub, 5);
3647
+ assert.equal(locusInfo.classicVsHashTreeMismatchMetricCounter, 5);
3648
+ });
3649
+ });
3650
+
3651
+ describe('#handleLocusAPIResponse', () => {
3652
+ it('calls handleLocusDelta when we are not using hash trees', () => {
3653
+ const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE};
3654
+
3655
+ sinon.stub(locusInfo, 'handleLocusDelta');
3656
+
3657
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus: fakeLocus});
3658
+
3659
+ assert.calledWith(locusInfo.handleLocusDelta, fakeLocus, mockMeeting);
3660
+ });
3661
+ it('calls hash tree parser when we are using hash trees', () => {
3662
+ const fakeLocus = {eventType: LOCUSEVENT.DIFFERENCE, url: 'http://locus-url.com'};
3663
+ const fakeDataSets = [{name: 'dataset1', url: 'http://test.com'}];
3664
+ const responseBody = {locus: fakeLocus, dataSets: fakeDataSets};
3665
+
3666
+ // Create a mock hash tree parser
3667
+ const mockHashTreeParser = {
3668
+ handleLocusUpdate: sinon.stub(),
3669
+ };
3670
+ locusInfo.hashTreeParsers.set(fakeLocus.url, {
3671
+ parser: mockHashTreeParser,
3672
+ initializedFromHashTree: true,
3673
+ });
3674
+
3675
+ sinon.stub(locusInfo, 'onDeltaLocus');
3676
+
3677
+ locusInfo.handleLocusAPIResponse(mockMeeting, responseBody);
3678
+
3679
+ assert.calledOnceWithExactly(mockHashTreeParser.handleLocusUpdate, responseBody);
3680
+ });
3681
+
3682
+ it('should handle unwrapped LocusDTO (without locus wrapper) when hash tree parser exists', () => {
3683
+ const fakeLocus = {url: 'http://locus-url.com', fullState: {state: 'ACTIVE'}};
3684
+ const mockHashTreeParser = {handleLocusUpdate: sinon.stub()};
3685
+ locusInfo.hashTreeParsers.set(fakeLocus.url, {
3686
+ parser: mockHashTreeParser,
3687
+ initializedFromHashTree: true,
3688
+ });
3689
+
3690
+ locusInfo.handleLocusAPIResponse(mockMeeting, fakeLocus);
3691
+
3692
+ assert.calledOnceWithExactly(mockHashTreeParser.handleLocusUpdate, {locus: fakeLocus});
3693
+ });
3694
+
3695
+ it('should handle unwrapped LocusDTO in classic mode (no hash tree parser)', () => {
3696
+ const fakeLocus = {url: 'http://locus-url.com', fullState: {state: 'ACTIVE'}};
3697
+ sinon.stub(locusInfo, 'handleLocusDelta');
3698
+
3699
+ locusInfo.handleLocusAPIResponse(mockMeeting, fakeLocus);
3700
+
3701
+ assert.calledOnceWithExactly(locusInfo.handleLocusDelta, fakeLocus, mockMeeting);
3702
+ });
3703
+
3704
+ it('should send mismatch metric in classic mode when wrapped response has dataSets', () => {
3705
+ const fakeLocus = {url: 'http://locus-url.com'};
3706
+ sinon.stub(locusInfo, 'handleLocusDelta');
3707
+
3708
+ locusInfo.handleLocusAPIResponse(mockMeeting, {
3709
+ locus: fakeLocus,
3710
+ dataSets: [{name: 'dataset1', url: 'test-url'}],
3711
+ });
3712
+
3713
+ assert.calledOnceWithExactly(
3714
+ sendBehavioralMetricStub,
3715
+ 'js_sdk_locus_classic_vs_hash_tree_mismatch',
3716
+ {
3717
+ correlationId: mockMeeting.correlationId,
3718
+ message: 'unexpected hash tree dataSets in API response',
3719
+ }
3720
+ );
3721
+ assert.calledOnce(locusInfo.handleLocusDelta);
3722
+ });
3723
+
3724
+ describe('parser switch via API response', () => {
3725
+ const deviceUrl = 'http://device-url.com';
3726
+ const locusUrlA = 'http://locus-url-A.com';
3727
+ const locusUrlB = 'http://locus-url-B.com';
3728
+
3729
+ let HashTreeParserStub;
3730
+
3731
+ const createMockApiParser = (state = 'active') => ({
3732
+ state,
3733
+ stop: sinon.stub(),
3734
+ resumeFromApiResponse: sinon.stub(),
3735
+ handleLocusUpdate: sinon.stub(),
3736
+ initializeFromGetLociResponse: sinon.stub(),
3737
+ });
3738
+
3739
+ const createLocusWithReplaces = (url, replacedLocusUrl, replacedAt) => ({
3740
+ url,
3741
+ self: {
3742
+ devices: [{url: deviceUrl, replaces: [{locusUrl: replacedLocusUrl, replacedAt}]}],
3743
+ },
3744
+ });
3745
+
3746
+ const createLocusWithoutReplaces = (url) => ({
3747
+ url,
3748
+ self: {devices: [{url: deviceUrl}]},
3749
+ });
3750
+
3751
+ beforeEach(() => {
3752
+ locusInfo.webex.internal.device.url = deviceUrl;
3753
+ HashTreeParserStub = sinon
3754
+ .stub(HashTreeParserModule, 'default')
3755
+ .returns(createMockApiParser());
3756
+ });
3757
+
3758
+ it('should create a new parser and initialize it when no entry exists for the locusUrl', () => {
3759
+ // existing parser for a different url so hashTreeParsers.size > 0
3760
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: createMockApiParser(), initializedFromHashTree: true});
3761
+
3762
+ const locus = createLocusWithReplaces(locusUrlB, locusUrlA, '2026-01-01T00:00:00Z');
3763
+ sinon.stub(locusInfo, 'handleLocusDelta');
3764
+
3765
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3766
+
3767
+ assert.isTrue(locusInfo.hashTreeParsers.has(locusUrlB));
3768
+ const newEntry = locusInfo.hashTreeParsers.get(locusUrlB);
3769
+ assert.isFalse(newEntry.initializedFromHashTree);
3770
+
3771
+ // the stub returns the mock, so initializeFromGetLociResponse should be called on it
3772
+ const createdParser = HashTreeParserStub.returnValues[0];
3773
+ assert.calledOnceWithExactly(createdParser.initializeFromGetLociResponse, locus);
3774
+ assert.notCalled(locusInfo.handleLocusDelta);
3775
+ });
3776
+
3777
+ it('should reactivate a stopped parser when replaces info is newer', () => {
3778
+ const parserA = createMockApiParser('stopped');
3779
+ const parserB = createMockApiParser('active');
3780
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-01-01T00:00:00Z', initializedFromHashTree: true});
3781
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3782
+
3783
+ const locus = createLocusWithReplaces(locusUrlA, locusUrlB, '2026-02-01T00:00:00Z');
3784
+
3785
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3786
+
3787
+ assert.calledOnce(parserA.resumeFromApiResponse);
3788
+ assert.calledWithExactly(parserA.resumeFromApiResponse, locus);
3789
+ assert.calledOnce(parserB.stop);
3790
+ assert.equal(locusInfo.hashTreeParsers.get(locusUrlB).replacedAt, '2026-02-01T00:00:00Z');
3791
+ assert.isFalse(locusInfo.hashTreeParsers.get(locusUrlA).initializedFromHashTree);
3792
+ });
3793
+
3794
+ it('should not reactivate a stopped parser when replaces info is not newer', () => {
3795
+ const parserA = createMockApiParser('stopped');
3796
+ const parserB = createMockApiParser('active');
3797
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, replacedAt: '2026-03-01T00:00:00Z', initializedFromHashTree: true});
3798
+ locusInfo.hashTreeParsers.set(locusUrlB, {parser: parserB, initializedFromHashTree: true});
3799
+
3800
+ const locus = createLocusWithReplaces(locusUrlA, locusUrlB, '2026-01-01T00:00:00Z');
3801
+
3802
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3803
+
3804
+ assert.notCalled(parserA.resumeFromApiResponse);
3805
+ assert.notCalled(parserB.stop);
3806
+ });
3807
+
3808
+ it('should not reactivate a stopped parser when no replaces info is available', () => {
3809
+ const parserA = createMockApiParser('stopped');
3810
+ locusInfo.hashTreeParsers.set(locusUrlA, {parser: parserA, initializedFromHashTree: true});
3811
+
3812
+ const locus = createLocusWithoutReplaces(locusUrlA);
3813
+
3814
+ locusInfo.handleLocusAPIResponse(mockMeeting, {locus});
3815
+
3816
+ assert.notCalled(parserA.resumeFromApiResponse);
3817
+ });
3818
+ });
3819
+ });
3820
+
3821
+ describe('#syncAllHashTreeDatasets', () => {
3822
+ it('should call syncAllDatasets on each parser that has an entry', async () => {
3823
+ const parser1 = {syncAllDatasets: sinon.stub().resolves()};
3824
+ const parser2 = {syncAllDatasets: sinon.stub().resolves()};
3825
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3826
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2});
3827
+
3828
+ await locusInfo.syncAllHashTreeDatasets();
3829
+
3830
+ assert.calledOnce(parser1.syncAllDatasets);
3831
+ assert.calledOnce(parser2.syncAllDatasets);
3832
+ });
3833
+
3834
+ it('should skip parser entries without a parser object', async () => {
3835
+ const parser1 = {syncAllDatasets: sinon.stub().resolves()};
3836
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3837
+ locusInfo.hashTreeParsers.set('url2', {parser: undefined});
3838
+
3839
+ await locusInfo.syncAllHashTreeDatasets();
3840
+
3841
+ assert.calledOnce(parser1.syncAllDatasets);
3842
+ });
3843
+
3844
+ it('should forward options to each parser syncAllDatasets', async () => {
3845
+ const parser1 = {syncAllDatasets: sinon.stub().resolves()};
3846
+ const parser2 = {syncAllDatasets: sinon.stub().resolves()};
3847
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3848
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2});
3849
+
3850
+ await locusInfo.syncAllHashTreeDatasets({onlyLLM: true});
3851
+
3852
+ assert.calledOnceWithExactly(parser1.syncAllDatasets, {onlyLLM: true});
3853
+ assert.calledOnceWithExactly(parser2.syncAllDatasets, {onlyLLM: true});
3854
+ });
3855
+
3856
+ it('should await each parsers syncAllDatasets sequentially', async () => {
3857
+ const callOrder = [];
3858
+ const parser1 = {syncAllDatasets: sinon.stub().callsFake(() => {
3859
+ callOrder.push('start1');
3860
+ return new Promise((resolve) => {
3861
+ setTimeout(() => {
3862
+ callOrder.push('end1');
3863
+ resolve();
3864
+ }, 100);
3865
+ });
3866
+ })};
3867
+ const parser2 = {syncAllDatasets: sinon.stub().callsFake(() => {
3868
+ callOrder.push('start2');
3869
+ return Promise.resolve();
3870
+ })};
3871
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1});
3872
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2});
3873
+
3874
+ const clock = sinon.useFakeTimers();
3875
+ const promise = locusInfo.syncAllHashTreeDatasets();
3876
+ // parser1 started but parser2 not yet
3877
+ assert.deepEqual(callOrder, ['start1']);
3878
+
3879
+ await clock.tickAsync(100);
3880
+ await promise;
3881
+ // parser1 finished, then parser2 started and finished
3882
+ assert.deepEqual(callOrder, ['start1', 'end1', 'start2']);
3883
+ clock.restore();
3884
+ });
3885
+ });
3886
+
3887
+ describe('#LocusDeltaEvents', () => {
3888
+ const fakeMeeting = 'fakeMeeting';
3889
+ let sandbox = null;
3890
+ let locusParser = null;
3891
+ let fakeLocus = null;
2872
3892
 
2873
3893
  beforeEach(() => {
2874
3894
  locusParser = locusInfo.locusParser;
@@ -2923,28 +3943,28 @@ describe('plugin-meetings', () => {
2923
3943
  assert.isFunction(locusParser.onDeltaAction);
2924
3944
  });
2925
3945
 
2926
- it("#updateLocusInfo invokes updateLocusUrl before updateMeetingInfo", () => {
3946
+ it('#updateLocusInfo invokes updateLocusUrl before updateMeetingInfo', () => {
2927
3947
  const callOrder = [];
2928
- sinon.stub(locusInfo, "updateControls");
2929
- sinon.stub(locusInfo, "updateConversationUrl");
2930
- sinon.stub(locusInfo, "updateCreated");
2931
- sinon.stub(locusInfo, "updateFullState");
2932
- sinon.stub(locusInfo, "updateHostInfo");
2933
- sinon.stub(locusInfo, "updateMeetingInfo").callsFake(() => {
2934
- callOrder.push("updateMeetingInfo");
3948
+ sinon.stub(locusInfo, 'updateControls');
3949
+ sinon.stub(locusInfo, 'updateConversationUrl');
3950
+ sinon.stub(locusInfo, 'updateCreated');
3951
+ sinon.stub(locusInfo, 'updateFullState');
3952
+ sinon.stub(locusInfo, 'updateHostInfo');
3953
+ sinon.stub(locusInfo, 'updateMeetingInfo').callsFake(() => {
3954
+ callOrder.push('updateMeetingInfo');
2935
3955
  });
2936
- sinon.stub(locusInfo, "updateMediaShares");
2937
- sinon.stub(locusInfo, "updateReplaces");
2938
- sinon.stub(locusInfo, "updateSelf");
2939
- sinon.stub(locusInfo, "updateLocusUrl").callsFake(() => {
2940
- callOrder.push("updateLocusUrl");
3956
+ sinon.stub(locusInfo, 'updateMediaShares');
3957
+ sinon.stub(locusInfo, 'updateReplaces');
3958
+ sinon.stub(locusInfo, 'updateSelf');
3959
+ sinon.stub(locusInfo, 'updateLocusUrl').callsFake(() => {
3960
+ callOrder.push('updateLocusUrl');
2941
3961
  });
2942
- sinon.stub(locusInfo, "updateAclUrl");
2943
- sinon.stub(locusInfo, "updateBasequence");
2944
- sinon.stub(locusInfo, "updateSequence");
2945
- sinon.stub(locusInfo, "updateEmbeddedApps");
2946
- sinon.stub(locusInfo, "updateLinks");
2947
- sinon.stub(locusInfo, "compareAndUpdate");
3962
+ sinon.stub(locusInfo, 'updateAclUrl');
3963
+ sinon.stub(locusInfo, 'updateBasequence');
3964
+ sinon.stub(locusInfo, 'updateSequence');
3965
+ sinon.stub(locusInfo, 'updateEmbeddedApps');
3966
+ sinon.stub(locusInfo, 'updateLinks');
3967
+ sinon.stub(locusInfo, 'compareAndUpdate');
2948
3968
 
2949
3969
  locusInfo.updateLocusInfo(locus);
2950
3970
 
@@ -2952,55 +3972,29 @@ describe('plugin-meetings', () => {
2952
3972
  assert.deepEqual(callOrder, ['updateLocusUrl', 'updateMeetingInfo']);
2953
3973
  });
2954
3974
 
2955
- it('#updateLocusInfo ignores breakout LEFT message', () => {
2956
- const newLocus = {
2957
- self: {
2958
- reason: 'MOVED',
2959
- state: 'LEFT',
2960
- },
2961
- };
3975
+ it('#updateLocusInfo ignores locus when isSelfMovedOrBreakoutEnded returns true', () => {
3976
+ const newLocus = {self: {state: 'JOINED'}};
3977
+
3978
+ sinon.stub(MeetingsUtil, 'isSelfMovedOrBreakoutEnded').returns(true);
2962
3979
 
2963
3980
  locusInfo.updateControls = sinon.stub();
2964
- locusInfo.updateConversationUrl = sinon.stub();
2965
- locusInfo.updateCreated = sinon.stub();
2966
3981
  locusInfo.updateFullState = sinon.stub();
2967
- locusInfo.updateHostInfo = sinon.stub();
2968
- locusInfo.updateMeetingInfo = sinon.stub();
2969
- locusInfo.updateMediaShares = sinon.stub();
2970
- locusInfo.updateReplaces = sinon.stub();
2971
3982
  locusInfo.updateSelf = sinon.stub();
2972
- locusInfo.updateLocusUrl = sinon.stub();
2973
- locusInfo.updateAclUrl = sinon.stub();
2974
- locusInfo.updateBasequence = sinon.stub();
2975
- locusInfo.updateSequence = sinon.stub();
2976
- locusInfo.updateEmbeddedApps = sinon.stub();
2977
- locusInfo.updateLinks = sinon.stub();
2978
- locusInfo.compareAndUpdate = sinon.stub();
2979
3983
 
2980
3984
  locusInfo.updateLocusInfo(newLocus);
2981
3985
 
3986
+ assert.calledOnceWithExactly(MeetingsUtil.isSelfMovedOrBreakoutEnded, newLocus);
2982
3987
  assert.notCalled(locusInfo.updateControls);
2983
- assert.notCalled(locusInfo.updateConversationUrl);
2984
- assert.notCalled(locusInfo.updateCreated);
2985
3988
  assert.notCalled(locusInfo.updateFullState);
2986
- assert.notCalled(locusInfo.updateHostInfo);
2987
- assert.notCalled(locusInfo.updateMeetingInfo);
2988
- assert.notCalled(locusInfo.updateMediaShares);
2989
- assert.notCalled(locusInfo.updateReplaces);
2990
3989
  assert.notCalled(locusInfo.updateSelf);
2991
- assert.notCalled(locusInfo.updateLocusUrl);
2992
- assert.notCalled(locusInfo.updateAclUrl);
2993
- assert.notCalled(locusInfo.updateBasequence);
2994
- assert.notCalled(locusInfo.updateSequence);
2995
- assert.notCalled(locusInfo.updateEmbeddedApps);
2996
- assert.notCalled(locusInfo.updateLinks);
2997
- assert.notCalled(locusInfo.compareAndUpdate);
3990
+
3991
+ MeetingsUtil.isSelfMovedOrBreakoutEnded.restore();
2998
3992
  });
2999
3993
 
3000
3994
  it('#updateLocusInfo puts the Locus DTO top level properties at the right place in LocusInfo class', () => {
3001
3995
  // this test verifies that the top-level properties of Locus DTO are copied
3002
3996
  // into LocusInfo class and set as top level properties too
3003
- // this is important, because the code handling Locus hass trees relies on it, see updateFromHashTree()
3997
+ // this is important, because the code handling Locus hash trees relies on it, see updateFromHashTree()
3004
3998
  const info = {id: 'info id'};
3005
3999
  const fullState = {id: 'fullState id'};
3006
4000
  const links = {services: {id: 'service links'}, resources: {id: 'resource links'}};
@@ -3039,7 +4033,7 @@ describe('plugin-meetings', () => {
3039
4033
  sandbox.stub(locusInfo, 'handleOneOnOneEvent');
3040
4034
  sandbox.stub(locusParser, 'isNewFullLocus').returns(true);
3041
4035
 
3042
- locusInfo.onFullLocus(fakeLocus, eventType);
4036
+ locusInfo.onFullLocus('test', fakeLocus, eventType);
3043
4037
 
3044
4038
  assert.equal(fakeLocus, locusParser.workingCopy);
3045
4039
  });
@@ -3060,7 +4054,7 @@ describe('plugin-meetings', () => {
3060
4054
 
3061
4055
  sandbox.stub(locusParser, 'isNewFullLocus').returns(false);
3062
4056
 
3063
- locusInfo.onFullLocus(fakeLocus, eventType);
4057
+ locusInfo.onFullLocus('test', fakeLocus, eventType);
3064
4058
 
3065
4059
  spies.forEach((spy) => {
3066
4060
  assert.notCalled(spy);
@@ -3210,7 +4204,11 @@ describe('plugin-meetings', () => {
3210
4204
  }).then(() => {
3211
4205
  assert.calledOnceWithExactly(meeting.meetingRequest.getLocusDTO, {url: 'oldLocusUrl'});
3212
4206
 
3213
- assert.calledOnceWithExactly(meeting.locusInfo.onFullLocus, fakeFullLocusDto);
4207
+ assert.calledOnceWithExactly(
4208
+ meeting.locusInfo.onFullLocus,
4209
+ 'classic Locus sync',
4210
+ fakeFullLocusDto
4211
+ );
3214
4212
  assert.calledOnce(locusInfo.locusParser.resume);
3215
4213
  });
3216
4214
  });
@@ -3308,7 +4306,11 @@ describe('plugin-meetings', () => {
3308
4306
  });
3309
4307
 
3310
4308
  assert.notCalled(meeting.locusInfo.handleLocusDelta);
3311
- assert.calledOnceWithExactly(meeting.locusInfo.onFullLocus, fakeFullLocusDto);
4309
+ assert.calledOnceWithExactly(
4310
+ meeting.locusInfo.onFullLocus,
4311
+ 'classic Locus sync',
4312
+ fakeFullLocusDto
4313
+ );
3312
4314
  assert.calledOnce(locusInfo.locusParser.resume);
3313
4315
  });
3314
4316
  });
@@ -3476,34 +4478,169 @@ describe('plugin-meetings', () => {
3476
4478
 
3477
4479
  locusInfo.locusParser.workingCopy = {syncUrl: 'fake locus DELTA url'};
3478
4480
 
3479
- await locusInfo.applyLocusDeltaData(DESYNC, fakeLocus, meeting);
4481
+ await locusInfo.applyLocusDeltaData(DESYNC, fakeLocus, meeting);
4482
+
4483
+ await testUtils.flushPromises();
4484
+
4485
+ assert.calledOnceWithExactly(meeting.meetingRequest.getLocusDTO, {
4486
+ url: 'fake locus DELTA url',
4487
+ });
4488
+ assert.notCalled(meeting.locusInfo.handleLocusDelta);
4489
+ assert.calledOnceWithExactly(
4490
+ meeting.locusInfo.onFullLocus,
4491
+ 'classic Locus sync',
4492
+ fakeFullLocusDto
4493
+ );
4494
+ assert.calledOnce(locusInfo.locusParser.resume);
4495
+ });
4496
+ });
4497
+
4498
+ describe('#updateLocusCache', () => {
4499
+ it('cache it if income locus is main session locus', () => {
4500
+ const locus = {url: 'url'};
4501
+ locusInfo.mainSessionLocusCache = null;
4502
+ locusInfo.updateLocusCache(locus);
4503
+
4504
+ assert.deepEqual(locusInfo.mainSessionLocusCache, locus);
4505
+ });
4506
+
4507
+ it('not cache it if income locus is breakout session locus', () => {
4508
+ const locus = {url: 'url', controls: {breakout: {sessionType: 'BREAKOUT'}}};
4509
+ locusInfo.mainSessionLocusCache = null;
4510
+ locusInfo.updateLocusCache(locus);
4511
+
4512
+ assert.isNull(locusInfo.mainSessionLocusCache);
4513
+ });
4514
+
4515
+ it('should map participant with htMeta.elementId.id of 0 (falsy number) to hashTreeObjectId2ParticipantId', () => {
4516
+ const locus = {
4517
+ url: 'url',
4518
+ participants: [
4519
+ {
4520
+ id: 'participant-zero',
4521
+ htMeta: {elementId: {id: 0}},
4522
+ },
4523
+ ],
4524
+ };
4525
+
4526
+ sinon.stub(locusInfo.locusParser, 'isNewFullLocus').returns(true);
4527
+ sinon.stub(locusInfo, 'updateLocusInfo');
4528
+ sinon.stub(locusInfo, 'updateParticipants');
4529
+ sinon.stub(locusInfo, 'isMeetingActive');
4530
+ sinon.stub(locusInfo, 'handleOneOnOneEvent');
4531
+ sinon.stub(locusInfo, 'updateEmbeddedApps');
4532
+ locusInfo.locusParser.workingCopy = null;
4533
+
4534
+ locusInfo.onFullLocus('test', locus);
4535
+
4536
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.get(0), 'participant-zero');
4537
+ });
4538
+ });
4539
+
4540
+ describe('#onDeltaLocus', () => {
4541
+ it('should use forceReplaceMembers from jsSdkMeta when it is defined', () => {
4542
+ sinon.stub(locusInfo, 'mergeParticipants');
4543
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(true);
4544
+ sinon.stub(locusInfo, 'updateParticipants');
4545
+ sinon.stub(locusInfo, 'isMeetingActive');
4546
+
4547
+ locusInfo.onDeltaLocus({
4548
+ participants: [],
4549
+ jsSdkMeta: {forceReplaceMembers: true, removedParticipantIds: []},
4550
+ });
4551
+
4552
+ assert.calledOnceWithExactly(locusInfo.updateParticipants, [], [], true);
4553
+ });
4554
+
4555
+ it('should fall back to isNeedReplaceMembers when forceReplaceMembers is not in jsSdkMeta', () => {
4556
+ sinon.stub(locusInfo, 'mergeParticipants');
4557
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(true);
4558
+ sinon.stub(locusInfo, 'updateParticipants');
4559
+ sinon.stub(locusInfo, 'isMeetingActive');
4560
+
4561
+ locusInfo.onDeltaLocus({participants: []});
4562
+
4563
+ // without jsSdkMeta.forceReplaceMembers, uses ControlsUtils.isNeedReplaceMembers result (false by default)
4564
+ assert.calledOnceWithExactly(locusInfo.updateParticipants, [], undefined, false);
4565
+ });
4566
+
4567
+ it('should not call updateParticipants when updateLocusInfo returns false', () => {
4568
+ sinon.stub(locusInfo, 'mergeParticipants');
4569
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(false);
4570
+ sinon.stub(locusInfo, 'updateParticipants');
4571
+ sinon.stub(locusInfo, 'isMeetingActive');
4572
+
4573
+ locusInfo.onDeltaLocus({participants: [], self: {state: 'LEFT', reason: 'MOVED'}});
4574
+
4575
+ assert.notCalled(locusInfo.updateParticipants);
4576
+ });
4577
+
4578
+ it('should call updateParticipants when updateLocusInfo returns true', () => {
4579
+ sinon.stub(locusInfo, 'mergeParticipants');
4580
+ sinon.stub(locusInfo, 'updateLocusInfo').returns(true);
4581
+ sinon.stub(locusInfo, 'updateParticipants');
4582
+ sinon.stub(locusInfo, 'isMeetingActive');
4583
+
4584
+ locusInfo.onDeltaLocus({participants: [{id: 'p1'}]});
4585
+
4586
+ assert.calledOnce(locusInfo.updateParticipants);
4587
+ });
4588
+
4589
+ [
4590
+ {forceReplaceMembers: true, selfInParticipants: false, expectedSelfCopied: true},
4591
+ {forceReplaceMembers: true, selfInParticipants: true, expectedSelfCopied: false},
4592
+ {forceReplaceMembers: false, selfInParticipants: false, expectedSelfCopied: false},
4593
+ {forceReplaceMembers: false, selfInParticipants: true, expectedSelfCopied: false},
4594
+ ].forEach(({forceReplaceMembers, selfInParticipants, expectedSelfCopied}) => {
4595
+ it(`should ${expectedSelfCopied ? '' : 'not '}copy self into participants when forceReplaceMembers=${forceReplaceMembers} and self ${selfInParticipants ? 'is' : 'is not'} in participants`, () => {
4596
+ const self = {identity: 'selfId', state: 'JOINED', devices: [], status: {}};
4597
+ const participant = {identity: selfInParticipants ? 'selfId' : 'other'};
4598
+ const locus = {
4599
+ participants: [participant],
4600
+ self,
4601
+ jsSdkMeta: {forceReplaceMembers, removedParticipantIds: []},
4602
+ };
3480
4603
 
3481
- await testUtils.flushPromises();
4604
+ locusInfo.onDeltaLocus(locus);
3482
4605
 
3483
- assert.calledOnceWithExactly(meeting.meetingRequest.getLocusDTO, {
3484
- url: 'fake locus DELTA url',
4606
+ const expectedParticipants = expectedSelfCopied ? [participant, self] : [participant];
4607
+ assert.deepEqual(locus.participants, expectedParticipants);
3485
4608
  });
3486
- assert.notCalled(meeting.locusInfo.handleLocusDelta);
3487
- assert.calledOnceWithExactly(meeting.locusInfo.onFullLocus, fakeFullLocusDto);
3488
- assert.calledOnce(locusInfo.locusParser.resume);
3489
4609
  });
3490
4610
  });
3491
4611
 
3492
- describe('#updateLocusCache', () => {
3493
- it('cache it if income locus is main session locus', () => {
3494
- const locus = {url: 'url'};
3495
- locusInfo.mainSessionLocusCache = null;
3496
- locusInfo.updateLocusCache(locus);
4612
+ describe('#updateLocusInfo', () => {
4613
+ it('should return false when self.reason is MOVED and self.state is LEFT', () => {
4614
+ sinon.stub(locusInfo, 'updateControls');
3497
4615
 
3498
- assert.deepEqual(locusInfo.mainSessionLocusCache, locus);
3499
- });
4616
+ const result = locusInfo.updateLocusInfo({self: {reason: 'MOVED', state: 'LEFT'}});
3500
4617
 
3501
- it('not cache it if income locus is breakout session locus', () => {
3502
- const locus = {url: 'url', controls: {breakout: {sessionType: 'BREAKOUT'}}};
3503
- locusInfo.mainSessionLocusCache = null;
3504
- locusInfo.updateLocusCache(locus);
4618
+ assert.isFalse(result);
4619
+ assert.notCalled(locusInfo.updateControls);
4620
+ });
3505
4621
 
3506
- assert.isNull(locusInfo.mainSessionLocusCache);
4622
+ it('should return true when self is not in MOVED/LEFT state', () => {
4623
+ sinon.stub(locusInfo, 'updateControls');
4624
+ sinon.stub(locusInfo, 'updateConversationUrl');
4625
+ sinon.stub(locusInfo, 'updateCreated');
4626
+ sinon.stub(locusInfo, 'updateFullState');
4627
+ sinon.stub(locusInfo, 'updateHostInfo');
4628
+ sinon.stub(locusInfo, 'updateLocusUrl');
4629
+ sinon.stub(locusInfo, 'updateMeetingInfo');
4630
+ sinon.stub(locusInfo, 'updateMediaShares');
4631
+ sinon.stub(locusInfo, 'updateReplaces');
4632
+ sinon.stub(locusInfo, 'updateSelf');
4633
+ sinon.stub(locusInfo, 'updateAclUrl');
4634
+ sinon.stub(locusInfo, 'updateBasequence');
4635
+ sinon.stub(locusInfo, 'updateSequence');
4636
+ sinon.stub(locusInfo, 'updateEmbeddedApps');
4637
+ sinon.stub(locusInfo, 'updateLinks');
4638
+ sinon.stub(locusInfo, 'compareAndUpdate');
4639
+
4640
+ const result = locusInfo.updateLocusInfo({self: {state: 'JOINED'}});
4641
+
4642
+ assert.isTrue(result);
4643
+ assert.calledOnce(locusInfo.updateControls);
3507
4644
  });
3508
4645
  });
3509
4646
 
@@ -3701,6 +4838,31 @@ describe('plugin-meetings', () => {
3701
4838
  });
3702
4839
  });
3703
4840
 
4841
+ describe('#cleanUp', () => {
4842
+ it('calls cleanUp on all hash tree parsers and clears maps', () => {
4843
+ const parser1 = {cleanUp: sinon.stub()};
4844
+ const parser2 = {cleanUp: sinon.stub()};
4845
+
4846
+ locusInfo.hashTreeParsers.set('url1', {parser: parser1, initializedFromHashTree: true});
4847
+ locusInfo.hashTreeParsers.set('url2', {parser: parser2, initializedFromHashTree: true});
4848
+ locusInfo.hashTreeObjectId2ParticipantId.set(1, 'participant1');
4849
+
4850
+ locusInfo.cleanUp();
4851
+
4852
+ assert.calledOnce(parser1.cleanUp);
4853
+ assert.calledOnce(parser2.cleanUp);
4854
+ assert.equal(locusInfo.hashTreeParsers.size, 0);
4855
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.size, 0);
4856
+ });
4857
+
4858
+ it('works when there are no hash tree parsers', () => {
4859
+ locusInfo.cleanUp();
4860
+
4861
+ assert.equal(locusInfo.hashTreeParsers.size, 0);
4862
+ assert.equal(locusInfo.hashTreeObjectId2ParticipantId.size, 0);
4863
+ });
4864
+ });
4865
+
3704
4866
  describe('#handleOneonOneEvent', () => {
3705
4867
  beforeEach(() => {
3706
4868
  locusInfo.emitScoped = sinon.stub();
@@ -3743,6 +4905,9 @@ describe('plugin-meetings', () => {
3743
4905
  });
3744
4906
 
3745
4907
  describe('#isMeetingActive', () => {
4908
+ beforeEach(() => {
4909
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
4910
+ });
3746
4911
  forEach([_CALL_, _SIP_BRIDGE_, _SPACE_SHARE_], (type) => {
3747
4912
  describe(`type = ${type}`, () => {
3748
4913
  it('sends client event correctly for state = inactive', () => {
@@ -3763,6 +4928,11 @@ describe('plugin-meetings', () => {
3763
4928
  options: {
3764
4929
  meetingId: locusInfo.meetingId,
3765
4930
  },
4931
+ payload: {
4932
+ eventData: {
4933
+ joinInProgress: false,
4934
+ },
4935
+ },
3766
4936
  });
3767
4937
  });
3768
4938
 
@@ -3783,6 +4953,11 @@ describe('plugin-meetings', () => {
3783
4953
  options: {
3784
4954
  meetingId: locusInfo.meetingId,
3785
4955
  },
4956
+ payload: {
4957
+ eventData: {
4958
+ joinInProgress: false,
4959
+ },
4960
+ },
3786
4961
  });
3787
4962
  });
3788
4963
 
@@ -3804,12 +4979,17 @@ describe('plugin-meetings', () => {
3804
4979
  options: {
3805
4980
  meetingId: locusInfo.meetingId,
3806
4981
  },
4982
+ payload: {
4983
+ eventData: {
4984
+ joinInProgress: false,
4985
+ },
4986
+ },
3807
4987
  });
3808
4988
  });
3809
4989
  });
3810
4990
  });
3811
4991
 
3812
- it('sends client event correctly for state = MEETING_INACTIVE_TERMINATING', () => {
4992
+ it('sends client event correctly for state = MEETING_INACTIVE', () => {
3813
4993
  locusInfo.getLocusPartner = sinon.stub().returns({state: MEETING_STATE.STATES.LEFT});
3814
4994
  locusInfo.parsedLocus = {
3815
4995
  fullState: {
@@ -3831,7 +5011,7 @@ describe('plugin-meetings', () => {
3831
5011
  });
3832
5012
  });
3833
5013
 
3834
- it('sends client event correctly for state = FULLSTATE_REMOVED', () => {
5014
+ it('does not send client event when state = INACTIVE and endMeetingReason = BREAKOUT_ENDED', () => {
3835
5015
  locusInfo.getLocusPartner = sinon.stub().returns({state: MEETING_STATE.STATES.LEFT});
3836
5016
  locusInfo.parsedLocus = {
3837
5017
  fullState: {
@@ -3840,23 +5020,134 @@ describe('plugin-meetings', () => {
3840
5020
  };
3841
5021
 
3842
5022
  locusInfo.fullState = {
3843
- removed: true,
5023
+ state: LOCUS.STATE.INACTIVE,
5024
+ endMeetingReason: 'BREAKOUT_ENDED',
3844
5025
  };
3845
5026
 
3846
5027
  locusInfo.isMeetingActive();
3847
5028
 
3848
- assert.calledWith(webex.internal.newMetrics.submitClientEvent, {
3849
- name: 'client.call.remote-ended',
3850
- options: {
3851
- meetingId: locusInfo.meetingId,
5029
+ assert.notCalled(webex.internal.newMetrics.submitClientEvent);
5030
+ });
5031
+
5032
+ it('sends client event correctly for state self removed', () => {
5033
+ locusInfo.emitScoped = sinon.stub();
5034
+ locusInfo.parsedLocus = {
5035
+ fullState: {
5036
+ type: _MEETING_,
5037
+ },
5038
+ self: {
5039
+ removed: true,
5040
+ }
5041
+ };
5042
+
5043
+ locusInfo.isMeetingActive();
5044
+
5045
+ assert.notCalled(webex.internal.newMetrics.submitClientEvent);
5046
+ assert.calledOnceWithExactly(
5047
+ locusInfo.emitScoped,
5048
+ {
5049
+ file: 'locus-info',
5050
+ function: 'isMeetingActive',
3852
5051
  },
5052
+ EVENTS.DESTROY_MEETING,
5053
+ {
5054
+ reason: MEETING_REMOVED_REASON.SELF_REMOVED,
5055
+ shouldLeave: false,
5056
+ }
5057
+ );
5058
+ });
5059
+
5060
+ describe('destroyMeetingSuspended', () => {
5061
+ it('suppresses DESTROY_MEETING for SELF_REMOVED when suspended', () => {
5062
+ locusInfo.emitScoped = sinon.stub();
5063
+ locusInfo.suspendDestroyMeeting(true);
5064
+ locusInfo.parsedLocus = {
5065
+ fullState: {
5066
+ type: _MEETING_,
5067
+ },
5068
+ self: {
5069
+ removed: true,
5070
+ }
5071
+ };
5072
+
5073
+ locusInfo.isMeetingActive();
5074
+
5075
+ assert.notCalled(locusInfo.emitScoped);
5076
+ assert.calledOnceWithExactly(
5077
+ sendBehavioralMetricStub,
5078
+ BEHAVIORAL_METRICS.DESTROY_MEETING_WHILE_SUSPENDED,
5079
+ {
5080
+ meetingId: locusInfo.meetingId,
5081
+ reason: 'SELF_REMOVED',
5082
+ }
5083
+ );
5084
+ });
5085
+
5086
+ it('suppresses DESTROY_MEETING for MEETING_INACTIVE_TERMINATING when suspended', () => {
5087
+ locusInfo.emitScoped = sinon.stub();
5088
+ locusInfo.suspendDestroyMeeting(true);
5089
+ locusInfo.parsedLocus = {
5090
+ fullState: {
5091
+ type: _MEETING_,
5092
+ },
5093
+ };
5094
+ locusInfo.fullState = {
5095
+ state: LOCUS.STATE.INACTIVE,
5096
+ };
5097
+
5098
+ locusInfo.isMeetingActive();
5099
+
5100
+ assert.notCalled(locusInfo.emitScoped);
5101
+ assert.notCalled(webex.internal.newMetrics.submitClientEvent);
5102
+ assert.calledOnceWithExactly(
5103
+ sendBehavioralMetricStub,
5104
+ BEHAVIORAL_METRICS.DESTROY_MEETING_WHILE_SUSPENDED,
5105
+ {
5106
+ meetingId: locusInfo.meetingId,
5107
+ reason: 'MEETING_INACTIVE_TERMINATING',
5108
+ }
5109
+ );
5110
+ });
5111
+
5112
+ [
5113
+ {reason: 'CALL_INACTIVE', setup: () => {
5114
+ locusInfo.parsedLocus = {fullState: {type: _CALL_}};
5115
+ locusInfo.fullState = {state: LOCUS.STATE.INACTIVE};
5116
+ }},
5117
+ {reason: 'PARTNER_LEFT', setup: () => {
5118
+ locusInfo.getLocusPartner = sinon.stub().returns({state: MEETING_STATE.STATES.LEFT});
5119
+ locusInfo.parsedLocus = {fullState: {type: _CALL_}, self: {state: MEETING_STATE.STATES.JOINED}};
5120
+ }},
5121
+ {reason: 'SELF_LEFT', setup: () => {
5122
+ locusInfo.getLocusPartner = sinon.stub().returns({state: MEETING_STATE.STATES.LEFT});
5123
+ locusInfo.parsedLocus = {fullState: {type: _CALL_}, self: {state: MEETING_STATE.STATES.LEFT}};
5124
+ }},
5125
+ ].forEach(({reason, setup}) => {
5126
+ it(`sends joinInProgress=true in client event for ${reason} when suspended`, () => {
5127
+ locusInfo.suspendDestroyMeeting(true);
5128
+ setup();
5129
+
5130
+ locusInfo.isMeetingActive();
5131
+
5132
+ assert.calledWith(webex.internal.newMetrics.submitClientEvent, {
5133
+ name: 'client.call.remote-ended',
5134
+ options: {
5135
+ meetingId: locusInfo.meetingId,
5136
+ },
5137
+ payload: {
5138
+ eventData: {
5139
+ joinInProgress: true,
5140
+ },
5141
+ },
5142
+ });
5143
+ });
3853
5144
  });
3854
5145
  });
3855
5146
  });
3856
5147
 
3857
5148
  describe('#updateLocusUrl', () => {
3858
5149
  it('trigger LOCUS_INFO_UPDATE_URL event with isMainLocus is true as default', () => {
3859
- const fakeUrl = "https://fake.com/locus";
5150
+ const fakeUrl = 'https://fake.com/locus';
3860
5151
  locusInfo.emitScoped = sinon.stub();
3861
5152
  locusInfo.updateLocusUrl(fakeUrl);
3862
5153
 
@@ -3869,12 +5160,12 @@ describe('plugin-meetings', () => {
3869
5160
  EVENTS.LOCUS_INFO_UPDATE_URL,
3870
5161
  {
3871
5162
  url: fakeUrl,
3872
- isMainLocus: true
3873
- },
5163
+ isMainLocus: true,
5164
+ }
3874
5165
  );
3875
5166
  });
3876
5167
  it('trigger LOCUS_INFO_UPDATE_URL event with isMainLocus is false', () => {
3877
- const fakeUrl = "https://fake.com/locus";
5168
+ const fakeUrl = 'https://fake.com/locus';
3878
5169
  locusInfo.emitScoped = sinon.stub();
3879
5170
  locusInfo.updateLocusUrl(fakeUrl, false);
3880
5171
 
@@ -3887,8 +5178,8 @@ describe('plugin-meetings', () => {
3887
5178
  EVENTS.LOCUS_INFO_UPDATE_URL,
3888
5179
  {
3889
5180
  url: fakeUrl,
3890
- isMainLocus: false
3891
- },
5181
+ isMainLocus: false,
5182
+ }
3892
5183
  );
3893
5184
  });
3894
5185
  });
@@ -3940,8 +5231,8 @@ describe('plugin-meetings', () => {
3940
5231
 
3941
5232
  sinon.stub(locusInfo, 'updateParticipants');
3942
5233
  sinon.stub(locusInfo, 'isMeetingActive');
3943
- sinon.stub(locusInfo, 'handleOneOnOneEvent');
3944
- (updateLocusInfoStub = sinon.stub(locusInfo, 'updateLocusInfo'));
5234
+ sinon.stub(locusInfo, 'handleOneOnOneEvent');
5235
+ updateLocusInfoStub = sinon.stub(locusInfo, 'updateLocusInfo');
3945
5236
  syncRequestStub = sinon.stub().resolves({body: {}});
3946
5237
 
3947
5238
  mockMeeting.locusInfo = locusInfo;
@@ -3950,7 +5241,7 @@ describe('plugin-meetings', () => {
3950
5241
  getLocusDTO: syncRequestStub,
3951
5242
  };
3952
5243
 
3953
- locusInfo.onFullLocus({
5244
+ locusInfo.onFullLocus('test', {
3954
5245
  sequence: {
3955
5246
  rangeStart: 0,
3956
5247
  rangeEnd: 0,
@@ -4188,7 +5479,9 @@ describe('plugin-meetings', () => {
4188
5479
 
4189
5480
  describe('#parse', () => {
4190
5481
  it('handles hash tree messages correctly', () => {
5482
+ const fakeLocusUrl = 'http://locus-url.com';
4191
5483
  const fakeHashTreeMessage = {
5484
+ locusUrl: fakeLocusUrl,
4192
5485
  locusStateElements: [
4193
5486
  {
4194
5487
  htMeta: {elementId: {type: 'self'}},
@@ -4207,12 +5500,403 @@ describe('plugin-meetings', () => {
4207
5500
  const mockHashTreeParser = {
4208
5501
  handleMessage: sinon.stub(),
4209
5502
  };
4210
- locusInfo.hashTreeParser = mockHashTreeParser;
5503
+ locusInfo.hashTreeParsers.set(fakeLocusUrl, {
5504
+ parser: mockHashTreeParser,
5505
+ initializedFromHashTree: true,
5506
+ });
4211
5507
 
4212
5508
  locusInfo.parse(mockMeeting, data);
4213
5509
 
4214
5510
  assert.calledOnceWithExactly(mockHashTreeParser.handleMessage, fakeHashTreeMessage);
4215
5511
  });
5512
+
5513
+ it('ignores hash tree event when hashTreeParser is not created yet', () => {
5514
+ const data = {
5515
+ eventType: LOCUSEVENT.HASH_TREE_DATA_UPDATED,
5516
+ stateElementsMessage: {
5517
+ locusStateElements: [],
5518
+ dataSets: [],
5519
+ },
5520
+ };
5521
+
5522
+ const loggerSpy = sinon.spy(LoggerProxy.logger, 'info');
5523
+ const getTheLocusToUpdateStub = sinon.stub(locusInfo, 'getTheLocusToUpdate');
5524
+
5525
+ // Ensure we're not using hash trees
5526
+ assert.equal(locusInfo.hashTreeParsers.size, 0);
5527
+
5528
+ locusInfo.parse(mockMeeting, data);
5529
+
5530
+ assert.calledWith(
5531
+ loggerSpy,
5532
+ 'Locus-info:index#parse --> received locus hash tree event before hashTreeParser is created'
5533
+ );
5534
+ assert.notCalled(getTheLocusToUpdateStub);
5535
+ });
5536
+
5537
+ it('should call handleLocusAPIResponse for SDK_LOCUS_FROM_SYNC_MEETINGS when hash tree parsers exist', () => {
5538
+ const fakeLocusUrl = 'http://locus-url.com';
5539
+ const fakeLocus = {url: fakeLocusUrl, fullState: {state: 'ACTIVE'}};
5540
+ const mockHashTreeParser = {
5541
+ handleMessage: sinon.stub(),
5542
+ handleLocusUpdate: sinon.stub(),
5543
+ };
5544
+ locusInfo.hashTreeParsers.set(fakeLocusUrl, {
5545
+ parser: mockHashTreeParser,
5546
+ initializedFromHashTree: true,
5547
+ });
5548
+
5549
+ sinon.stub(locusInfo, 'handleLocusDelta');
5550
+
5551
+ locusInfo.parse(mockMeeting, {
5552
+ eventType: LOCUSEVENT.SDK_LOCUS_FROM_SYNC_MEETINGS,
5553
+ locus: fakeLocus,
5554
+ });
5555
+
5556
+ // should route through handleLocusAPIResponse which passes unwrapped LocusDTO to parser
5557
+ assert.calledOnce(mockHashTreeParser.handleLocusUpdate);
5558
+ assert.notCalled(mockHashTreeParser.handleMessage);
5559
+ assert.notCalled(locusInfo.handleLocusDelta);
5560
+ });
5561
+ });
5562
+ });
5563
+
5564
+ describe('#createLocusFromHashTreeMessage', () => {
5565
+ const LOCUS_URL = 'https://locus.example.com/loci/abc-123';
5566
+
5567
+ const createElement = (type, data) => ({
5568
+ htMeta: {elementId: {type, id: 1, version: 1}},
5569
+ data,
5570
+ });
5571
+
5572
+ it('returns locus with url and empty participants when no locusStateElements', () => {
5573
+ const result = createLocusFromHashTreeMessage({locusUrl: LOCUS_URL});
5574
+
5575
+ assert.deepEqual(result.locus, {participants: [], url: LOCUS_URL});
5576
+ assert.isUndefined(result.metadata);
5577
+ });
5578
+
5579
+ it('skips elements without data', () => {
5580
+ const result = createLocusFromHashTreeMessage({
5581
+ locusUrl: LOCUS_URL,
5582
+ locusStateElements: [{htMeta: {elementId: {type: 'Self', id: 1, version: 1}}, data: null}],
5583
+ });
5584
+
5585
+ assert.deepEqual(result.locus, {participants: [], url: LOCUS_URL});
5586
+ });
5587
+
5588
+ [
5589
+ {type: 'Self', locusKey: 'self', data: {id: 'self-1', state: 'JOINED'}},
5590
+ {type: 'Info', locusKey: 'info', data: {webExMeetingId: '123'}},
5591
+ {type: 'FullState', locusKey: 'fullState', data: {state: 'ACTIVE'}},
5592
+ {type: 'Links', locusKey: 'links', data: {resources: {}}},
5593
+ ].forEach(({type, locusKey, data}) => {
5594
+ it(`maps ${type} element to locus.${locusKey}`, () => {
5595
+ const result = createLocusFromHashTreeMessage({
5596
+ locusUrl: LOCUS_URL,
5597
+ locusStateElements: [createElement(type, data)],
5598
+ });
5599
+
5600
+ assert.deepEqual(result.locus[locusKey], data);
5601
+ });
5602
+ });
5603
+
5604
+ it('pushes Participant elements to locus.participants', () => {
5605
+ const p1 = {id: 'p1', state: 'JOINED'};
5606
+ const p2 = {id: 'p2', state: 'LEFT'};
5607
+
5608
+ const result = createLocusFromHashTreeMessage({
5609
+ locusUrl: LOCUS_URL,
5610
+ locusStateElements: [createElement('Participant', p1), createElement('Participant', p2)],
5611
+ });
5612
+
5613
+ assert.deepEqual(result.locus.participants, [p1, p2]);
5614
+ });
5615
+
5616
+ it('pushes MediaShare elements to locus.mediaShares array', () => {
5617
+ const share1 = {name: 'whiteboard'};
5618
+ const share2 = {name: 'content'};
5619
+
5620
+ const result = createLocusFromHashTreeMessage({
5621
+ locusUrl: LOCUS_URL,
5622
+ locusStateElements: [
5623
+ createElement('MediaShare', share1),
5624
+ createElement('MediaShare', share2),
5625
+ ],
5626
+ });
5627
+
5628
+ assert.deepEqual(result.locus.mediaShares, [share1, share2]);
5629
+ });
5630
+
5631
+ it('pushes EmbeddedApp elements to locus.embeddedApps array', () => {
5632
+ const app = {appId: 'app-1', state: 'STARTED'};
5633
+
5634
+ const result = createLocusFromHashTreeMessage({
5635
+ locusUrl: LOCUS_URL,
5636
+ locusStateElements: [createElement('EmbeddedApp', app)],
5637
+ });
5638
+
5639
+ assert.deepEqual(result.locus.embeddedApps, [app]);
5640
+ });
5641
+
5642
+ it('merges ControlEntry elements into locus.controls', () => {
5643
+ const control1 = {record: {recording: true}};
5644
+ const control2 = {lock: {locked: false}};
5645
+
5646
+ const result = createLocusFromHashTreeMessage({
5647
+ locusUrl: LOCUS_URL,
5648
+ locusStateElements: [
5649
+ createElement('ControlEntry', control1),
5650
+ createElement('ControlEntry', control2),
5651
+ ],
5652
+ });
5653
+
5654
+ assert.deepEqual(result.locus.controls, {record: {recording: true}, lock: {locked: false}});
5655
+ });
5656
+
5657
+ it('spreads Locus element data onto top level but removes managed keys', () => {
5658
+ const locusData = {
5659
+ url: 'should-be-overridden',
5660
+ someTopLevelField: 'value',
5661
+ // these are managed by other ObjectTypes and should be removed
5662
+ links: {should: 'be removed'},
5663
+ info: {should: 'be removed'},
5664
+ fullState: {should: 'be removed'},
5665
+ self: {should: 'be removed'},
5666
+ participants: [{should: 'be removed'}],
5667
+ mediaShares: [{should: 'be removed'}],
5668
+ controls: {should: 'be removed'},
5669
+ embeddedApps: [{should: 'be removed'}],
5670
+ };
5671
+
5672
+ const result = createLocusFromHashTreeMessage({
5673
+ locusUrl: LOCUS_URL,
5674
+ locusStateElements: [createElement('Locus', locusData)],
5675
+ });
5676
+
5677
+ assert.equal(result.locus.someTopLevelField, 'value');
5678
+ assert.deepEqual(result.locus.participants, []);
5679
+ assert.isUndefined(result.locus.links);
5680
+ assert.isUndefined(result.locus.info);
5681
+ assert.isUndefined(result.locus.fullState);
5682
+ assert.isUndefined(result.locus.self);
5683
+ assert.isUndefined(result.locus.mediaShares);
5684
+ assert.isUndefined(result.locus.controls);
5685
+ assert.isUndefined(result.locus.embeddedApps);
5686
+ });
5687
+
5688
+ it('extracts Metadata element as metadata in the result', () => {
5689
+ const metadataData = {visibleDataSets: [{name: 'ds1', url: 'http://ds1.url'}]};
5690
+ const htMeta = {elementId: {type: 'Metadata', id: 99, version: 3}};
5691
+
5692
+ const result = createLocusFromHashTreeMessage({
5693
+ locusUrl: LOCUS_URL,
5694
+ locusStateElements: [{htMeta, data: metadataData}],
5695
+ });
5696
+
5697
+ assert.deepEqual(result.metadata, {...metadataData, htMeta});
5698
+ assert.isUndefined(result.locus.metadata);
5699
+ });
5700
+
5701
+ it('handles a message with multiple element types', () => {
5702
+ const selfData = {id: 'self-1'};
5703
+ const participantData = {id: 'p1'};
5704
+ const infoData = {webExMeetingId: '456'};
5705
+
5706
+ const result = createLocusFromHashTreeMessage({
5707
+ locusUrl: LOCUS_URL,
5708
+ locusStateElements: [
5709
+ createElement('Self', selfData),
5710
+ createElement('Participant', participantData),
5711
+ createElement('Info', infoData),
5712
+ ],
5713
+ });
5714
+
5715
+ assert.deepEqual(result.locus.self, selfData);
5716
+ assert.deepEqual(result.locus.participants, [participantData]);
5717
+ assert.deepEqual(result.locus.info, infoData);
5718
+ assert.equal(result.locus.url, LOCUS_URL);
5719
+ });
5720
+
5721
+ it('ignores unknown element types', () => {
5722
+ const result = createLocusFromHashTreeMessage({
5723
+ locusUrl: LOCUS_URL,
5724
+ locusStateElements: [createElement('UnknownType', {foo: 'bar'})],
5725
+ });
5726
+
5727
+ assert.deepEqual(result.locus, {participants: [], url: LOCUS_URL});
5728
+ });
5729
+ });
5730
+
5731
+ describe('findMeetingForHashTreeMessage', () => {
5732
+ const deviceUrl = 'https://devices.example.com/device1';
5733
+
5734
+ function createMockMeetingCollection(meetings) {
5735
+ return {
5736
+ getAll: () => meetings,
5737
+ };
5738
+ }
5739
+
5740
+ function createMockMeeting(id, hashTreeParsersMap) {
5741
+ return {
5742
+ id,
5743
+ locusInfo: {
5744
+ hashTreeParsers: hashTreeParsersMap,
5745
+ },
5746
+ };
5747
+ }
5748
+
5749
+ function createSelfElement(devices) {
5750
+ return {
5751
+ htMeta: {elementId: {type: 'Self'}},
5752
+ data: {
5753
+ deviceUrl,
5754
+ devices,
5755
+ },
5756
+ };
5757
+ }
5758
+
5759
+ it('returns the meeting when locusUrl matches a hashTreeParser directly', () => {
5760
+ const locusUrl = 'https://locus.example.com/loci/abc123';
5761
+ const parsersMap = new Map([[locusUrl, {state: 'active'}]]);
5762
+ const meeting = createMockMeeting('meeting1', parsersMap);
5763
+ const collection = createMockMeetingCollection({meeting1: meeting});
5764
+
5765
+ const message = {locusUrl, locusStateElements: []};
5766
+
5767
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5768
+
5769
+ assert.equal(result, meeting);
5770
+ });
5771
+
5772
+ it('returns undefined when no meeting matches and message has no locusStateElements', () => {
5773
+ const locusUrl = 'https://locus.example.com/loci/unknown';
5774
+ const parsersMap = new Map([['https://locus.example.com/loci/other', {state: 'active'}]]);
5775
+ const meeting = createMockMeeting('meeting1', parsersMap);
5776
+ const collection = createMockMeetingCollection({meeting1: meeting});
5777
+
5778
+ const message = {locusUrl};
5779
+
5780
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5781
+
5782
+ assert.isUndefined(result);
5783
+ });
5784
+
5785
+ it('returns undefined when no meeting matches and self element has no replaces', () => {
5786
+ const locusUrl = 'https://locus.example.com/loci/unknown';
5787
+ const parsersMap = new Map([['https://locus.example.com/loci/other', {state: 'active'}]]);
5788
+ const meeting = createMockMeeting('meeting1', parsersMap);
5789
+ const collection = createMockMeetingCollection({meeting1: meeting});
5790
+
5791
+ const selfElement = createSelfElement([{url: deviceUrl}]);
5792
+ const message = {locusUrl, locusStateElements: [selfElement]};
5793
+
5794
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5795
+
5796
+ assert.isUndefined(result);
5797
+ });
5798
+
5799
+ it('returns the meeting when locusUrl from replaces matches a hashTreeParser', () => {
5800
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5801
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5802
+ const parsersMap = new Map([[oldLocusUrl, {state: 'active'}]]);
5803
+ const meeting = createMockMeeting('meeting1', parsersMap);
5804
+ const collection = createMockMeetingCollection({meeting1: meeting});
5805
+
5806
+ const selfElement = createSelfElement([
5807
+ {url: deviceUrl, replaces: [{locusUrl: oldLocusUrl}]},
5808
+ ]);
5809
+ const message = {locusUrl: newLocusUrl, locusStateElements: [selfElement]};
5810
+
5811
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5812
+
5813
+ assert.equal(result, meeting);
5814
+ });
5815
+
5816
+ it('returns undefined when replaces locusUrl does not match any hashTreeParser', () => {
5817
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5818
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5819
+ const parsersMap = new Map([
5820
+ ['https://locus.example.com/loci/something-else', {state: 'active'}],
5821
+ ]);
5822
+ const meeting = createMockMeeting('meeting1', parsersMap);
5823
+ const collection = createMockMeetingCollection({meeting1: meeting});
5824
+
5825
+ const selfElement = createSelfElement([
5826
+ {url: deviceUrl, replaces: [{locusUrl: oldLocusUrl}]},
5827
+ ]);
5828
+ const message = {locusUrl: newLocusUrl, locusStateElements: [selfElement]};
5829
+
5830
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5831
+
5832
+ assert.isUndefined(result);
5833
+ });
5834
+
5835
+ it('returns undefined when meetingCollection is empty', () => {
5836
+ const collection = createMockMeetingCollection({});
5837
+ const message = {locusUrl: 'https://locus.example.com/loci/abc', locusStateElements: []};
5838
+
5839
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5840
+
5841
+ assert.isUndefined(result);
5842
+ });
5843
+
5844
+ it('checks multiple meetings and returns the correct one', () => {
5845
+ const targetLocusUrl = 'https://locus.example.com/loci/target';
5846
+ const meeting1 = createMockMeeting(
5847
+ 'meeting1',
5848
+ new Map([['https://locus.example.com/loci/other', {state: 'active'}]])
5849
+ );
5850
+ const meeting2 = createMockMeeting(
5851
+ 'meeting2',
5852
+ new Map([[targetLocusUrl, {state: 'active'}]])
5853
+ );
5854
+ const collection = createMockMeetingCollection({meeting1, meeting2});
5855
+
5856
+ const message = {locusUrl: targetLocusUrl, locusStateElements: []};
5857
+
5858
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5859
+
5860
+ assert.equal(result, meeting2);
5861
+ });
5862
+
5863
+ it('ignores devices that do not match deviceUrl when looking for replaces', () => {
5864
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5865
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5866
+ const parsersMap = new Map([[oldLocusUrl, {state: 'active'}]]);
5867
+ const meeting = createMockMeeting('meeting1', parsersMap);
5868
+ const collection = createMockMeetingCollection({meeting1: meeting});
5869
+
5870
+ // self element has replaces, but on a different device
5871
+ const selfElement = createSelfElement([
5872
+ {url: 'https://devices.example.com/other-device', replaces: [{locusUrl: oldLocusUrl}]},
5873
+ ]);
5874
+ const message = {locusUrl: newLocusUrl, locusStateElements: [selfElement]};
5875
+
5876
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5877
+
5878
+ assert.isUndefined(result);
5879
+ });
5880
+
5881
+ it('does not use self element if it is not of type Self', () => {
5882
+ const oldLocusUrl = 'https://locus.example.com/loci/old';
5883
+ const newLocusUrl = 'https://locus.example.com/loci/new';
5884
+ const parsersMap = new Map([[oldLocusUrl, {state: 'active'}]]);
5885
+ const meeting = createMockMeeting('meeting1', parsersMap);
5886
+ const collection = createMockMeetingCollection({meeting1: meeting});
5887
+
5888
+ // element has replaces data but is not of type Self
5889
+ const nonSelfElement = {
5890
+ htMeta: {elementId: {type: 'Participant'}},
5891
+ data: {
5892
+ devices: [{url: deviceUrl, replaces: [{locusUrl: oldLocusUrl}]}],
5893
+ },
5894
+ };
5895
+ const message = {locusUrl: newLocusUrl, locusStateElements: [nonSelfElement]};
5896
+
5897
+ const result = findMeetingForHashTreeMessage(message, collection, deviceUrl);
5898
+
5899
+ assert.isUndefined(result);
4216
5900
  });
4217
5901
  });
4218
5902
  });