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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +197 -0
  3. package/dist/aiEnableRequest/index.js.map +1 -0
  4. package/dist/aiEnableRequest/utils.js +36 -0
  5. package/dist/aiEnableRequest/utils.js.map +1 -0
  6. package/dist/annotation/index.js +14 -5
  7. package/dist/annotation/index.js.map +1 -1
  8. package/dist/breakouts/breakout.js +8 -3
  9. package/dist/breakouts/breakout.js.map +1 -1
  10. package/dist/breakouts/index.js +26 -2
  11. package/dist/breakouts/index.js.map +1 -1
  12. package/dist/common/errors/webex-errors.js +49 -5
  13. package/dist/common/errors/webex-errors.js.map +1 -1
  14. package/dist/config.js +9 -3
  15. package/dist/config.js.map +1 -1
  16. package/dist/constants.js +59 -10
  17. package/dist/constants.js.map +1 -1
  18. package/dist/controls-options-manager/constants.js +11 -1
  19. package/dist/controls-options-manager/constants.js.map +1 -1
  20. package/dist/controls-options-manager/index.js +67 -29
  21. package/dist/controls-options-manager/index.js.map +1 -1
  22. package/dist/controls-options-manager/util.js +91 -0
  23. package/dist/controls-options-manager/util.js.map +1 -1
  24. package/dist/hashTree/constants.js +34 -0
  25. package/dist/hashTree/constants.js.map +1 -0
  26. package/dist/hashTree/hashTree.js +533 -0
  27. package/dist/hashTree/hashTree.js.map +1 -0
  28. package/dist/hashTree/hashTreeParser.js +2068 -36
  29. package/dist/hashTree/hashTreeParser.js.map +1 -1
  30. package/dist/hashTree/types.js +13 -3
  31. package/dist/hashTree/types.js.map +1 -1
  32. package/dist/hashTree/utils.js +111 -0
  33. package/dist/hashTree/utils.js.map +1 -0
  34. package/dist/index.js +18 -2
  35. package/dist/index.js.map +1 -1
  36. package/dist/interceptors/constant.js +12 -0
  37. package/dist/interceptors/constant.js.map +1 -0
  38. package/dist/interceptors/dataChannelAuthToken.js +350 -0
  39. package/dist/interceptors/dataChannelAuthToken.js.map +1 -0
  40. package/dist/interceptors/index.js +7 -0
  41. package/dist/interceptors/index.js.map +1 -1
  42. package/dist/interceptors/locusRetry.js +23 -8
  43. package/dist/interceptors/locusRetry.js.map +1 -1
  44. package/dist/interceptors/locusRouteToken.js +27 -5
  45. package/dist/interceptors/locusRouteToken.js.map +1 -1
  46. package/dist/interceptors/utils.js +27 -0
  47. package/dist/interceptors/utils.js.map +1 -0
  48. package/dist/interpretation/index.js +11 -2
  49. package/dist/interpretation/index.js.map +1 -1
  50. package/dist/interpretation/interpretation.types.js +7 -0
  51. package/dist/interpretation/interpretation.types.js.map +1 -0
  52. package/dist/interpretation/siLanguage.js +1 -1
  53. package/dist/locus-info/controlsUtils.js +11 -4
  54. package/dist/locus-info/controlsUtils.js.map +1 -1
  55. package/dist/locus-info/index.js +896 -277
  56. package/dist/locus-info/index.js.map +1 -1
  57. package/dist/locus-info/infoUtils.js +36 -5
  58. package/dist/locus-info/infoUtils.js.map +1 -1
  59. package/dist/locus-info/selfUtils.js +1 -0
  60. package/dist/locus-info/selfUtils.js.map +1 -1
  61. package/dist/locus-info/types.js +19 -0
  62. package/dist/locus-info/types.js.map +1 -1
  63. package/dist/media/MediaConnectionAwaiter.js +72 -3
  64. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  65. package/dist/media/index.js +8 -2
  66. package/dist/media/index.js.map +1 -1
  67. package/dist/media/properties.js +5 -2
  68. package/dist/media/properties.js.map +1 -1
  69. package/dist/meeting/in-meeting-actions.js +11 -1
  70. package/dist/meeting/in-meeting-actions.js.map +1 -1
  71. package/dist/meeting/index.js +2075 -1096
  72. package/dist/meeting/index.js.map +1 -1
  73. package/dist/meeting/locusMediaRequest.js +229 -82
  74. package/dist/meeting/locusMediaRequest.js.map +1 -1
  75. package/dist/meeting/muteState.js +10 -1
  76. package/dist/meeting/muteState.js.map +1 -1
  77. package/dist/meeting/request.js +55 -2
  78. package/dist/meeting/request.js.map +1 -1
  79. package/dist/meeting/request.type.js.map +1 -1
  80. package/dist/meeting/util.js +168 -5
  81. package/dist/meeting/util.js.map +1 -1
  82. package/dist/meeting-info/meeting-info-v2.js +2 -2
  83. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  84. package/dist/meetings/index.js +369 -173
  85. package/dist/meetings/index.js.map +1 -1
  86. package/dist/meetings/meetings.types.js +6 -1
  87. package/dist/meetings/meetings.types.js.map +1 -1
  88. package/dist/meetings/request.js +39 -0
  89. package/dist/meetings/request.js.map +1 -1
  90. package/dist/meetings/util.js +127 -25
  91. package/dist/meetings/util.js.map +1 -1
  92. package/dist/member/index.js +20 -0
  93. package/dist/member/index.js.map +1 -1
  94. package/dist/member/types.js.map +1 -1
  95. package/dist/member/util.js +40 -0
  96. package/dist/member/util.js.map +1 -1
  97. package/dist/members/index.js +101 -43
  98. package/dist/members/index.js.map +1 -1
  99. package/dist/members/util.js +8 -1
  100. package/dist/members/util.js.map +1 -1
  101. package/dist/metrics/constants.js +11 -1
  102. package/dist/metrics/constants.js.map +1 -1
  103. package/dist/multistream/codec/constants.js +63 -0
  104. package/dist/multistream/codec/constants.js.map +1 -0
  105. package/dist/multistream/mediaRequestManager.js +64 -68
  106. package/dist/multistream/mediaRequestManager.js.map +1 -1
  107. package/dist/multistream/receiveSlot.js +9 -0
  108. package/dist/multistream/receiveSlot.js.map +1 -1
  109. package/dist/multistream/remoteMediaManager.js +11 -0
  110. package/dist/multistream/remoteMediaManager.js.map +1 -1
  111. package/dist/multistream/sendSlotManager.js +116 -2
  112. package/dist/multistream/sendSlotManager.js.map +1 -1
  113. package/dist/reachability/clusterReachability.js +171 -18
  114. package/dist/reachability/clusterReachability.js.map +1 -1
  115. package/dist/reachability/index.js +142 -94
  116. package/dist/reachability/index.js.map +1 -1
  117. package/dist/reachability/reachability.types.js +2 -0
  118. package/dist/reachability/reachability.types.js.map +1 -1
  119. package/dist/reachability/reachabilityPeerConnection.js +1 -1
  120. package/dist/reachability/reachabilityPeerConnection.js.map +1 -1
  121. package/dist/reachability/util.js +45 -0
  122. package/dist/reachability/util.js.map +1 -1
  123. package/dist/reactions/reactions.type.js.map +1 -1
  124. package/dist/reconnection-manager/index.js +0 -1
  125. package/dist/reconnection-manager/index.js.map +1 -1
  126. package/dist/recording-controller/index.js +1 -3
  127. package/dist/recording-controller/index.js.map +1 -1
  128. package/dist/types/aiEnableRequest/index.d.ts +5 -0
  129. package/dist/types/aiEnableRequest/utils.d.ts +2 -0
  130. package/dist/types/common/browser-detection.d.ts +1 -0
  131. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  132. package/dist/types/common/events/events-scope.d.ts +1 -0
  133. package/dist/types/common/events/events.d.ts +1 -0
  134. package/dist/types/config.d.ts +7 -2
  135. package/dist/types/constants.d.ts +35 -1
  136. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  137. package/dist/types/controls-options-manager/index.d.ts +16 -0
  138. package/dist/types/hashTree/constants.d.ts +11 -0
  139. package/dist/types/hashTree/hashTree.d.ts +136 -0
  140. package/dist/types/hashTree/hashTreeParser.d.ts +392 -14
  141. package/dist/types/hashTree/types.d.ts +20 -0
  142. package/dist/types/hashTree/utils.d.ts +40 -0
  143. package/dist/types/index.d.ts +4 -0
  144. package/dist/types/interceptors/constant.d.ts +5 -0
  145. package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
  146. package/dist/types/interceptors/index.d.ts +2 -1
  147. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  148. package/dist/types/interceptors/locusRouteToken.d.ts +2 -0
  149. package/dist/types/interceptors/utils.d.ts +1 -0
  150. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  151. package/dist/types/locus-info/index.d.ts +116 -51
  152. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  153. package/dist/types/locus-info/types.d.ts +48 -12
  154. package/dist/types/media/MediaConnectionAwaiter.d.ts +20 -2
  155. package/dist/types/media/properties.d.ts +3 -1
  156. package/dist/types/meeting/in-meeting-actions.d.ts +10 -0
  157. package/dist/types/meeting/index.d.ts +196 -15
  158. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  159. package/dist/types/meeting/request.d.ts +17 -1
  160. package/dist/types/meeting/request.type.d.ts +5 -0
  161. package/dist/types/meeting/util.d.ts +40 -0
  162. package/dist/types/meeting-info/util.d.ts +1 -0
  163. package/dist/types/meeting-info/utilv2.d.ts +1 -0
  164. package/dist/types/meetings/index.d.ts +34 -20
  165. package/dist/types/meetings/meetings.types.d.ts +15 -0
  166. package/dist/types/meetings/request.d.ts +14 -0
  167. package/dist/types/member/index.d.ts +2 -0
  168. package/dist/types/member/types.d.ts +5 -4
  169. package/dist/types/member/util.d.ts +14 -0
  170. package/dist/types/members/index.d.ts +15 -2
  171. package/dist/types/members/util.d.ts +1 -5
  172. package/dist/types/metrics/constants.d.ts +10 -0
  173. package/dist/types/multistream/codec/constants.d.ts +7 -0
  174. package/dist/types/multistream/mediaRequestManager.d.ts +20 -26
  175. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  176. package/dist/types/reachability/clusterReachability.d.ts +33 -6
  177. package/dist/types/reachability/index.d.ts +10 -3
  178. package/dist/types/reachability/reachability.types.d.ts +7 -0
  179. package/dist/types/reachability/util.d.ts +17 -0
  180. package/dist/types/reactions/reactions.type.d.ts +4 -0
  181. package/dist/types/recording-controller/util.d.ts +5 -5
  182. package/dist/types/roap/index.d.ts +1 -1
  183. package/dist/types/webinar/utils.d.ts +6 -0
  184. package/dist/webinar/index.js +585 -164
  185. package/dist/webinar/index.js.map +1 -1
  186. package/dist/webinar/utils.js +25 -0
  187. package/dist/webinar/utils.js.map +1 -0
  188. package/package.json +26 -24
  189. package/src/aiEnableRequest/README.md +84 -0
  190. package/src/aiEnableRequest/index.ts +186 -0
  191. package/src/aiEnableRequest/utils.ts +25 -0
  192. package/src/annotation/index.ts +27 -7
  193. package/src/breakouts/breakout.ts +3 -1
  194. package/src/breakouts/index.ts +31 -0
  195. package/src/common/errors/webex-errors.ts +50 -3
  196. package/src/config.ts +7 -2
  197. package/src/constants.ts +49 -3
  198. package/src/controls-options-manager/constants.ts +14 -1
  199. package/src/controls-options-manager/index.ts +87 -28
  200. package/src/controls-options-manager/util.ts +81 -1
  201. package/src/hashTree/constants.ts +26 -0
  202. package/src/hashTree/hashTree.ts +480 -0
  203. package/src/hashTree/hashTreeParser.ts +1911 -29
  204. package/src/hashTree/types.ts +24 -1
  205. package/src/hashTree/utils.ts +98 -0
  206. package/src/index.ts +14 -1
  207. package/src/interceptors/constant.ts +6 -0
  208. package/src/interceptors/dataChannelAuthToken.ts +246 -0
  209. package/src/interceptors/index.ts +2 -1
  210. package/src/interceptors/locusRetry.ts +25 -4
  211. package/src/interceptors/locusRouteToken.ts +22 -5
  212. package/src/interceptors/utils.ts +16 -0
  213. package/src/interpretation/index.ts +29 -11
  214. package/src/interpretation/interpretation.types.ts +11 -0
  215. package/src/locus-info/controlsUtils.ts +20 -1
  216. package/src/locus-info/index.ts +958 -250
  217. package/src/locus-info/infoUtils.ts +41 -6
  218. package/src/locus-info/selfUtils.ts +1 -0
  219. package/src/locus-info/types.ts +51 -12
  220. package/src/media/MediaConnectionAwaiter.ts +62 -5
  221. package/src/media/index.ts +10 -1
  222. package/src/media/properties.ts +4 -1
  223. package/src/meeting/in-meeting-actions.ts +20 -0
  224. package/src/meeting/index.ts +1025 -146
  225. package/src/meeting/locusMediaRequest.ts +106 -6
  226. package/src/meeting/muteState.ts +10 -1
  227. package/src/meeting/request.ts +53 -0
  228. package/src/meeting/request.type.ts +6 -0
  229. package/src/meeting/util.ts +207 -7
  230. package/src/meeting-info/meeting-info-v2.ts +4 -2
  231. package/src/meetings/index.ts +307 -132
  232. package/src/meetings/meetings.types.ts +19 -0
  233. package/src/meetings/request.ts +43 -0
  234. package/src/meetings/util.ts +127 -13
  235. package/src/member/index.ts +20 -0
  236. package/src/member/types.ts +1 -0
  237. package/src/member/util.ts +41 -0
  238. package/src/members/index.ts +70 -7
  239. package/src/members/util.ts +12 -4
  240. package/src/metrics/constants.ts +11 -0
  241. package/src/multistream/codec/constants.ts +58 -0
  242. package/src/multistream/mediaRequestManager.ts +117 -76
  243. package/src/multistream/receiveSlot.ts +18 -0
  244. package/src/multistream/remoteMediaManager.ts +13 -0
  245. package/src/multistream/sendSlotManager.ts +97 -3
  246. package/src/reachability/clusterReachability.ts +156 -29
  247. package/src/reachability/index.ts +62 -17
  248. package/src/reachability/reachability.types.ts +11 -0
  249. package/src/reachability/reachabilityPeerConnection.ts +3 -1
  250. package/src/reachability/util.ts +36 -0
  251. package/src/reactions/reactions.type.ts +4 -0
  252. package/src/reconnection-manager/index.ts +0 -1
  253. package/src/recording-controller/index.ts +1 -2
  254. package/src/webinar/index.ts +448 -11
  255. package/src/webinar/utils.ts +16 -0
  256. package/test/unit/spec/aiEnableRequest/index.ts +1067 -0
  257. package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
  258. package/test/unit/spec/annotation/index.ts +69 -7
  259. package/test/unit/spec/breakouts/breakout.ts +9 -3
  260. package/test/unit/spec/breakouts/index.ts +49 -0
  261. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  262. package/test/unit/spec/controls-options-manager/index.js +244 -29
  263. package/test/unit/spec/controls-options-manager/util.js +165 -0
  264. package/test/unit/spec/hashTree/hashTree.ts +721 -0
  265. package/test/unit/spec/hashTree/hashTreeParser.ts +5328 -0
  266. package/test/unit/spec/hashTree/utils.ts +264 -0
  267. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +406 -0
  268. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  269. package/test/unit/spec/interceptors/locusRouteToken.ts +44 -0
  270. package/test/unit/spec/interceptors/utils.ts +75 -0
  271. package/test/unit/spec/interpretation/index.ts +26 -4
  272. package/test/unit/spec/locus-info/controlsUtils.js +222 -52
  273. package/test/unit/spec/locus-info/index.js +2000 -171
  274. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  275. package/test/unit/spec/media/MediaConnectionAwaiter.ts +96 -1
  276. package/test/unit/spec/media/index.ts +92 -0
  277. package/test/unit/spec/media/properties.ts +12 -3
  278. package/test/unit/spec/meeting/in-meeting-actions.ts +12 -2
  279. package/test/unit/spec/meeting/index.js +2925 -209
  280. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  281. package/test/unit/spec/meeting/muteState.js +81 -0
  282. package/test/unit/spec/meeting/request.js +82 -0
  283. package/test/unit/spec/meeting/utils.js +595 -27
  284. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  285. package/test/unit/spec/meetings/index.js +1214 -75
  286. package/test/unit/spec/meetings/request.js +141 -0
  287. package/test/unit/spec/meetings/utils.js +453 -52
  288. package/test/unit/spec/member/index.js +35 -4
  289. package/test/unit/spec/member/util.js +154 -27
  290. package/test/unit/spec/members/index.js +216 -0
  291. package/test/unit/spec/members/request.js +37 -1
  292. package/test/unit/spec/members/utils.js +63 -0
  293. package/test/unit/spec/multistream/mediaRequestManager.ts +503 -122
  294. package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
  295. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  296. package/test/unit/spec/reachability/clusterReachability.ts +125 -1
  297. package/test/unit/spec/reachability/index.ts +154 -49
  298. package/test/unit/spec/reachability/util.ts +31 -0
  299. package/test/unit/spec/reconnection-manager/index.js +4 -8
  300. package/test/unit/spec/recording-controller/index.js +9 -8
  301. package/test/unit/spec/webinar/index.ts +837 -39
  302. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -0,0 +1,264 @@
