@webex/plugin-meetings 3.11.0 → 3.12.0-llmrefactor.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 (294) 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 +58 -13
  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 +124 -7
  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 +332 -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 +914 -212
  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 +2287 -1118
  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/annotation/index.d.ts +19 -0
  130. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  131. package/dist/types/config.d.ts +6 -2
  132. package/dist/types/constants.d.ts +35 -1
  133. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  134. package/dist/types/controls-options-manager/index.d.ts +16 -0
  135. package/dist/types/hashTree/constants.d.ts +3 -0
  136. package/dist/types/hashTree/hashTree.d.ts +7 -0
  137. package/dist/types/hashTree/hashTreeParser.d.ts +315 -30
  138. package/dist/types/hashTree/types.d.ts +3 -0
  139. package/dist/types/hashTree/utils.d.ts +24 -0
  140. package/dist/types/index.d.ts +4 -0
  141. package/dist/types/interceptors/constant.d.ts +5 -0
  142. package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
  143. package/dist/types/interceptors/index.d.ts +2 -1
  144. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  145. package/dist/types/interceptors/utils.d.ts +1 -0
  146. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  147. package/dist/types/locus-info/index.d.ts +126 -15
  148. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  149. package/dist/types/locus-info/types.d.ts +28 -1
  150. package/dist/types/media/MediaConnectionAwaiter.d.ts +20 -2
  151. package/dist/types/media/properties.d.ts +8 -3
  152. package/dist/types/meeting/in-meeting-actions.d.ts +10 -0
  153. package/dist/types/meeting/index.d.ts +271 -16
  154. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  155. package/dist/types/meeting/request.d.ts +17 -1
  156. package/dist/types/meeting/request.type.d.ts +5 -0
  157. package/dist/types/meeting/util.d.ts +40 -0
  158. package/dist/types/meetings/index.d.ts +42 -20
  159. package/dist/types/meetings/meetings.types.d.ts +15 -0
  160. package/dist/types/meetings/request.d.ts +14 -0
  161. package/dist/types/member/index.d.ts +2 -0
  162. package/dist/types/member/types.d.ts +1 -0
  163. package/dist/types/member/util.d.ts +14 -0
  164. package/dist/types/members/index.d.ts +15 -2
  165. package/dist/types/members/util.d.ts +1 -5
  166. package/dist/types/metrics/constants.d.ts +11 -0
  167. package/dist/types/multistream/codec/constants.d.ts +7 -0
  168. package/dist/types/multistream/mediaRequestManager.d.ts +20 -26
  169. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  170. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  171. package/dist/types/reachability/index.d.ts +10 -3
  172. package/dist/types/reachability/reachability.types.d.ts +7 -0
  173. package/dist/types/reachability/util.d.ts +17 -0
  174. package/dist/types/reactions/reactions.type.d.ts +4 -0
  175. package/dist/types/webinar/utils.d.ts +6 -0
  176. package/dist/webinar/index.js +611 -164
  177. package/dist/webinar/index.js.map +1 -1
  178. package/dist/webinar/utils.js +25 -0
  179. package/dist/webinar/utils.js.map +1 -0
  180. package/package.json +24 -23
  181. package/src/aiEnableRequest/README.md +84 -0
  182. package/src/aiEnableRequest/index.ts +186 -0
  183. package/src/aiEnableRequest/utils.ts +25 -0
  184. package/src/annotation/index.ts +62 -12
  185. package/src/breakouts/breakout.ts +3 -1
  186. package/src/breakouts/events.ts +33 -11
  187. package/src/breakouts/index.ts +143 -3
  188. package/src/common/errors/webex-errors.ts +50 -3
  189. package/src/config.ts +6 -2
  190. package/src/constants.ts +49 -3
  191. package/src/controls-options-manager/constants.ts +14 -1
  192. package/src/controls-options-manager/index.ts +87 -28
  193. package/src/controls-options-manager/util.ts +81 -1
  194. package/src/hashTree/constants.ts +17 -0
  195. package/src/hashTree/hashTree.ts +17 -0
  196. package/src/hashTree/hashTreeParser.ts +1482 -361
  197. package/src/hashTree/types.ts +4 -0
  198. package/src/hashTree/utils.ts +45 -0
  199. package/src/index.ts +14 -1
  200. package/src/interceptors/constant.ts +6 -0
  201. package/src/interceptors/dataChannelAuthToken.ts +217 -0
  202. package/src/interceptors/index.ts +2 -1
  203. package/src/interceptors/locusRetry.ts +25 -4
  204. package/src/interceptors/utils.ts +16 -0
  205. package/src/interpretation/index.ts +29 -11
  206. package/src/interpretation/interpretation.types.ts +11 -0
  207. package/src/locus-info/controlsUtils.ts +14 -1
  208. package/src/locus-info/index.ts +976 -203
  209. package/src/locus-info/infoUtils.ts +41 -6
  210. package/src/locus-info/selfUtils.ts +1 -0
  211. package/src/locus-info/types.ts +33 -1
  212. package/src/media/MediaConnectionAwaiter.ts +62 -5
  213. package/src/media/index.ts +10 -1
  214. package/src/media/properties.ts +11 -4
  215. package/src/meeting/in-meeting-actions.ts +20 -0
  216. package/src/meeting/index.ts +1258 -222
  217. package/src/meeting/locusMediaRequest.ts +106 -6
  218. package/src/meeting/muteState.ts +10 -1
  219. package/src/meeting/request.ts +53 -0
  220. package/src/meeting/request.type.ts +6 -0
  221. package/src/meeting/util.ts +207 -7
  222. package/src/meeting-info/meeting-info-v2.ts +4 -2
  223. package/src/meetings/index.ts +319 -117
  224. package/src/meetings/meetings.types.ts +19 -0
  225. package/src/meetings/request.ts +43 -0
  226. package/src/meetings/util.ts +117 -4
  227. package/src/member/index.ts +20 -0
  228. package/src/member/types.ts +1 -0
  229. package/src/member/util.ts +41 -0
  230. package/src/members/index.ts +70 -7
  231. package/src/members/util.ts +12 -4
  232. package/src/metrics/constants.ts +12 -0
  233. package/src/multistream/codec/constants.ts +58 -0
  234. package/src/multistream/mediaRequestManager.ts +117 -76
  235. package/src/multistream/receiveSlot.ts +18 -0
  236. package/src/multistream/remoteMediaManager.ts +13 -0
  237. package/src/multistream/sendSlotManager.ts +97 -3
  238. package/src/reachability/clusterReachability.ts +3 -2
  239. package/src/reachability/index.ts +56 -16
  240. package/src/reachability/reachability.types.ts +11 -0
  241. package/src/reachability/util.ts +36 -0
  242. package/src/reactions/reactions.type.ts +4 -0
  243. package/src/reconnection-manager/index.ts +0 -1
  244. package/src/recording-controller/index.ts +1 -2
  245. package/src/roap/turnDiscovery.ts +9 -1
  246. package/src/webinar/index.ts +415 -11
  247. package/src/webinar/utils.ts +16 -0
  248. package/test/unit/spec/aiEnableRequest/index.ts +1067 -0
  249. package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
  250. package/test/unit/spec/annotation/index.ts +228 -134
  251. package/test/unit/spec/breakouts/breakout.ts +9 -3
  252. package/test/unit/spec/breakouts/events.ts +120 -2
  253. package/test/unit/spec/breakouts/index.ts +305 -18
  254. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  255. package/test/unit/spec/controls-options-manager/index.js +244 -29
  256. package/test/unit/spec/controls-options-manager/util.js +165 -0
  257. package/test/unit/spec/hashTree/hashTree.ts +66 -0
  258. package/test/unit/spec/hashTree/hashTreeParser.ts +4528 -171
  259. package/test/unit/spec/hashTree/utils.ts +125 -1
  260. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +388 -0
  261. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  262. package/test/unit/spec/interceptors/utils.ts +75 -0
  263. package/test/unit/spec/interpretation/index.ts +26 -4
  264. package/test/unit/spec/locus-info/controlsUtils.js +200 -56
  265. package/test/unit/spec/locus-info/index.js +1861 -149
  266. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  267. package/test/unit/spec/media/MediaConnectionAwaiter.ts +96 -1
  268. package/test/unit/spec/media/index.ts +92 -0
  269. package/test/unit/spec/media/properties.ts +35 -26
  270. package/test/unit/spec/meeting/in-meeting-actions.ts +12 -2
  271. package/test/unit/spec/meeting/index.js +3694 -450
  272. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  273. package/test/unit/spec/meeting/muteState.js +81 -0
  274. package/test/unit/spec/meeting/request.js +82 -0
  275. package/test/unit/spec/meeting/utils.js +595 -27
  276. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  277. package/test/unit/spec/meetings/index.js +1138 -86
  278. package/test/unit/spec/meetings/request.js +141 -0
  279. package/test/unit/spec/meetings/utils.js +402 -51
  280. package/test/unit/spec/member/index.js +35 -4
  281. package/test/unit/spec/member/util.js +154 -27
  282. package/test/unit/spec/members/index.js +216 -0
  283. package/test/unit/spec/members/request.js +37 -1
  284. package/test/unit/spec/members/utils.js +63 -0
  285. package/test/unit/spec/multistream/mediaRequestManager.ts +503 -122
  286. package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
  287. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  288. package/test/unit/spec/reachability/index.ts +151 -46
  289. package/test/unit/spec/reachability/util.ts +31 -0
  290. package/test/unit/spec/reconnection-manager/index.js +4 -8
  291. package/test/unit/spec/recording-controller/index.js +9 -8
  292. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  293. package/test/unit/spec/webinar/index.ts +1087 -167
  294. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -1,5 +1,12 @@