1
+ import {HashTreeObject, ObjectType} from '../../../../src/hashTree/types';
2
+ import {
3
+ deleteNestedObjectsWithHtMeta,
4
+ isSelf,
5
+ sleep,
6
+ sortByInitPriority,
7
+ } from '../../../../src/hashTree/utils';
8
+ import {DataSetNames, DATA_SET_INIT_PRIORITY} from '../../../../src/hashTree/constants';
9
+ import sinon from 'sinon';
10
+
11
+ import {assert} from '@webex/test-helper-chai';
12
+
13
+ describe('Hash Tree Utils', () => {
14
+ describe('#deleteNestedObjectsWithHtMeta', () => {
15
+ it('should delete nested objects with htMeta', () => {
16
+ const locusPart = {
17
+ a: {
18
+ htMeta: {
19
+ id: '1',
20
+ },
21
+ value: 'to be deleted',
22
+ },
23
+ b: {
24
+ c: {
25
+ htMeta: {
26
+ id: '2',
27
+ },
28
+ value: 'to be deleted',
29
+ },
30
+ d: 'to be kept',
31
+ },
32
+ e: [
33
+ {
34
+ htMeta: {
35
+ id: '3',
36
+ },
37
+ value: 'to be deleted',
38
+ },
39
+ {
40
+ f: 'to be kept',
41
+ },
42
+ {
43
+ htMeta: {
44
+ id: '4',
45
+ },
46
+ value: 'to be deleted',
47
+ },
48
+ {
49
+ g: 'to be kept',
50
+ },
51
+ ],
52
+ };
53
+
54
+ deleteNestedObjectsWithHtMeta(locusPart);
55
+
56
+ assert.deepEqual(locusPart, {
57
+ b: {
58
+ d: 'to be kept',
59
+ },
60
+ e: [
61
+ {
62
+ f: 'to be kept',
63
+ },
64
+ {
65
+ g: 'to be kept',
66
+ },
67
+ ],
68
+ });
69
+ });
70
+
71
+ it('should handle arrays correctly', () => {
72
+ const locusPart = {
73
+ htMeta: {
74
+ id: '0', // this should not be deleted
75
+ },
76
+ participants: [
77
+ {
78
+ htMeta: {
79
+ id: '1',
80
+ },
81
+ id: 'participant1',
82
+ value: 'to be deleted',
83
+ },
84
+ {
85
+ htMeta: {
86
+ id: '2',
87
+ },
88
+ id: 'participant2',
89
+ value: 'to be deleted',
90
+ },
91
+ ],
92
+ self: {
93
+ htMeta: {
94
+ id: '3',
95
+ },
96
+ id: 'self1',
97
+ value: 'to be deleted',
98
+ },
99
+ };
100
+
101
+ deleteNestedObjectsWithHtMeta(locusPart);
102
+
103
+ assert.deepEqual(locusPart, {
104
+ htMeta: {
105
+ id: '0',
106
+ },
107
+ participants: [],
108
+ });
109
+ });
110
+ });
111
+
112
+ describe('#isSelf', () => {
113
+ ['self', 'SELF', 'Self'].forEach((type) => {
114
+ it(`should return true for object with type="${type}"`, () => {
115
+ const selfObject = {
116
+ htMeta: {
117
+ elementId: {
118
+ type,
119
+ id: 1,
120
+ version: 1,
121
+ },
122
+ dataSetNames: [],
123
+ },
124
+ data: {},
125
+ };
126
+
127
+ assert.isTrue(isSelf(selfObject as HashTreeObject));
128
+ });
129
+ });
130
+
131
+ it('should return false for non-self object', () => {
132
+ const participantObject = {
133
+ htMeta: {
134
+ elementId: {
135
+ type: ObjectType.participant,
136
+ id: 2,
137
+ version: 1,
138
+ },
139
+ dataSetNames: [],
140
+ },
141
+ data: {},
142
+ };
143
+
144
+ assert.isFalse(isSelf(participantObject));
145
+ });
146
+ });
147
+
148
+ describe('#sortByInitPriority', () => {
149
+ [
150
+ {
151
+ description: 'places "main" and "self" first when both appear',
152
+ input: ['atd-active', 'main', 'atd-unmuted', 'self'],
153
+ expected: ['main', 'self', 'atd-active', 'atd-unmuted'],
154
+ },
155
+ {
156
+ description: 'preserves original order of non-priority items',
157
+ input: ['atd-unmuted', 'atd-active', 'self'],
158
+ expected: ['self', 'atd-unmuted', 'atd-active'],
159
+ },
160
+ {
161
+ description: 'returns items unchanged when no priority items present',
162
+ input: ['atd-active', 'atd-unmuted'],
163
+ expected: ['atd-active', 'atd-unmuted'],
164
+ },
165
+ {
166
+ description: 'reorders when only priority items present',
167
+ input: ['self', 'main'],
168
+ expected: ['main', 'self'],
169
+ },
170
+ {
171
+ description: 'handles empty list',
172
+ input: [],
173
+ expected: [],
174
+ },
175
+ {
176
+ description: 'handles only some priority items present',
177
+ input: ['atd-active', 'main'],
178
+ expected: ['main', 'atd-active'],
179
+ },
180
+ {
181
+ description: 'handles single non-priority item',
182
+ input: ['atd-active'],
183
+ expected: ['atd-active'],
184
+ },
185
+ {
186
+ description: 'handles single priority item',
187
+ input: ['self'],
188
+ expected: ['self'],
189
+ },
190
+ ].forEach(({description, input, expected}) => {
191
+ it(description, () => {
192
+ const items = input.map((name) => ({name}));
193
+
194
+ const result = sortByInitPriority(items, DATA_SET_INIT_PRIORITY);
195
+
196
+ assert.deepEqual(
197
+ result.map((i) => i.name),
198
+ expected
199
+ );
200
+ });
201
+ });
202
+
203
+ it('should not mutate the original array', () => {
204
+ const items = [{name: DataSetNames.ATD_ACTIVE}, {name: DataSetNames.SELF}];
205
+ const originalOrder = items.map((i) => i.name);
206
+
207
+ sortByInitPriority(items, DATA_SET_INIT_PRIORITY);
208
+
209
+ assert.deepEqual(
210
+ items.map((i) => i.name),
211
+ originalOrder
212
+ );
213
+ });
214
+
215
+ it('should preserve extra properties on items', () => {
216
+ const items = [
217
+ {name: DataSetNames.ATD_ACTIVE, url: 'url1'},
218
+ {name: DataSetNames.SELF, url: 'url2'},
219
+ ];
220
+
221
+ const result = sortByInitPriority(items, DATA_SET_INIT_PRIORITY);
222
+
223
+ assert.deepEqual(result, [
224
+ {name: DataSetNames.SELF, url: 'url2'},
225
+ {name: DataSetNames.ATD_ACTIVE, url: 'url1'},
226
+ ]);
227
+ });
228
+ });
229
+
230
+ describe('#sleep', () => {
231
+ let clock;
232
+
233
+ beforeEach(() => {
234
+ clock = sinon.useFakeTimers();
235
+ });
236
+
237
+ afterEach(() => {
238
+ clock.restore();
239
+ });
240
+
241
+ [0, -1, -100].forEach((ms) => {
242
+ it(`resolves immediately when ms is ${ms}`, async () => {
243
+ const result = sleep(ms);
244
+
245
+ assert.instanceOf(result, Promise);
246
+ await result;
247
+ });
248
+ });
249
+
250
+ it('resolves after the specified delay', async () => {
251
+ let resolved = false;
252
+
253
+ sleep(500).then(() => { resolved = true; });
254
+
255
+ assert.isFalse(resolved);
256
+
257
+ await clock.tickAsync(499);
258
+ assert.isFalse(resolved);
259
+
260
+ await clock.tickAsync(1);
261
+ assert.isTrue(resolved);
262
+ });
263
+ });
264
+ });
@@ -0,0 +1,406 @@
1
+ import 'jsdom-global/register';
2
+ import {assert, expect} from '@webex/test-helper-chai';
3
+ import sinon from 'sinon';
4
+ import MockWebex from '@webex/test-helper-mock-webex';
5
+ import {WebexHttpError} from '@webex/webex-core';
6
+ import DataChannelAuthTokenInterceptor from '@webex/plugin-meetings/src/interceptors/dataChannelAuthToken';
7
+ import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
8
+ import * as utils from '@webex/plugin-meetings/src/interceptors/utils';
9
+ import {DATA_CHANNEL_AUTH_HEADER, MAX_RETRY} from '@webex/plugin-meetings/src/interceptors/constant';
10
+ import {LOCUS_URL} from '@webex/plugin-meetings/src/constants';
11
+
12
+ describe('plugin-meetings', () => {
13
+ describe('Interceptors', () => {
14
+ describe('DataChannelAuthTokenInterceptor', () => {
15
+ let interceptor, webex, clock;
16
+
17
+ beforeEach(() => {
18
+ clock = sinon.useFakeTimers();
19
+ sinon.stub(LoggerProxy, 'logger').value({
20
+ error: sinon.stub(),
21
+ warn: sinon.stub(),
22
+ });
23
+
24
+ webex = new MockWebex({children: {}});
25
+ webex.request = sinon.stub().resolves({});
26
+
27
+ interceptor = Reflect.apply(DataChannelAuthTokenInterceptor.create, webex, []);
28
+
29
+ interceptor._refreshDataChannelToken = sinon.stub();
30
+ interceptor._isDataChannelTokenEnabled = sinon.stub().resolves(true);
31
+ });
32
+
33
+ afterEach(() => {
34
+ sinon.restore();
35
+ clock.restore();
36
+ });
37
+
38
+ const makeReason = (statusCode) =>
39
+ new WebexHttpError({
40
+ statusCode,
41
+ options: {headers: {}, uri: 'https://example.com'},
42
+ body: {},
43
+ });
44
+
45
+ describe('#onResponseError', () => {
46
+ it('rejects when no Data-Channel-Auth-Token header exists', async () => {
47
+ const options = {headers: {}};
48
+ const reason = makeReason(401);
49
+
50
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
51
+ });
52
+
53
+ it('rejects when statusCode is not 401/403', async () => {
54
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
55
+ const reason = makeReason(500);
56
+
57
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
58
+ });
59
+
60
+ it('rejects when retry count exceeds MAX_RETRY', async () => {
61
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
62
+ const reason = makeReason(401);
63
+
64
+ for (let i = 0; i < MAX_RETRY; i++) {
65
+ interceptor.onResponseError(options, reason).catch(() => {});
66
+ }
67
+
68
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
69
+
70
+ sinon.assert.calledOnce(LoggerProxy.logger.error);
71
+ });
72
+
73
+ it('calls refreshTokenAndRetryWithDelay when eligible', async () => {
74
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
75
+ const reason = makeReason(401);
76
+
77
+ interceptor._isDataChannelTokenEnabled.resolves(true);
78
+
79
+ const stub = sinon.stub(interceptor, 'refreshTokenAndRetryWithDelay').resolves('ok');
80
+
81
+ await interceptor.onResponseError(options, reason);
82
+
83
+ sinon.assert.calledOnceWithExactly(stub, options);
84
+ });
85
+
86
+ it('rejects when isDataChannelTokenEnabled is false', async () => {
87
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
88
+ const reason = makeReason(401);
89
+
90
+ interceptor._isDataChannelTokenEnabled.resolves(false);
91
+
92
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
93
+ });
94
+ });
95
+
96
+ describe('#onRequest', () => {
97
+ let isJwtTokenExpiredStub;
98
+
99
+ beforeEach(() => {
100
+ isJwtTokenExpiredStub = sinon.stub(utils, 'isJwtTokenExpired').returns(false);
101
+ });
102
+
103
+ it('does nothing when token is missing', async () => {
104
+ const options = {headers: {}};
105
+
106
+ const res = await interceptor.onRequest(options);
107
+
108
+ expect(res).to.equal(options);
109
+ sinon.assert.notCalled(isJwtTokenExpiredStub);
110
+ });
111
+
112
+ it('does nothing when feature is disabled', async () => {
113
+ interceptor._isDataChannelTokenEnabled.resolves(false);
114
+
115
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
116
+ const res = await interceptor.onRequest(options);
117
+
118
+ expect(res).to.equal(options);
119
+ sinon.assert.notCalled(isJwtTokenExpiredStub);
120
+ });
121
+
122
+ it('does not refresh when token is not expired', async () => {
123
+ interceptor._isDataChannelTokenEnabled.resolves(true);
124
+ isJwtTokenExpiredStub.returns(false);
125
+
126
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
127
+ const res = await interceptor.onRequest(options);
128
+
129
+ sinon.assert.notCalled(interceptor._refreshDataChannelToken);
130
+ expect(res.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('old-token');
131
+ });
132
+
133
+ it('refreshes token when expired', async () => {
134
+ interceptor._isDataChannelTokenEnabled.resolves(true);
135
+ isJwtTokenExpiredStub.returns(true);
136
+
137
+ interceptor._refreshDataChannelToken.resolves('new-token');
138
+
139
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
140
+ const res = await interceptor.onRequest(options);
141
+
142
+ sinon.assert.calledOnce(interceptor._refreshDataChannelToken);
143
+ expect(res.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('new-token');
144
+ });
145
+
146
+ it('continues request when refresh fails', async () => {
147
+ interceptor._isDataChannelTokenEnabled.resolves(true);
148
+ isJwtTokenExpiredStub.returns(true);
149
+
150
+ interceptor._refreshDataChannelToken.rejects(new Error('refresh failed'));
151
+
152
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
153
+ const res = await interceptor.onRequest(options);
154
+
155
+ expect(res.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('old-token');
156
+ });
157
+ });
158
+
159
+ describe('#refreshTokenAndRetryWithDelay', () => {
160
+ const options = {
161
+ headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'},
162
+ method: 'GET',
163
+ uri: 'https://example.com',
164
+ };
165
+
166
+ it('refreshes token and retries request successfully', async () => {
167
+ interceptor._refreshDataChannelToken.resolves('new-token');
168
+ webex.request.resolves('mock-response');
169
+
170
+ const promise = interceptor.refreshTokenAndRetryWithDelay(options);
171
+
172
+ clock.tick(2000);
173
+
174
+ const result = await promise;
175
+
176
+ expect(interceptor._refreshDataChannelToken.calledOnce).to.be.true;
177
+ expect(options.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('new-token');
178
+ expect(webex.request.calledOnceWith(options)).to.be.true;
179
+ expect(result).to.equal('mock-response');
180
+ });
181
+
182
+ it('passes request URL to _refreshDataChannelToken', async () => {
183
+ const psOptions = {
184
+ headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'},
185
+ method: 'POST',
186
+ uri: 'https://locus.example.com/practiceSession/datachannel',
187
+ };
188
+
189
+ interceptor._refreshDataChannelToken.resolves('new-token');
190
+ webex.request.resolves('mock-response');
191
+
192
+ const promise = interceptor.refreshTokenAndRetryWithDelay(psOptions);
193
+
194
+ clock.tick(2000);
195
+
196
+ await promise;
197
+
198
+ sinon.assert.calledOnceWithExactly(
199
+ interceptor._refreshDataChannelToken,
200
+ psOptions.uri
201
+ );
202
+ });
203
+
204
+ it('rejects when refreshDataChannelToken fails', async () => {
205
+ interceptor._refreshDataChannelToken.rejects(new Error('refresh failed'));
206
+
207
+ const promise = interceptor.refreshTokenAndRetryWithDelay(options);
208
+
209
+ clock.tick(2000);
210
+
211
+ await assert.isRejected(
212
+ promise,
213
+ /DataChannel token refresh failed: refresh failed/
214
+ );
215
+ });
216
+
217
+ it('rejects when retry request fails', async () => {
218
+ interceptor._refreshDataChannelToken.resolves('new-token');
219
+ webex.request.rejects(new Error('request failed'));
220
+
221
+ const promise = interceptor.refreshTokenAndRetryWithDelay(options);
222
+
223
+ clock.tick(2000);
224
+
225
+ await assert.isRejected(
226
+ promise,
227
+ /DataChannel token refresh failed: request failed/
228
+ );
229
+ });
230
+ });
231
+
232
+ describe('refreshDataChannelToken routing (factory dispatcher)', () => {
233
+ let llmMock;
234
+ let meetingA;
235
+ let meetingsMock;
236
+ let dispatcherInterceptor;
237
+
238
+ const PS_DATACHANNEL_URL = 'https://board-a.wbx2.com/datachannel/api/v1/locus/cHJhY3RpY2Vfc2Vzc2lvbl9sb2N1cw==/registrations';
239
+ const DEFAULT_DATACHANNEL_URL = 'https://board-a.wbx2.com/datachannel/api/v1/locus/aHR0cHM6Ly9sb2N1cy1hLndieDIuY29t/registrations';
240
+
241
+ beforeEach(() => {
242
+ meetingA = {
243
+ id: 'meeting-a',
244
+ refreshDataChannelToken: sinon.stub().resolves({
245
+ body: {
246
+ datachannelToken: 'token-from-meeting-a',
247
+ dataChannelTokenType: 'llm-practice-session',
248
+ },
249
+ }),
250
+ };
251
+
252
+ llmMock = {
253
+ isDataChannelTokenEnabled: sinon.stub().resolves(true),
254
+ getSessionIdByDatachannelUrl: sinon.stub(),
255
+ getLocusUrlByDatachannelUrl: sinon.stub(),
256
+ getOwnerMeetingId: sinon.stub().returns(undefined),
257
+ refreshDataChannelToken: sinon.stub().resolves({
258
+ body: {
259
+ datachannelToken: 'token-from-llm-fallback',
260
+ dataChannelTokenType: 'llm-default-session',
261
+ },
262
+ }),
263
+ setDatachannelToken: sinon.stub(),
264
+ };
265
+
266
+ meetingsMock = {
267
+ getMeetingByType: sinon.stub(),
268
+ };
269
+
270
+ const context = {
271
+ internal: {llm: llmMock},
272
+ meetings: meetingsMock,
273
+ };
274
+
275
+ dispatcherInterceptor = Reflect.apply(DataChannelAuthTokenInterceptor.create, context, []);
276
+ });
277
+
278
+ it('routes PS request URL to PS session handler', async () => {
279
+ llmMock.getSessionIdByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns('llm-practice-session');
280
+ llmMock.refreshDataChannelToken
281
+ .withArgs('llm-practice-session')
282
+ .resolves({
283
+ body: {
284
+ datachannelToken: 'token-from-ps-session',
285
+ dataChannelTokenType: 'llm-practice-session',
286
+ },
287
+ });
288
+
289
+ const token = await dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL);
290
+
291
+ expect(token).to.equal('token-from-ps-session');
292
+ sinon.assert.calledOnceWithExactly(llmMock.refreshDataChannelToken, 'llm-practice-session');
293
+ sinon.assert.calledOnceWithExactly(
294
+ llmMock.setDatachannelToken,
295
+ 'token-from-ps-session',
296
+ 'llm-practice-session',
297
+ undefined
298
+ );
299
+ });
300
+
301
+ it('routes non-PS URL to default session handler', async () => {
302
+ llmMock.getSessionIdByDatachannelUrl.withArgs(DEFAULT_DATACHANNEL_URL).returns('llm-default-session');
303
+ llmMock.refreshDataChannelToken
304
+ .withArgs('llm-default-session')
305
+ .resolves({
306
+ body: {
307
+ datachannelToken: 'token-from-default-session',
308
+ dataChannelTokenType: 'llm-default-session',
309
+ },
310
+ });
311
+
312
+ const token = await dispatcherInterceptor._refreshDataChannelToken(DEFAULT_DATACHANNEL_URL);
313
+
314
+ expect(token).to.equal('token-from-default-session');
315
+ sinon.assert.calledOnceWithExactly(llmMock.refreshDataChannelToken, 'llm-default-session');
316
+ sinon.assert.calledOnceWithExactly(
317
+ llmMock.setDatachannelToken,
318
+ 'token-from-default-session',
319
+ 'llm-default-session',
320
+ undefined
321
+ );
322
+ });
323
+
324
+ it('falls back to default refresh when URL does not match any session or meeting route', async () => {
325
+ llmMock.getSessionIdByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns(undefined);
326
+ llmMock.getLocusUrlByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns(undefined);
327
+ llmMock.refreshDataChannelToken.withArgs(undefined).resolves({
328
+ body: {
329
+ datachannelToken: 'token-from-default-fallback',
330
+ dataChannelTokenType: 'llm-default-session',
331
+ },
332
+ });
333
+
334
+ const token = await dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL);
335
+
336
+ expect(token).to.equal('token-from-default-fallback');
337
+ sinon.assert.calledOnceWithExactly(llmMock.refreshDataChannelToken, undefined);
338
+ sinon.assert.calledOnceWithExactly(
339
+ llmMock.setDatachannelToken,
340
+ 'token-from-default-fallback',
341
+ 'llm-default-session',
342
+ undefined
343
+ );
344
+ });
345
+
346
+ it('falls back to meeting lookup by locusUrl when session cannot be resolved', async () => {
347
+ llmMock.getSessionIdByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns(undefined);
348
+ llmMock.getLocusUrlByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns('https://locus-a.example.com');
349
+ meetingsMock.getMeetingByType.withArgs(LOCUS_URL, 'https://locus-a.example.com').returns(meetingA);
350
+
351
+ const token = await dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL);
352
+
353
+ expect(token).to.equal('token-from-meeting-a');
354
+ sinon.assert.calledOnceWithExactly(meetingA.refreshDataChannelToken);
355
+ sinon.assert.notCalled(llmMock.refreshDataChannelToken);
356
+ sinon.assert.calledOnceWithExactly(
357
+ llmMock.setDatachannelToken,
358
+ 'token-from-meeting-a',
359
+ 'llm-practice-session',
360
+ 'meeting-a'
361
+ );
362
+ });
363
+
364
+ it('falls back to active meeting datachannel URL lookup when session/locus routing is unavailable', async () => {
365
+ llmMock.getSessionIdByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns(undefined);
366
+ llmMock.getLocusUrlByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns(undefined);
367
+ meetingsMock.getAllMeetings = sinon.stub().returns({
368
+ 'meeting-a': {
369
+ ...meetingA,
370
+ locusInfo: {
371
+ info: {
372
+ practiceSessionDatachannelUrl: PS_DATACHANNEL_URL,
373
+ datachannelUrl: DEFAULT_DATACHANNEL_URL,
374
+ },
375
+ },
376
+ },
377
+ });
378
+
379
+ const token = await dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL);
380
+
381
+ expect(token).to.equal('token-from-meeting-a');
382
+ sinon.assert.calledOnceWithExactly(meetingA.refreshDataChannelToken);
383
+ sinon.assert.notCalled(llmMock.refreshDataChannelToken);
384
+ sinon.assert.calledOnceWithExactly(
385
+ llmMock.setDatachannelToken,
386
+ 'token-from-meeting-a',
387
+ 'llm-practice-session',
388
+ 'meeting-a'
389
+ );
390
+ });
391
+
392
+ it('throws when refresh returns no payload', async () => {
393
+ llmMock.getSessionIdByDatachannelUrl.returns('llm-default-session');
394
+ llmMock.refreshDataChannelToken.withArgs('llm-default-session').resolves(null);
395
+
396
+ await assert.isRejected(
397
+ dispatcherInterceptor._refreshDataChannelToken(
398
+ 'https://unknown-datachannel.example.com/registrations'
399
+ ),
400
+ /DataChannel token refresh returned no payload/
401
+ );
402
+ });
403
+ });
404
+ });
405
+ });
406
+ });