1
1
  import {HashTreeObject, ObjectType} from '../../../../src/hashTree/types';
2
- import {deleteNestedObjectsWithHtMeta, isSelf} from '../../../../src/hashTree/utils';
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';
3
10
 
4
11
  import {assert} from '@webex/test-helper-chai';
5
12
 
@@ -137,4 +144,121 @@ describe('Hash Tree Utils', () => {
137
144
  assert.isFalse(isSelf(participantObject));
138
145
  });
139
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
+ });
140
264
  });
@@ -0,0 +1,388 @@
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 {
10
+ DATA_CHANNEL_AUTH_HEADER,
11
+ MAX_RETRY,
12
+ } from '@webex/plugin-meetings/src/interceptors/constant';
13
+
14
+ describe('plugin-meetings', () => {
15
+ describe('Interceptors', () => {
16
+ describe('DataChannelAuthTokenInterceptor', () => {
17
+ let interceptor, webex, clock;
18
+
19
+ beforeEach(() => {
20
+ clock = sinon.useFakeTimers();
21
+ sinon.stub(LoggerProxy, 'logger').value({
22
+ error: sinon.stub(),
23
+ warn: sinon.stub(),
24
+ });
25
+
26
+ webex = new MockWebex({children: {}});
27
+ webex.request = sinon.stub().resolves({});
28
+
29
+ interceptor = Reflect.apply(DataChannelAuthTokenInterceptor.create, webex, []);
30
+
31
+ interceptor._refreshDataChannelToken = sinon.stub();
32
+ interceptor._isDataChannelTokenEnabled = sinon.stub().resolves(true);
33
+ });
34
+
35
+ afterEach(() => {
36
+ sinon.restore();
37
+ clock.restore();
38
+ });
39
+
40
+ const makeReason = (statusCode) =>
41
+ new WebexHttpError({
42
+ statusCode,
43
+ options: {headers: {}, uri: 'https://example.com'},
44
+ body: {},
45
+ });
46
+
47
+ describe('#onResponseError', () => {
48
+ it('rejects when no Data-Channel-Auth-Token header exists', async () => {
49
+ const options = {headers: {}};
50
+ const reason = makeReason(401);
51
+
52
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
53
+ });
54
+
55
+ it('rejects when statusCode is not 401/403', async () => {
56
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
57
+ const reason = makeReason(500);
58
+
59
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
60
+ });
61
+
62
+ it('rejects when retry count exceeds MAX_RETRY', async () => {
63
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
64
+ const reason = makeReason(401);
65
+
66
+ for (let i = 0; i < MAX_RETRY; i++) {
67
+ interceptor.onResponseError(options, reason).catch(() => {});
68
+ }
69
+
70
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
71
+
72
+ sinon.assert.calledOnce(LoggerProxy.logger.error);
73
+ });
74
+
75
+ it('calls refreshTokenAndRetryWithDelay when eligible', async () => {
76
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
77
+ const reason = makeReason(401);
78
+
79
+ interceptor._isDataChannelTokenEnabled.resolves(true);
80
+
81
+ const stub = sinon.stub(interceptor, 'refreshTokenAndRetryWithDelay').resolves('ok');
82
+
83
+ await interceptor.onResponseError(options, reason);
84
+
85
+ sinon.assert.calledOnceWithExactly(stub, options);
86
+ });
87
+
88
+ it('rejects when isDataChannelTokenEnabled is false', async () => {
89
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'abc'}};
90
+ const reason = makeReason(401);
91
+
92
+ interceptor._isDataChannelTokenEnabled.resolves(false);
93
+
94
+ await assert.isRejected(interceptor.onResponseError(options, reason), reason);
95
+ });
96
+ });
97
+
98
+ describe('#onRequest', () => {
99
+ let isJwtTokenExpiredStub;
100
+
101
+ beforeEach(() => {
102
+ isJwtTokenExpiredStub = sinon.stub(utils, 'isJwtTokenExpired').returns(false);
103
+ });
104
+
105
+ it('does nothing when token is missing', async () => {
106
+ const options = {headers: {}};
107
+
108
+ const res = await interceptor.onRequest(options);
109
+
110
+ expect(res).to.equal(options);
111
+ sinon.assert.notCalled(isJwtTokenExpiredStub);
112
+ });
113
+
114
+ it('does nothing when feature is disabled', async () => {
115
+ interceptor._isDataChannelTokenEnabled.resolves(false);
116
+
117
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
118
+ const res = await interceptor.onRequest(options);
119
+
120
+ expect(res).to.equal(options);
121
+ sinon.assert.notCalled(isJwtTokenExpiredStub);
122
+ });
123
+
124
+ it('does not refresh when token is not expired', async () => {
125
+ interceptor._isDataChannelTokenEnabled.resolves(true);
126
+ isJwtTokenExpiredStub.returns(false);
127
+
128
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
129
+ const res = await interceptor.onRequest(options);
130
+
131
+ sinon.assert.notCalled(interceptor._refreshDataChannelToken);
132
+ expect(res.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('old-token');
133
+ });
134
+
135
+ it('refreshes token when expired', async () => {
136
+ interceptor._isDataChannelTokenEnabled.resolves(true);
137
+ isJwtTokenExpiredStub.returns(true);
138
+
139
+ interceptor._refreshDataChannelToken.resolves('new-token');
140
+
141
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
142
+ const res = await interceptor.onRequest(options);
143
+
144
+ sinon.assert.calledOnce(interceptor._refreshDataChannelToken);
145
+ expect(res.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('new-token');
146
+ });
147
+
148
+ it('continues request when refresh fails', async () => {
149
+ interceptor._isDataChannelTokenEnabled.resolves(true);
150
+ isJwtTokenExpiredStub.returns(true);
151
+
152
+ interceptor._refreshDataChannelToken.rejects(new Error('refresh failed'));
153
+
154
+ const options = {headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'}};
155
+ const res = await interceptor.onRequest(options);
156
+
157
+ expect(res.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('old-token');
158
+ });
159
+ });
160
+
161
+ describe('#refreshTokenAndRetryWithDelay', () => {
162
+ const options = {
163
+ headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'},
164
+ method: 'GET',
165
+ uri: 'https://example.com',
166
+ };
167
+
168
+ it('refreshes token and retries request successfully', async () => {
169
+ interceptor._refreshDataChannelToken.resolves('new-token');
170
+ webex.request.resolves('mock-response');
171
+
172
+ const promise = interceptor.refreshTokenAndRetryWithDelay(options);
173
+
174
+ clock.tick(2000);
175
+
176
+ const result = await promise;
177
+
178
+ expect(interceptor._refreshDataChannelToken.calledOnce).to.be.true;
179
+ expect(options.headers[DATA_CHANNEL_AUTH_HEADER]).to.equal('new-token');
180
+ expect(webex.request.calledOnceWith(options)).to.be.true;
181
+ expect(result).to.equal('mock-response');
182
+ });
183
+
184
+ it('passes request URL to _refreshDataChannelToken', async () => {
185
+ const psOptions = {
186
+ headers: {[DATA_CHANNEL_AUTH_HEADER]: 'old-token'},
187
+ method: 'POST',
188
+ uri: 'https://locus.example.com/practiceSession/datachannel',
189
+ };
190
+
191
+ interceptor._refreshDataChannelToken.resolves('new-token');
192
+ webex.request.resolves('mock-response');
193
+
194
+ const promise = interceptor.refreshTokenAndRetryWithDelay(psOptions);
195
+
196
+ clock.tick(2000);
197
+
198
+ await promise;
199
+
200
+ sinon.assert.calledOnceWithExactly(
201
+ interceptor._refreshDataChannelToken,
202
+ psOptions.uri
203
+ );
204
+ });
205
+
206
+ it('rejects when refreshDataChannelToken fails', async () => {
207
+ interceptor._refreshDataChannelToken.rejects(new Error('refresh failed'));
208
+
209
+ const promise = interceptor.refreshTokenAndRetryWithDelay(options);
210
+
211
+ clock.tick(2000);
212
+
213
+ await assert.isRejected(
214
+ promise,
215
+ /DataChannel token refresh failed: refresh failed/
216
+ );
217
+ });
218
+
219
+ it('rejects when retry request fails', async () => {
220
+ interceptor._refreshDataChannelToken.resolves('new-token');
221
+ webex.request.rejects(new Error('request failed'));
222
+
223
+ const promise = interceptor.refreshTokenAndRetryWithDelay(options);
224
+
225
+ clock.tick(2000);
226
+
227
+ await assert.isRejected(
228
+ promise,
229
+ /DataChannel token refresh failed: request failed/
230
+ );
231
+ });
232
+ });
233
+
234
+ describe('refreshDataChannelToken routing (factory dispatcher)', () => {
235
+ let llmMock;
236
+ let meetingA;
237
+ let meetingsMock;
238
+ let dispatcherInterceptor;
239
+
240
+ const PS_DATACHANNEL_URL = 'https://board-a.wbx2.com/datachannel/api/v1/locus/cHJhY3RpY2Vfc2Vzc2lvbl9sb2N1cw==/registrations';
241
+ const DEFAULT_DATACHANNEL_URL = 'https://board-a.wbx2.com/datachannel/api/v1/locus/aHR0cHM6Ly9sb2N1cy1hLndieDIuY29t/registrations';
242
+
243
+ beforeEach(() => {
244
+ meetingA = {
245
+ id: 'meeting-a',
246
+ refreshDataChannelToken: sinon.stub().resolves({
247
+ body: {
248
+ datachannelToken: 'token-from-meeting-a',
249
+ dataChannelTokenType: 'llm-practice-session',
250
+ },
251
+ }),
252
+ setLLMChannelDataToken: sinon.stub(),
253
+ };
254
+
255
+ llmMock = {
256
+ isDataChannelTokenEnabled: sinon.stub().resolves(true),
257
+ getChannelByDatachannelUrl: sinon.stub().returns(undefined),
258
+ };
259
+
260
+ meetingsMock = {
261
+ getAllMeetings: sinon.stub().returns({}),
262
+ };
263
+
264
+ const context = {
265
+ internal: {llm: llmMock},
266
+ meetings: meetingsMock,
267
+ };
268
+
269
+ dispatcherInterceptor = Reflect.apply(DataChannelAuthTokenInterceptor.create, context, []);
270
+ });
271
+
272
+ it('routes request URL to matching channel', async () => {
273
+ const mockChannel = {
274
+ refreshDataChannelToken: sinon.stub().resolves({
275
+ body: {
276
+ datachannelToken: 'token-from-channel',
277
+ dataChannelTokenType: 'llm-practice-session',
278
+ },
279
+ }),
280
+ setDatachannelToken: sinon.stub(),
281
+ };
282
+ llmMock.getChannelByDatachannelUrl.withArgs(PS_DATACHANNEL_URL).returns(mockChannel);
283
+
284
+ const token = await dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL);
285
+
286
+ expect(token).to.equal('token-from-channel');
287
+ sinon.assert.calledOnceWithExactly(
288
+ llmMock.getChannelByDatachannelUrl,
289
+ PS_DATACHANNEL_URL
290
+ );
291
+ sinon.assert.calledOnceWithExactly(mockChannel.refreshDataChannelToken);
292
+ sinon.assert.calledOnceWithExactly(mockChannel.setDatachannelToken, 'token-from-channel');
293
+ });
294
+
295
+ it('falls back to meeting lookup when no channel matches', async () => {
296
+ llmMock.getChannelByDatachannelUrl.returns(undefined);
297
+
298
+ // Import the static method for matching datachannel URLs
299
+ const LLMChannel = require('@webex/internal-plugin-llm').default;
300
+ sinon
301
+ .stub(LLMChannel, 'matchesDatachannelRequestUrl')
302
+ .callsFake((requestUrl, datachannelUrl) => {
303
+ return requestUrl === PS_DATACHANNEL_URL && datachannelUrl === PS_DATACHANNEL_URL;
304
+ });
305
+
306
+ meetingsMock.getAllMeetings.returns({
307
+ 'meeting-a': {
308
+ ...meetingA,
309
+ locusInfo: {
310
+ info: {
311
+ practiceSessionDatachannelUrl: PS_DATACHANNEL_URL,
312
+ datachannelUrl: DEFAULT_DATACHANNEL_URL,
313
+ },
314
+ },
315
+ },
316
+ });
317
+
318
+ const token = await dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL);
319
+
320
+ expect(token).to.equal('token-from-meeting-a');
321
+ sinon.assert.calledOnceWithExactly(meetingA.refreshDataChannelToken);
322
+ sinon.assert.calledOnceWithExactly(
323
+ meetingA.setLLMChannelDataToken,
324
+ 'token-from-meeting-a'
325
+ );
326
+
327
+ LLMChannel.matchesDatachannelRequestUrl.restore();
328
+ });
329
+
330
+ it('throws when no channel or meeting matches', async () => {
331
+ llmMock.getChannelByDatachannelUrl.returns(undefined);
332
+ meetingsMock.getAllMeetings.returns({});
333
+
334
+ await assert.isRejected(
335
+ dispatcherInterceptor._refreshDataChannelToken(
336
+ 'https://unknown-datachannel.example.com/registrations'
337
+ ),
338
+ /No LLM channel or meeting found for request URL/
339
+ );
340
+ });
341
+
342
+ it('throws when channel refresh returns no payload', async () => {
343
+ const mockChannel = {
344
+ refreshDataChannelToken: sinon.stub().resolves(null),
345
+ setDatachannelToken: sinon.stub(),
346
+ };
347
+ llmMock.getChannelByDatachannelUrl.returns(mockChannel);
348
+
349
+ await assert.isRejected(
350
+ dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL),
351
+ /DataChannel token refresh returned no payload/
352
+ );
353
+ });
354
+
355
+ it('throws when meeting refresh returns no payload', async () => {
356
+ llmMock.getChannelByDatachannelUrl.returns(undefined);
357
+
358
+ const LLMChannel = require('@webex/internal-plugin-llm').default;
359
+ sinon.stub(LLMChannel, 'matchesDatachannelRequestUrl').returns(true);
360
+
361
+ const meetingWithNoPayload = {
362
+ id: 'meeting-b',
363
+ refreshDataChannelToken: sinon.stub().resolves(null),
364
+ setLLMChannelDataToken: sinon.stub(),
365
+ };
366
+
367
+ meetingsMock.getAllMeetings.returns({
368
+ 'meeting-b': {
369
+ ...meetingWithNoPayload,
370
+ locusInfo: {
371
+ info: {
372
+ datachannelUrl: PS_DATACHANNEL_URL,
373
+ },
374
+ },
375
+ },
376
+ });
377
+
378
+ await assert.isRejected(
379
+ dispatcherInterceptor._refreshDataChannelToken(PS_DATACHANNEL_URL),
380
+ /DataChannel token refresh returned no payload/
381
+ );
382
+
383
+ LLMChannel.matchesDatachannelRequestUrl.restore();
384
+ });
385
+ });
386
+ });
387
+ });
388
+ });