@webex/plugin-meetings 3.12.0-next.11 → 3.12.0-next.111

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 (235) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +15 -2
  3. package/dist/aiEnableRequest/index.js.map +1 -1
  4. package/dist/breakouts/breakout.js +8 -3
  5. package/dist/breakouts/breakout.js.map +1 -1
  6. package/dist/breakouts/events.js +29 -14
  7. package/dist/breakouts/events.js.map +1 -1
  8. package/dist/breakouts/index.js +90 -3
  9. package/dist/breakouts/index.js.map +1 -1
  10. package/dist/common/errors/webex-errors.js +49 -5
  11. package/dist/common/errors/webex-errors.js.map +1 -1
  12. package/dist/config.js +2 -2
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants.js +37 -10
  15. package/dist/constants.js.map +1 -1
  16. package/dist/controls-options-manager/constants.js +11 -1
  17. package/dist/controls-options-manager/constants.js.map +1 -1
  18. package/dist/controls-options-manager/index.js +67 -29
  19. package/dist/controls-options-manager/index.js.map +1 -1
  20. package/dist/controls-options-manager/util.js +91 -0
  21. package/dist/controls-options-manager/util.js.map +1 -1
  22. package/dist/hashTree/constants.js +4 -1
  23. package/dist/hashTree/constants.js.map +1 -1
  24. package/dist/hashTree/hashTreeParser.js +1003 -393
  25. package/dist/hashTree/hashTreeParser.js.map +1 -1
  26. package/dist/hashTree/utils.js +20 -0
  27. package/dist/hashTree/utils.js.map +1 -1
  28. package/dist/index.js +7 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/interceptors/dataChannelAuthToken.js +75 -15
  31. package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
  32. package/dist/interceptors/locusRetry.js +23 -8
  33. package/dist/interceptors/locusRetry.js.map +1 -1
  34. package/dist/interpretation/index.js +10 -1
  35. package/dist/interpretation/index.js.map +1 -1
  36. package/dist/interpretation/interpretation.types.js +7 -0
  37. package/dist/interpretation/interpretation.types.js.map +1 -0
  38. package/dist/interpretation/siLanguage.js +1 -1
  39. package/dist/locus-info/controlsUtils.js +4 -1
  40. package/dist/locus-info/controlsUtils.js.map +1 -1
  41. package/dist/locus-info/index.js +406 -121
  42. package/dist/locus-info/index.js.map +1 -1
  43. package/dist/locus-info/infoUtils.js +36 -5
  44. package/dist/locus-info/infoUtils.js.map +1 -1
  45. package/dist/locus-info/types.js +19 -0
  46. package/dist/locus-info/types.js.map +1 -1
  47. package/dist/media/MediaConnectionAwaiter.js +15 -2
  48. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  49. package/dist/media/index.js +8 -2
  50. package/dist/media/index.js.map +1 -1
  51. package/dist/media/properties.js +4 -5
  52. package/dist/media/properties.js.map +1 -1
  53. package/dist/meeting/in-meeting-actions.js +5 -1
  54. package/dist/meeting/in-meeting-actions.js.map +1 -1
  55. package/dist/meeting/index.js +1662 -829
  56. package/dist/meeting/index.js.map +1 -1
  57. package/dist/meeting/locusMediaRequest.js +229 -82
  58. package/dist/meeting/locusMediaRequest.js.map +1 -1
  59. package/dist/meeting/muteState.js +10 -1
  60. package/dist/meeting/muteState.js.map +1 -1
  61. package/dist/meeting/request.js +5 -2
  62. package/dist/meeting/request.js.map +1 -1
  63. package/dist/meeting/util.js +34 -2
  64. package/dist/meeting/util.js.map +1 -1
  65. package/dist/meeting-info/meeting-info-v2.js +2 -2
  66. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  67. package/dist/meetings/index.js +256 -118
  68. package/dist/meetings/index.js.map +1 -1
  69. package/dist/meetings/meetings.types.js +6 -1
  70. package/dist/meetings/meetings.types.js.map +1 -1
  71. package/dist/meetings/request.js +39 -0
  72. package/dist/meetings/request.js.map +1 -1
  73. package/dist/meetings/util.js +116 -18
  74. package/dist/meetings/util.js.map +1 -1
  75. package/dist/member/index.js +10 -0
  76. package/dist/member/index.js.map +1 -1
  77. package/dist/member/types.js.map +1 -1
  78. package/dist/member/util.js +30 -0
  79. package/dist/member/util.js.map +1 -1
  80. package/dist/members/index.js +101 -43
  81. package/dist/members/index.js.map +1 -1
  82. package/dist/members/util.js +8 -1
  83. package/dist/members/util.js.map +1 -1
  84. package/dist/metrics/constants.js +7 -1
  85. package/dist/metrics/constants.js.map +1 -1
  86. package/dist/multistream/codec/constants.js +63 -0
  87. package/dist/multistream/codec/constants.js.map +1 -0
  88. package/dist/multistream/mediaRequestManager.js +62 -15
  89. package/dist/multistream/mediaRequestManager.js.map +1 -1
  90. package/dist/multistream/receiveSlot.js +9 -0
  91. package/dist/multistream/receiveSlot.js.map +1 -1
  92. package/dist/reachability/clusterReachability.js.map +1 -1
  93. package/dist/reachability/index.js +121 -83
  94. package/dist/reachability/index.js.map +1 -1
  95. package/dist/reachability/reachability.types.js +2 -0
  96. package/dist/reachability/reachability.types.js.map +1 -1
  97. package/dist/reachability/util.js +45 -0
  98. package/dist/reachability/util.js.map +1 -1
  99. package/dist/reactions/reactions.type.js.map +1 -1
  100. package/dist/recording-controller/index.js +1 -3
  101. package/dist/recording-controller/index.js.map +1 -1
  102. package/dist/roap/turnDiscovery.js +8 -1
  103. package/dist/roap/turnDiscovery.js.map +1 -1
  104. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  105. package/dist/types/config.d.ts +2 -2
  106. package/dist/types/constants.d.ts +13 -1
  107. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  108. package/dist/types/controls-options-manager/index.d.ts +16 -0
  109. package/dist/types/hashTree/constants.d.ts +1 -0
  110. package/dist/types/hashTree/hashTreeParser.d.ts +178 -22
  111. package/dist/types/hashTree/utils.d.ts +7 -0
  112. package/dist/types/index.d.ts +3 -0
  113. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  114. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  115. package/dist/types/locus-info/index.d.ts +61 -7
  116. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  117. package/dist/types/locus-info/types.d.ts +21 -1
  118. package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
  119. package/dist/types/media/properties.d.ts +6 -2
  120. package/dist/types/meeting/in-meeting-actions.d.ts +4 -0
  121. package/dist/types/meeting/index.d.ts +175 -11
  122. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  123. package/dist/types/meeting/request.d.ts +1 -0
  124. package/dist/types/meeting/util.d.ts +9 -0
  125. package/dist/types/meetings/index.d.ts +38 -18
  126. package/dist/types/meetings/meetings.types.d.ts +15 -0
  127. package/dist/types/meetings/request.d.ts +14 -0
  128. package/dist/types/member/index.d.ts +1 -0
  129. package/dist/types/member/types.d.ts +1 -0
  130. package/dist/types/member/util.d.ts +9 -0
  131. package/dist/types/members/index.d.ts +15 -2
  132. package/dist/types/members/util.d.ts +1 -5
  133. package/dist/types/metrics/constants.d.ts +6 -0
  134. package/dist/types/multistream/codec/constants.d.ts +7 -0
  135. package/dist/types/multistream/mediaRequestManager.d.ts +22 -5
  136. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  137. package/dist/types/reachability/index.d.ts +10 -3
  138. package/dist/types/reachability/reachability.types.d.ts +7 -0
  139. package/dist/types/reachability/util.d.ts +17 -0
  140. package/dist/types/reactions/reactions.type.d.ts +3 -0
  141. package/dist/webinar/index.js +307 -161
  142. package/dist/webinar/index.js.map +1 -1
  143. package/package.json +23 -23
  144. package/src/aiEnableRequest/index.ts +16 -0
  145. package/src/breakouts/breakout.ts +3 -1
  146. package/src/breakouts/events.ts +33 -11
  147. package/src/breakouts/index.ts +110 -1
  148. package/src/common/errors/webex-errors.ts +50 -3
  149. package/src/config.ts +2 -2
  150. package/src/constants.ts +21 -3
  151. package/src/controls-options-manager/constants.ts +14 -1
  152. package/src/controls-options-manager/index.ts +87 -28
  153. package/src/controls-options-manager/util.ts +81 -1
  154. package/src/hashTree/constants.ts +7 -0
  155. package/src/hashTree/hashTreeParser.ts +752 -192
  156. package/src/hashTree/utils.ts +19 -0
  157. package/src/index.ts +6 -0
  158. package/src/interceptors/dataChannelAuthToken.ts +88 -12
  159. package/src/interceptors/locusRetry.ts +25 -4
  160. package/src/interpretation/index.ts +27 -9
  161. package/src/interpretation/interpretation.types.ts +11 -0
  162. package/src/locus-info/controlsUtils.ts +3 -1
  163. package/src/locus-info/index.ts +412 -130
  164. package/src/locus-info/infoUtils.ts +41 -6
  165. package/src/locus-info/types.ts +25 -1
  166. package/src/media/MediaConnectionAwaiter.ts +21 -4
  167. package/src/media/index.ts +10 -1
  168. package/src/media/properties.ts +8 -3
  169. package/src/meeting/in-meeting-actions.ts +8 -0
  170. package/src/meeting/index.ts +913 -111
  171. package/src/meeting/locusMediaRequest.ts +106 -6
  172. package/src/meeting/muteState.ts +10 -1
  173. package/src/meeting/request.ts +11 -0
  174. package/src/meeting/util.ts +46 -5
  175. package/src/meeting-info/meeting-info-v2.ts +4 -2
  176. package/src/meetings/index.ts +168 -79
  177. package/src/meetings/meetings.types.ts +19 -0
  178. package/src/meetings/request.ts +43 -0
  179. package/src/meetings/util.ts +117 -4
  180. package/src/member/index.ts +10 -0
  181. package/src/member/types.ts +1 -0
  182. package/src/member/util.ts +29 -0
  183. package/src/members/index.ts +70 -7
  184. package/src/members/util.ts +12 -4
  185. package/src/metrics/constants.ts +6 -0
  186. package/src/multistream/codec/constants.ts +58 -0
  187. package/src/multistream/mediaRequestManager.ts +119 -28
  188. package/src/multistream/receiveSlot.ts +18 -0
  189. package/src/reachability/clusterReachability.ts +3 -2
  190. package/src/reachability/index.ts +47 -16
  191. package/src/reachability/reachability.types.ts +11 -0
  192. package/src/reachability/util.ts +36 -0
  193. package/src/reactions/reactions.type.ts +3 -0
  194. package/src/recording-controller/index.ts +1 -2
  195. package/src/roap/turnDiscovery.ts +9 -1
  196. package/src/webinar/index.ts +216 -38
  197. package/test/unit/spec/aiEnableRequest/index.ts +86 -0
  198. package/test/unit/spec/breakouts/breakout.ts +9 -3
  199. package/test/unit/spec/breakouts/events.ts +120 -2
  200. package/test/unit/spec/breakouts/index.ts +191 -2
  201. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  202. package/test/unit/spec/controls-options-manager/index.js +244 -29
  203. package/test/unit/spec/controls-options-manager/util.js +165 -0
  204. package/test/unit/spec/hashTree/hashTreeParser.ts +2110 -170
  205. package/test/unit/spec/hashTree/utils.ts +37 -0
  206. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +196 -0
  207. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  208. package/test/unit/spec/interpretation/index.ts +26 -4
  209. package/test/unit/spec/locus-info/controlsUtils.js +172 -57
  210. package/test/unit/spec/locus-info/index.js +643 -63
  211. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  212. package/test/unit/spec/media/MediaConnectionAwaiter.ts +55 -0
  213. package/test/unit/spec/media/index.ts +92 -0
  214. package/test/unit/spec/media/properties.ts +23 -23
  215. package/test/unit/spec/meeting/in-meeting-actions.ts +4 -0
  216. package/test/unit/spec/meeting/index.js +2711 -183
  217. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  218. package/test/unit/spec/meeting/muteState.js +81 -0
  219. package/test/unit/spec/meeting/request.js +12 -0
  220. package/test/unit/spec/meeting/utils.js +153 -1
  221. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  222. package/test/unit/spec/meetings/index.js +467 -36
  223. package/test/unit/spec/meetings/request.js +141 -0
  224. package/test/unit/spec/meetings/utils.js +402 -51
  225. package/test/unit/spec/member/index.js +7 -0
  226. package/test/unit/spec/member/util.js +89 -0
  227. package/test/unit/spec/members/index.js +216 -0
  228. package/test/unit/spec/members/request.js +37 -1
  229. package/test/unit/spec/members/utils.js +63 -0
  230. package/test/unit/spec/multistream/mediaRequestManager.ts +501 -37
  231. package/test/unit/spec/reachability/index.ts +128 -46
  232. package/test/unit/spec/reachability/util.ts +31 -0
  233. package/test/unit/spec/recording-controller/index.js +9 -8
  234. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  235. package/test/unit/spec/webinar/index.ts +332 -31
@@ -34,6 +34,9 @@ import {
34
34
  ONLINE,
35
35
  OFFLINE,
36
36
  ROAP_OFFER_ANSWER_EXCHANGE_TIMEOUT,
37
+ LOCUS_LLM_EVENT,
38
+ LLM_PRACTICE_SESSION,
39
+ RECORDING_STATE,
37
40
  } from '@webex/plugin-meetings/src/constants';
38
41
  import {
39
42
  ConnectionState,
@@ -91,6 +94,7 @@ import {
91
94
  MeetingNotActiveError,
92
95
  UserInLobbyError,
93
96
  AddMediaFailed,
97
+ MediaConnectionTimedOutError,
94
98
  } from '../../../../src/common/errors/webex-errors';
95
99
  import WebExMeetingsErrors from '../../../../src/common/errors/webex-meetings-error';
96
100
  import ParameterError from '../../../../src/common/errors/parameter';
@@ -261,11 +265,26 @@ describe('plugin-meetings', () => {
261
265
  webex.meetings.uploadLogs = sinon.stub().returns(Promise.resolve());
262
266
  webex.meetings.reachability = {
263
267
  isAnyPublicClusterReachable: sinon.stub().resolves(true),
268
+ isAnyClusterReachableViaProtocol: sinon.stub().resolves(false),
264
269
  getReachabilityResults: sinon.stub().resolves(undefined),
265
270
  getReachabilityMetrics: sinon.stub().resolves({}),
266
271
  stopReachability: sinon.stub(),
267
272
  isSubnetReachable: sinon.stub().returns(true),
268
273
  };
274
+ webex.internal.llm.resolveSessionOwnership = sinon
275
+ .stub()
276
+ .callsFake((ownerMeetingId, sessionId) => {
277
+ const currentOwner = webex.internal.llm.getOwnerMeetingId
278
+ ? webex.internal.llm.getOwnerMeetingId(sessionId)
279
+ : undefined;
280
+ const canAssertOwnership = !!ownerMeetingId;
281
+
282
+ return {
283
+ currentOwner,
284
+ canAssertOwnership,
285
+ isOwner: !currentOwner || !canAssertOwnership || currentOwner === ownerMeetingId,
286
+ };
287
+ });
269
288
  webex.internal.llm.isDataChannelTokenEnabled = sinon.stub().resolves(false);
270
289
  webex.internal.llm.on = sinon.stub();
271
290
  webex.internal.voicea.announce = sinon.stub();
@@ -417,6 +436,161 @@ describe('plugin-meetings', () => {
417
436
  assert.instanceOf(meeting.mediaRequestManagers.screenShareVideo, MediaRequestManager);
418
437
  });
419
438
 
439
+ it('getIngressPayloadType on webrtcMediaConnection is invoked for H264 when sending multistream video requests', () => {
440
+ const getIngressPayloadType = sinon.stub().returns(97);
441
+
442
+ meeting.isMultistream = true;
443
+ meeting.mediaProperties.webrtcMediaConnection = {
444
+ getIngressPayloadType,
445
+ requestMedia: sinon.stub(),
446
+ };
447
+
448
+ const fakeReceiveSlot = {
449
+ on: sinon.stub(),
450
+ off: sinon.stub(),
451
+ sourceState: 'live',
452
+ mediaType: MediaType.VideoMain,
453
+ wcmeReceiveSlot: {id: 'fake-wcme-slot'},
454
+ };
455
+
456
+ meeting.mediaRequestManagers.video.addRequest(
457
+ {
458
+ policyInfo: {
459
+ policy: 'receiver-selected',
460
+ csi: 42,
461
+ },
462
+ receiveSlots: [fakeReceiveSlot],
463
+ codecInfo: {
464
+ codec: 'h264',
465
+ maxFs: 3600,
466
+ },
467
+ },
468
+ true
469
+ );
470
+
471
+ assert.calledOnceWithExactly(
472
+ getIngressPayloadType,
473
+ MediaType.VideoMain,
474
+ MediaCodecMimeType.H264
475
+ );
476
+ });
477
+
478
+ it('getIngressPayloadType on webrtcMediaConnection is invoked for H264 and AV1 for slides video when AV1 slides support is enabled', () => {
479
+ const localWebex = new MockWebex({
480
+ children: {
481
+ meetings: Meetings,
482
+ credentials: Credentials,
483
+ support: Support,
484
+ llm: LLM,
485
+ mercury: Mercury,
486
+ },
487
+ config: {
488
+ credentials: {
489
+ client_id: 'mock-client-id',
490
+ },
491
+ meetings: {
492
+ reconnection: {
493
+ enabled: false,
494
+ },
495
+ mediaSettings: {},
496
+ metrics: {},
497
+ stats: {},
498
+ experimental: {enableUnifiedMeetings: true},
499
+ degradationPreferences: {maxMacroblocksLimit: 8192},
500
+ enableAv1SlidesSupport: true,
501
+ },
502
+ metrics: {
503
+ type: ['behavioral'],
504
+ },
505
+ },
506
+ });
507
+
508
+ localWebex.internal.newMetrics.callDiagnosticMetrics.clearErrorCache = sinon.stub();
509
+ localWebex.internal.newMetrics.callDiagnosticMetrics.clearEventLimitsForCorrelationId =
510
+ sinon.stub();
511
+ localWebex.internal.support.submitLogs = sinon.stub().returns(Promise.resolve());
512
+ localWebex.internal.services = {get: sinon.stub().returns('locus-url')};
513
+ localWebex.credentials.getOrgId = sinon.stub().returns('fake-org-id');
514
+ localWebex.internal.metrics.submitClientMetrics = sinon.stub().returns(Promise.resolve());
515
+ localWebex.meetings.uploadLogs = sinon.stub().returns(Promise.resolve());
516
+ localWebex.meetings.reachability = {
517
+ isAnyPublicClusterReachable: sinon.stub().resolves(true),
518
+ isAnyClusterReachableViaProtocol: sinon.stub().resolves(false),
519
+ getReachabilityResults: sinon.stub().resolves(undefined),
520
+ getReachabilityMetrics: sinon.stub().resolves({}),
521
+ stopReachability: sinon.stub(),
522
+ isSubnetReachable: sinon.stub().returns(true),
523
+ };
524
+ localWebex.internal.llm.isDataChannelTokenEnabled = sinon.stub().resolves(false);
525
+ localWebex.internal.llm.on = sinon.stub();
526
+ localWebex.internal.voicea.announce = sinon.stub();
527
+ localWebex.internal.newMetrics.callDiagnosticLatencies = new CallDiagnosticLatencies(
528
+ {},
529
+ {parent: localWebex}
530
+ );
531
+
532
+ Metrics.initialSetup(localWebex);
533
+
534
+ const localMeeting = new Meeting(
535
+ {
536
+ userId: uuid1,
537
+ resource: uuid2,
538
+ deviceUrl: uuid3,
539
+ locus: {url: url1},
540
+ destination: testDestination,
541
+ destinationType: DESTINATION_TYPE.MEETING_ID,
542
+ correlationId,
543
+ selfId: uuid1,
544
+ },
545
+ {
546
+ parent: localWebex,
547
+ }
548
+ );
549
+
550
+ const getIngressPayloadType = sinon.stub().callsFake((_mediaType, codecMimeType) => {
551
+ if (codecMimeType === MediaCodecMimeType.H264) {
552
+ return 97;
553
+ }
554
+ if (codecMimeType === MediaCodecMimeType.AV1) {
555
+ return 98;
556
+ }
557
+
558
+ return undefined;
559
+ });
560
+
561
+ localMeeting.isMultistream = true;
562
+ localMeeting.mediaProperties.webrtcMediaConnection = {
563
+ getIngressPayloadType,
564
+ requestMedia: sinon.stub(),
565
+ };
566
+
567
+ const fakeReceiveSlot = {
568
+ on: sinon.stub(),
569
+ off: sinon.stub(),
570
+ sourceState: 'live',
571
+ mediaType: MediaType.VideoSlides,
572
+ wcmeReceiveSlot: {id: 'fake-wcme-slides-slot'},
573
+ };
574
+
575
+ localMeeting.mediaRequestManagers.screenShareVideo.addRequest(
576
+ {
577
+ policyInfo: {
578
+ policy: 'receiver-selected',
579
+ csi: 42,
580
+ },
581
+ receiveSlots: [fakeReceiveSlot],
582
+ codecInfo: {
583
+ codec: 'h264',
584
+ maxFs: 3600,
585
+ },
586
+ },
587
+ true
588
+ );
589
+
590
+ assert.calledWith(getIngressPayloadType, MediaType.VideoSlides, MediaCodecMimeType.H264);
591
+ assert.calledWith(getIngressPayloadType, MediaType.VideoSlides, MediaCodecMimeType.AV1);
592
+ });
593
+
420
594
  it('uses meeting id as correlation id if not provided in constructor', () => {
421
595
  const newMeeting = new Meeting(
422
596
  {
@@ -712,6 +886,81 @@ describe('plugin-meetings', () => {
712
886
  assert.deepEqual(args, [[uuid1], locusUrls]);
713
887
  });
714
888
  });
889
+ describe('#transfer', () => {
890
+ it('should have #transfer', () => {
891
+ assert.exists(meeting.transfer);
892
+ });
893
+
894
+ it('should transfer host using the current locus when the target member is in the current session', async () => {
895
+ sinon
896
+ .stub(meeting.members.membersCollection, 'get')
897
+ .withArgs(uuid2)
898
+ .returns({isInMeeting: true});
899
+ meeting.members.transferHostToMember = sinon.stub().resolves(test1);
900
+
901
+ await meeting.transfer(uuid2, false);
902
+
903
+ assert.calledOnceWithExactly(meeting.members.transferHostToMember, uuid2, false);
904
+ });
905
+
906
+ it('should transfer host using breakout locus when the target member is joined in a breakout session', async () => {
907
+ sinon
908
+ .stub(meeting.members.membersCollection, 'get')
909
+ .withArgs(uuid2)
910
+ .returns({isInMeeting: false});
911
+ meeting.members.transferHostToMember = sinon.stub().resolves(test1);
912
+ meeting.breakouts.breakouts = {
913
+ models: [
914
+ {
915
+ members: {
916
+ membersCollection: {
917
+ get: sinon.stub().withArgs(uuid2).returns({isInMeeting: true}),
918
+ },
919
+ },
920
+ breakoutRosterLocus: {url: 'https://example.com/breakout-locus'},
921
+ },
922
+ ],
923
+ };
924
+
925
+ await meeting.transfer(uuid2, false);
926
+
927
+ assert.calledOnceWithExactly(
928
+ meeting.members.transferHostToMember,
929
+ uuid2,
930
+ false,
931
+ 'https://example.com/breakout-locus'
932
+ );
933
+ });
934
+
935
+ it('should not use breakout locus when the breakout member is not in meeting', async () => {
936
+ sinon
937
+ .stub(meeting.members.membersCollection, 'get')
938
+ .withArgs(uuid2)
939
+ .returns({isInMeeting: false});
940
+ meeting.members.transferHostToMember = sinon.stub().resolves(test1);
941
+ meeting.breakouts.breakouts = {
942
+ models: [
943
+ {
944
+ members: {
945
+ membersCollection: {
946
+ get: sinon.stub().withArgs(uuid2).returns({isInMeeting: false}),
947
+ },
948
+ },
949
+ breakoutRosterLocus: {url: 'https://example.com/breakout-locus'},
950
+ },
951
+ ],
952
+ };
953
+
954
+ await meeting.transfer(uuid2, false);
955
+
956
+ assert.calledOnceWithExactly(
957
+ meeting.members.transferHostToMember,
958
+ uuid2,
959
+ false,
960
+ undefined
961
+ );
962
+ });
963
+ });
715
964
  describe('#getMembers', () => {
716
965
  it('should have #getMembers', () => {
717
966
  assert.exists(meeting.getMembers);
@@ -741,6 +990,8 @@ describe('plugin-meetings', () => {
741
990
  let addMediaInternalStub;
742
991
  let supportsRTCPeerConnectionStub;
743
992
 
993
+ let suspendDestroyMeetingStub;
994
+
744
995
  beforeEach(() => {
745
996
  supportsRTCPeerConnectionStub = sinon
746
997
  .stub(WebCapabilities, 'supportsRTCPeerConnection')
@@ -761,6 +1012,7 @@ describe('plugin-meetings', () => {
761
1012
  .stub(meeting.roap, 'handleTurnDiscoveryHttpResponse')
762
1013
  .resolves({turnServerInfo: fakeTurnServerInfo, turnDiscoverySkippedReason: undefined});
763
1014
  abortTurnDiscoveryStub = sinon.stub(meeting.roap, 'abortTurnDiscovery');
1015
+ suspendDestroyMeetingStub = sinon.stub(meeting.locusInfo, 'suspendDestroyMeeting');
764
1016
  });
765
1017
 
766
1018
  it('should work as expected', async () => {
@@ -783,8 +1035,9 @@ describe('plugin-meetings', () => {
783
1035
  assert.calledOnceWithExactly(
784
1036
  meeting.addMediaInternal,
785
1037
  sinon.match.any,
786
- fakeTurnServerInfo,
787
1038
  false,
1039
+ fakeTurnServerInfo,
1040
+ undefined,
788
1041
  mediaOptions
789
1042
  );
790
1043
 
@@ -792,9 +1045,14 @@ describe('plugin-meetings', () => {
792
1045
 
793
1046
  // resets joinWithMediaRetryInfo
794
1047
  assert.deepEqual(meeting.joinWithMediaRetryInfo, {
795
- isRetry: false,
1048
+ retryCount: 0,
796
1049
  prevJoinResponse: undefined,
797
1050
  });
1051
+
1052
+ // suspendDestroyMeeting should be called with true at start and false on success
1053
+ assert.calledTwice(suspendDestroyMeetingStub);
1054
+ assert.calledWith(suspendDestroyMeetingStub.firstCall, true);
1055
+ assert.calledWith(suspendDestroyMeetingStub.secondCall, false);
798
1056
  });
799
1057
 
800
1058
  it("should not call handleTurnDiscoveryHttpResponse if we don't send a TURN discovery request with join", async () => {
@@ -816,8 +1074,9 @@ describe('plugin-meetings', () => {
816
1074
  assert.calledOnceWithExactly(
817
1075
  meeting.addMediaInternal,
818
1076
  sinon.match.any,
819
- undefined,
820
1077
  false,
1078
+ undefined,
1079
+ undefined,
821
1080
  mediaOptions
822
1081
  );
823
1082
 
@@ -851,8 +1110,9 @@ describe('plugin-meetings', () => {
851
1110
  assert.calledOnceWithExactly(
852
1111
  meeting.addMediaInternal,
853
1112
  sinon.match.any,
854
- undefined,
855
1113
  false,
1114
+ undefined,
1115
+ undefined,
856
1116
  mediaOptions
857
1117
  );
858
1118
 
@@ -864,7 +1124,12 @@ describe('plugin-meetings', () => {
864
1124
  meeting.join = sinon.stub().returns(Promise.reject(error));
865
1125
  meeting.locusUrl = null; // when join fails, we end up with null locusUrl
866
1126
 
867
- await assert.isRejected(meeting.joinWithMedia({mediaOptions: {allowMediaInLobby: true}}));
1127
+ const thrownError = await assert.isRejected(
1128
+ meeting.joinWithMedia({mediaOptions: {allowMediaInLobby: true}})
1129
+ );
1130
+
1131
+ // should throw the first attempt's error
1132
+ assert.equal(thrownError, error);
868
1133
 
869
1134
  assert.calledTwice(abortTurnDiscoveryStub);
870
1135
 
@@ -902,11 +1167,86 @@ describe('plugin-meetings', () => {
902
1167
 
903
1168
  // resets joinWithMediaRetryInfo
904
1169
  assert.deepEqual(meeting.joinWithMediaRetryInfo, {
905
- isRetry: false,
1170
+ retryCount: 0,
1171
+ prevJoinResponse: undefined,
1172
+ firstError: undefined,
1173
+ prevError: undefined,
1174
+ });
1175
+
1176
+ // suspendDestroyMeeting(true) called at start of each attempt, (false) only on final failure
1177
+ // 1st attempt: suspendDestroyMeeting(true), 2nd attempt (retry): suspendDestroyMeeting(true), final failure: suspendDestroyMeeting(false)
1178
+ assert.calledThrice(suspendDestroyMeetingStub);
1179
+ assert.calledWith(suspendDestroyMeetingStub.firstCall, true);
1180
+ assert.calledWith(suspendDestroyMeetingStub.secondCall, true);
1181
+ assert.calledWith(suspendDestroyMeetingStub.thirdCall, false);
1182
+ });
1183
+
1184
+ it('should re-join on retry when join() fails on first attempt, and throw the first error if join fails again', async () => {
1185
+ const firstJoinError = new Error('first join error');
1186
+ const secondJoinError = new Error('second join error');
1187
+
1188
+ meeting.join = sinon
1189
+ .stub()
1190
+ .onFirstCall()
1191
+ .rejects(firstJoinError)
1192
+ .onSecondCall()
1193
+ .rejects(secondJoinError);
1194
+ meeting.locusUrl = null; // join never succeeds
1195
+
1196
+ const thrownError = await assert.isRejected(
1197
+ meeting.joinWithMedia({joinOptions, mediaOptions})
1198
+ );
1199
+
1200
+ // join() should be called twice — once for the first attempt, once for the re-join
1201
+ assert.calledTwice(meeting.join);
1202
+ // TURN discovery should be attempted twice (once per join)
1203
+ assert.calledTwice(generateTurnDiscoveryRequestMessageStub);
1204
+
1205
+ // should throw the first attempt's error, not the second
1206
+ assert.equal(thrownError, firstJoinError);
1207
+
1208
+ assert.calledTwice(Metrics.sendBehavioralMetric);
1209
+ assert.calledWith(
1210
+ Metrics.sendBehavioralMetric.firstCall,
1211
+ BEHAVIORAL_METRICS.JOIN_WITH_MEDIA_FAILURE,
1212
+ sinon.match({reason: firstJoinError.message, isRetry: false}),
1213
+ sinon.match.any
1214
+ );
1215
+ assert.calledWith(
1216
+ Metrics.sendBehavioralMetric.secondCall,
1217
+ BEHAVIORAL_METRICS.JOIN_WITH_MEDIA_FAILURE,
1218
+ sinon.match({reason: secondJoinError.message, isRetry: true}),
1219
+ sinon.match.any
1220
+ );
1221
+
1222
+ assert.deepEqual(meeting.joinWithMediaRetryInfo, {
1223
+ retryCount: 0,
906
1224
  prevJoinResponse: undefined,
1225
+ firstError: undefined,
1226
+ prevError: undefined,
907
1227
  });
908
1228
  });
909
1229
 
1230
+ it('should NOT call join() again on retry when join() succeeded but addMediaInternal() failed', async () => {
1231
+ const addMediaError = new Error('addMedia error');
1232
+
1233
+ meeting.addMediaInternal = sinon
1234
+ .stub()
1235
+ .onFirstCall()
1236
+ .rejects(addMediaError)
1237
+ .onSecondCall()
1238
+ .resolves(test4);
1239
+
1240
+ const result = await meeting.joinWithMedia({joinOptions, mediaOptions});
1241
+
1242
+ assert.deepEqual(result, {join: fakeJoinResult, media: test4, multistreamEnabled: true});
1243
+
1244
+ // join() should only be called once — the successful join result is reused on retry
1245
+ assert.calledOnce(meeting.join);
1246
+ // TURN discovery request is only generated once (on the first attempt alongside join)
1247
+ assert.calledOnce(generateTurnDiscoveryRequestMessageStub);
1248
+ });
1249
+
910
1250
  it('should resolve if join() fails the first time but succeeds the second time', async () => {
911
1251
  const error = new Error('fake');
912
1252
  meeting.join = sinon
@@ -948,7 +1288,7 @@ describe('plugin-meetings', () => {
948
1288
 
949
1289
  // resets joinWithMediaRetryInfo
950
1290
  assert.deepEqual(meeting.joinWithMediaRetryInfo, {
951
- isRetry: false,
1291
+ retryCount: 0,
952
1292
  prevJoinResponse: undefined,
953
1293
  });
954
1294
  });
@@ -1017,6 +1357,127 @@ describe('plugin-meetings', () => {
1017
1357
  );
1018
1358
  });
1019
1359
 
1360
+ it('should throw the first attempt error when retry also fails with a different error', async () => {
1361
+ const firstError = new Error('first attempt error');
1362
+ const secondError = new Error('second attempt error');
1363
+
1364
+ const addMediaInternalResults = [];
1365
+ meeting.addMediaInternal = sinon.stub().callsFake(() => {
1366
+ const defer = new Defer();
1367
+ addMediaInternalResults.push(defer);
1368
+ return defer.promise;
1369
+ });
1370
+
1371
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1372
+
1373
+ const result = meeting.joinWithMedia({joinOptions, mediaOptions});
1374
+
1375
+ await testUtils.flushPromises();
1376
+
1377
+ // 1st attempt fails
1378
+ addMediaInternalResults[0].reject(firstError);
1379
+ await testUtils.flushPromises();
1380
+
1381
+ // leave() should NOT be called after the 1st attempt (intermediate retry)
1382
+ assert.notCalled(leaveStub);
1383
+
1384
+ // 2nd (final) attempt fails
1385
+ addMediaInternalResults[1].reject(secondError);
1386
+ const thrownError = await assert.isRejected(result);
1387
+
1388
+ // should throw the first error, not the second
1389
+ assert.equal(thrownError, firstError);
1390
+
1391
+ // leave() should only be called after the last (2nd) attempt
1392
+ assert.calledOnce(leaveStub);
1393
+
1394
+ assert.calledTwice(Metrics.sendBehavioralMetric);
1395
+ });
1396
+
1397
+ it('should throw the UserNotJoinedError as firstError when it occurs on the 1st attempt and 2nd attempt fails differently', async () => {
1398
+ const userNotJoinedError = new UserNotJoinedError();
1399
+ const secondError = new Error('second attempt error');
1400
+
1401
+ const addMediaInternalResults = [];
1402
+ meeting.addMediaInternal = sinon.stub().callsFake(() => {
1403
+ const defer = new Defer();
1404
+ addMediaInternalResults.push(defer);
1405
+ return defer.promise;
1406
+ });
1407
+
1408
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1409
+
1410
+ const result = meeting.joinWithMedia({joinOptions, mediaOptions});
1411
+
1412
+ await testUtils.flushPromises();
1413
+
1414
+ // 1st attempt fails with UserNotJoinedError — triggers a re-join
1415
+ addMediaInternalResults[0].reject(userNotJoinedError);
1416
+ await testUtils.flushPromises();
1417
+
1418
+ // leave() should NOT be called after the 1st attempt (intermediate retry)
1419
+ assert.notCalled(leaveStub);
1420
+
1421
+ // 2nd (final) attempt fails
1422
+ addMediaInternalResults[1].reject(secondError);
1423
+ const thrownError = await assert.isRejected(result);
1424
+
1425
+ // should throw the first (UserNotJoinedError), not the second
1426
+ assert.equal(thrownError, userNotJoinedError);
1427
+
1428
+ // join() called twice: original + re-join triggered by UserNotJoinedError in prevError
1429
+ assert.calledTwice(meeting.join);
1430
+ // leave() should only be called after the last (2nd) attempt
1431
+ assert.calledOnce(leaveStub);
1432
+ assert.calledTwice(Metrics.sendBehavioralMetric);
1433
+ });
1434
+
1435
+ it('should throw the first UserNotJoinedError when it occurs on both 1st and 2nd attempts and a 3rd attempt also fails', async () => {
1436
+ const firstUserNotJoinedError = new UserNotJoinedError('first');
1437
+ const secondUserNotJoinedError = new UserNotJoinedError('second');
1438
+ const thirdError = new Error('third attempt error');
1439
+
1440
+ const addMediaInternalResults = [];
1441
+ meeting.addMediaInternal = sinon.stub().callsFake(() => {
1442
+ const defer = new Defer();
1443
+ addMediaInternalResults.push(defer);
1444
+ return defer.promise;
1445
+ });
1446
+
1447
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1448
+
1449
+ const result = meeting.joinWithMedia({joinOptions, mediaOptions});
1450
+
1451
+ await testUtils.flushPromises();
1452
+
1453
+ // 1st attempt fails with UserNotJoinedError — triggers a re-join
1454
+ addMediaInternalResults[0].reject(firstUserNotJoinedError);
1455
+ await testUtils.flushPromises();
1456
+
1457
+ // leave() should NOT be called after the 1st attempt (intermediate retry)
1458
+ assert.notCalled(leaveStub);
1459
+
1460
+ // 2nd attempt fails with UserNotJoinedError again — triggers another re-join
1461
+ addMediaInternalResults[1].reject(secondUserNotJoinedError);
1462
+ await testUtils.flushPromises();
1463
+
1464
+ // leave() should NOT be called after the 2nd attempt (intermediate retry)
1465
+ assert.notCalled(leaveStub);
1466
+
1467
+ // 3rd (final) attempt fails
1468
+ addMediaInternalResults[2].reject(thirdError);
1469
+ const thrownError = await assert.isRejected(result);
1470
+
1471
+ // should throw the very first error across all 3 attempts
1472
+ assert.equal(thrownError, firstUserNotJoinedError);
1473
+
1474
+ // join() called 3 times: original + 2 re-joins triggered by prevError being UserNotJoinedError
1475
+ assert.calledThrice(meeting.join);
1476
+ // leave() should only be called after the last (3rd) attempt
1477
+ assert.calledOnce(leaveStub);
1478
+ assert.calledThrice(Metrics.sendBehavioralMetric);
1479
+ });
1480
+
1020
1481
  it('should call leave() if addMediaInternal() fails with a browser media error (TypeError)', async () => {
1021
1482
  const addMediaError = new Error('fake addMedia error');
1022
1483
  addMediaError.name = 'TypeError'; // This makes it a browser media error
@@ -1212,8 +1673,9 @@ describe('plugin-meetings', () => {
1212
1673
  assert.calledWith(
1213
1674
  meeting.addMediaInternal.firstCall,
1214
1675
  sinon.match.any,
1215
- fakeTurnServerInfo,
1216
1676
  false,
1677
+ fakeTurnServerInfo,
1678
+ undefined,
1217
1679
  mediaOptions
1218
1680
  );
1219
1681
 
@@ -1221,8 +1683,9 @@ describe('plugin-meetings', () => {
1221
1683
  assert.calledWith(
1222
1684
  meeting.addMediaInternal.secondCall,
1223
1685
  sinon.match.any,
1224
- undefined,
1225
1686
  true,
1687
+ undefined,
1688
+ undefined,
1226
1689
  mediaOptions
1227
1690
  );
1228
1691
 
@@ -1240,7 +1703,7 @@ describe('plugin-meetings', () => {
1240
1703
 
1241
1704
  meeting.addMediaInternal = sinon
1242
1705
  .stub()
1243
- .callsFake((icePhaseCallback, _turnServerInfo, _forceTurnDiscovery) => {
1706
+ .callsFake((icePhaseCallback, _forceTurnDiscovery, _turnServerInfo) => {
1244
1707
  const defer = new Defer();
1245
1708
 
1246
1709
  icePhaseCallbacks.push(icePhaseCallback);
@@ -1264,7 +1727,8 @@ describe('plugin-meetings', () => {
1264
1727
 
1265
1728
  await testUtils.flushPromises();
1266
1729
 
1267
- // check the callback works correctly on the 2nd attempt
1730
+ // check the callback works correctly on the 2nd attempt:
1731
+ // retryCount=1 with a non-UserNotJoinedError is terminal, so icePhase must be JOIN_MEETING_FINAL
1268
1732
  assert.equal(icePhaseCallbacks.length, 2);
1269
1733
  assert.equal(icePhaseCallbacks[1](), 'JOIN_MEETING_FINAL');
1270
1734
 
@@ -1274,33 +1738,143 @@ describe('plugin-meetings', () => {
1274
1738
  await assert.isRejected(result);
1275
1739
  });
1276
1740
 
1277
- [
1278
- {
1279
- errorName: 'SdpOfferCreationError',
1280
- description: 'if we fail to create the offer on first attempt',
1281
- },
1282
- {
1283
- errorName: 'WebrtcApiNotAvailableError',
1284
- description: 'if RTCPeerConnection is not available',
1285
- },
1286
- ].forEach(({errorName, description}) => {
1287
- it(`should not attempt a retry ${description}`, async () => {
1288
- const addMediaError = new Error('fake addMedia error');
1289
- addMediaError.name = errorName;
1741
+ it('should allow an additional retry when UserNotJoinedError occurs and return JOIN_MEETING_FINAL on the 3rd attempt', async () => {
1742
+ const genericError = new Error('generic error');
1743
+ const userNotJoinedError = new UserNotJoinedError();
1744
+ const thirdError = new Error('third error');
1290
1745
 
1291
- meeting.addMediaInternal.rejects(addMediaError);
1292
- sinon.stub(meeting, 'leave').resolves();
1746
+ const icePhaseCallbacks = [];
1747
+ const addMediaInternalResults = [];
1293
1748
 
1294
- await assert.isRejected(
1295
- meeting.joinWithMedia({
1296
- joinOptions,
1297
- mediaOptions,
1298
- }),
1299
- addMediaError
1300
- );
1749
+ meeting.addMediaInternal = sinon.stub().callsFake((icePhaseCallback) => {
1750
+ const defer = new Defer();
1301
1751
 
1302
- // check that only 1 attempt was done
1303
- assert.calledOnce(meeting.join);
1752
+ icePhaseCallbacks.push(icePhaseCallback);
1753
+ addMediaInternalResults.push(defer);
1754
+ return defer.promise;
1755
+ });
1756
+
1757
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1758
+
1759
+ const result = meeting.joinWithMedia({
1760
+ joinOptions,
1761
+ mediaOptions,
1762
+ });
1763
+
1764
+ await testUtils.flushPromises();
1765
+
1766
+ // 1st attempt: retryCount=0 → JOIN_MEETING_RETRY
1767
+ assert.equal(icePhaseCallbacks.length, 1);
1768
+ assert.equal(icePhaseCallbacks[0](), 'JOIN_MEETING_RETRY');
1769
+ addMediaInternalResults[0].reject(genericError);
1770
+
1771
+ await testUtils.flushPromises();
1772
+
1773
+ // leave() should NOT be called after the 1st attempt (intermediate retry)
1774
+ assert.notCalled(leaveStub);
1775
+
1776
+ // 2nd attempt: retryCount=1 → JOIN_MEETING_FINAL
1777
+ // (In real usage this callback is never invoked when UserNotJoinedError is thrown,
1778
+ // because UserNotJoinedError is thrown before waitForMediaConnectionConnected() is reached.)
1779
+ assert.equal(icePhaseCallbacks.length, 2);
1780
+ assert.equal(icePhaseCallbacks[1](), 'JOIN_MEETING_FINAL');
1781
+ addMediaInternalResults[1].reject(userNotJoinedError);
1782
+
1783
+ await testUtils.flushPromises();
1784
+
1785
+ // leave() should NOT be called after the 2nd attempt (intermediate retry)
1786
+ assert.notCalled(leaveStub);
1787
+
1788
+ // 3rd attempt: retryCount=2 → JOIN_MEETING_FINAL
1789
+ assert.equal(icePhaseCallbacks.length, 3);
1790
+ assert.equal(icePhaseCallbacks[2](), 'JOIN_MEETING_FINAL');
1791
+ addMediaInternalResults[2].reject(thirdError);
1792
+
1793
+ const thrownError = await assert.isRejected(result);
1794
+
1795
+ // should throw the first error
1796
+ assert.equal(thrownError, genericError);
1797
+
1798
+ // leave() should only be called once, after the last (3rd) attempt
1799
+ assert.calledOnce(leaveStub);
1800
+ });
1801
+
1802
+ it('should re-join when retrying after a UserNotJoinedError', async () => {
1803
+ const userNotJoinedError = new UserNotJoinedError();
1804
+
1805
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1806
+
1807
+ meeting.addMediaInternal = sinon
1808
+ .stub()
1809
+ .onFirstCall()
1810
+ .rejects(userNotJoinedError)
1811
+ .onSecondCall()
1812
+ .resolves(test4);
1813
+
1814
+ const result = await meeting.joinWithMedia({joinOptions, mediaOptions});
1815
+
1816
+ assert.deepEqual(result, {join: fakeJoinResult, media: test4, multistreamEnabled: true});
1817
+
1818
+ // join() should be called twice — once for the first attempt, once for the re-join after UserNotJoinedError
1819
+ assert.calledTwice(meeting.join);
1820
+ // TURN discovery should be attempted twice (once per join)
1821
+ assert.calledTwice(generateTurnDiscoveryRequestMessageStub);
1822
+ // leave() should never be called when retrying after UserNotJoinedError
1823
+ assert.notCalled(leaveStub);
1824
+ });
1825
+
1826
+ it('should re-join when isUserInLeftState returns true on retry', async () => {
1827
+ const addMediaError = new Error('addMedia error');
1828
+
1829
+ sinon.stub(MeetingUtil, 'isUserInLeftState').returns(true);
1830
+
1831
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1832
+
1833
+ meeting.addMediaInternal = sinon
1834
+ .stub()
1835
+ .onFirstCall()
1836
+ .rejects(addMediaError)
1837
+ .onSecondCall()
1838
+ .resolves(test4);
1839
+
1840
+ const result = await meeting.joinWithMedia({joinOptions, mediaOptions});
1841
+
1842
+ assert.deepEqual(result, {join: fakeJoinResult, media: test4, multistreamEnabled: true});
1843
+
1844
+ // join() should be called twice — once for the first attempt, once because the user is in left state
1845
+ assert.calledTwice(meeting.join);
1846
+ assert.calledTwice(generateTurnDiscoveryRequestMessageStub);
1847
+ // leave() should never be called when retrying after isUserInLeftState returns true
1848
+ assert.notCalled(leaveStub);
1849
+ });
1850
+
1851
+ [
1852
+ {
1853
+ errorName: 'SdpOfferCreationError',
1854
+ description: 'if we fail to create the offer on first attempt',
1855
+ },
1856
+ {
1857
+ errorName: 'WebrtcApiNotAvailableError',
1858
+ description: 'if RTCPeerConnection is not available',
1859
+ },
1860
+ ].forEach(({errorName, description}) => {
1861
+ it(`should not attempt a retry ${description}`, async () => {
1862
+ const addMediaError = new Error('fake addMedia error');
1863
+ addMediaError.name = errorName;
1864
+
1865
+ meeting.addMediaInternal.rejects(addMediaError);
1866
+ sinon.stub(meeting, 'leave').resolves();
1867
+
1868
+ await assert.isRejected(
1869
+ meeting.joinWithMedia({
1870
+ joinOptions,
1871
+ mediaOptions,
1872
+ }),
1873
+ addMediaError
1874
+ );
1875
+
1876
+ // check that only 1 attempt was done
1877
+ assert.calledOnce(meeting.join);
1304
1878
  assert.calledOnce(meeting.addMediaInternal);
1305
1879
  assert.calledOnce(Metrics.sendBehavioralMetric);
1306
1880
  assert.calledWith(
@@ -1341,6 +1915,7 @@ describe('plugin-meetings', () => {
1341
1915
  sinon.match.any,
1342
1916
  sinon.match.any,
1343
1917
  sinon.match.any,
1918
+ sinon.match.any,
1344
1919
  sinon.match.has('videoEnabled', false).and(sinon.match.has('allowMediaInLobby', true))
1345
1920
  );
1346
1921
  });
@@ -1361,6 +1936,7 @@ describe('plugin-meetings', () => {
1361
1936
  sinon.match.any,
1362
1937
  sinon.match.any,
1363
1938
  sinon.match.any,
1939
+ sinon.match.any,
1364
1940
  sinon.match.has('audioEnabled', false).and(sinon.match.has('allowMediaInLobby', true))
1365
1941
  );
1366
1942
  });
@@ -1382,6 +1958,7 @@ describe('plugin-meetings', () => {
1382
1958
  sinon.match.any,
1383
1959
  sinon.match.any,
1384
1960
  sinon.match.any,
1961
+ sinon.match.any,
1385
1962
  sinon.match({
1386
1963
  sendVideo: true,
1387
1964
  receiveVideo: false,
@@ -1391,6 +1968,101 @@ describe('plugin-meetings', () => {
1391
1968
  );
1392
1969
  });
1393
1970
 
1971
+ describe('shouldRetryMediaWithOnlyTurnTLS', () => {
1972
+ it('should pass iceTransportPolicy=relay for multistream when previous error is DTLS failure over UDP and TLS is reachable', async () => {
1973
+ meeting.isMultistream = true;
1974
+ const dtlsError = new AddMediaFailed({iceConnected: true, connectionType: 'UDP'});
1975
+
1976
+ webex.meetings.reachability.isAnyClusterReachableViaProtocol = sinon
1977
+ .stub()
1978
+ .resolves(true);
1979
+
1980
+ addMediaInternalStub.onFirstCall().rejects(dtlsError);
1981
+ addMediaInternalStub.onSecondCall().resolves(test4);
1982
+
1983
+ await meeting.joinWithMedia({joinOptions, mediaOptions});
1984
+
1985
+ assert.calledWith(
1986
+ meeting.addMediaInternal.secondCall,
1987
+ sinon.match.any,
1988
+ sinon.match.any,
1989
+ sinon.match.any,
1990
+ 'relay',
1991
+ mediaOptions
1992
+ );
1993
+ });
1994
+
1995
+ [
1996
+ {
1997
+ title: 'TLS is not reachable',
1998
+ prevError: new AddMediaFailed({iceConnected: true, connectionType: 'UDP'}),
1999
+ tlsReachable: false,
2000
+ isMultistream: true,
2001
+ },
2002
+ {
2003
+ title: 'error is not AddMediaFailed',
2004
+ prevError: new Error('generic error'),
2005
+ tlsReachable: true,
2006
+ isMultistream: true,
2007
+ },
2008
+ {
2009
+ title: 'error is AddMediaFailed but not DTLS failure',
2010
+ prevError: new AddMediaFailed({iceConnected: false, connectionType: 'UDP'}),
2011
+ tlsReachable: true,
2012
+ isMultistream: true,
2013
+ },
2014
+ {
2015
+ title: 'error is DTLS failure but connectionType is not UDP',
2016
+ prevError: new AddMediaFailed({iceConnected: true, connectionType: 'TURN-TLS'}),
2017
+ tlsReachable: true,
2018
+ isMultistream: true,
2019
+ },
2020
+ {
2021
+ title: 'isMultistream is false',
2022
+ prevError: new AddMediaFailed({iceConnected: true, connectionType: 'UDP'}),
2023
+ tlsReachable: true,
2024
+ isMultistream: false,
2025
+ },
2026
+ ].forEach(({title, prevError, tlsReachable, isMultistream}) => {
2027
+ it(`should pass iceTransportPolicy=undefined when ${title}`, async () => {
2028
+ meeting.join = sinon.stub().callsFake(() => {
2029
+ meeting.isMultistream = isMultistream;
2030
+ return Promise.resolve(fakeJoinResult);
2031
+ });
2032
+ webex.meetings.reachability.isAnyClusterReachableViaProtocol = sinon
2033
+ .stub()
2034
+ .resolves(tlsReachable);
2035
+
2036
+ addMediaInternalStub.onFirstCall().rejects(prevError);
2037
+ addMediaInternalStub.onSecondCall().resolves(test4);
2038
+
2039
+ await meeting.joinWithMedia({joinOptions, mediaOptions});
2040
+
2041
+ assert.calledWith(
2042
+ meeting.addMediaInternal.secondCall,
2043
+ sinon.match.any,
2044
+ sinon.match.any,
2045
+ sinon.match.any,
2046
+ undefined,
2047
+ mediaOptions
2048
+ );
2049
+ });
2050
+ });
2051
+
2052
+ it('should pass iceTransportPolicy=undefined on first attempt (no prevError)', async () => {
2053
+ await meeting.joinWithMedia({joinOptions, mediaOptions});
2054
+
2055
+ assert.calledWith(
2056
+ meeting.addMediaInternal.firstCall,
2057
+ sinon.match.any,
2058
+ sinon.match.any,
2059
+ sinon.match.any,
2060
+ undefined,
2061
+ mediaOptions
2062
+ );
2063
+ });
2064
+ });
2065
+
1394
2066
  it('should throw immediately if RTCPeerConnection is not available', async () => {
1395
2067
  supportsRTCPeerConnectionStub.returns(CapabilityState.NOT_CAPABLE);
1396
2068
 
@@ -1402,9 +2074,87 @@ describe('plugin-meetings', () => {
1402
2074
  Errors.WebrtcApiNotAvailableError
1403
2075
  );
1404
2076
 
2077
+ assert.notCalled(suspendDestroyMeetingStub);
1405
2078
  assert.notCalled(meeting.join);
1406
2079
  assert.notCalled(meeting.addMediaInternal);
1407
2080
  });
2081
+
2082
+ [
2083
+ {description: '409 error from join()', statusCode: 409, useCause: false},
2084
+ {description: '403 error from join()', statusCode: 403, useCause: false},
2085
+ {description: '409 error in cause (e.g. AddMediaFailed)', statusCode: 409, useCause: true},
2086
+ {description: '403 error in cause (e.g. AddMediaFailed)', statusCode: 403, useCause: true},
2087
+ ].forEach(({description, statusCode, useCause}) => {
2088
+ it(`should re-join on retry when ${description}`, async () => {
2089
+ const error = useCause
2090
+ ? Object.assign(new Error('wrapped error'), {cause: {statusCode}})
2091
+ : Object.assign(new Error('locus error'), {statusCode});
2092
+
2093
+ meeting.addMediaInternal = sinon
2094
+ .stub()
2095
+ .onFirstCall()
2096
+ .rejects(error)
2097
+ .onSecondCall()
2098
+ .resolves(test4);
2099
+
2100
+ const result = await meeting.joinWithMedia({joinOptions, mediaOptions});
2101
+
2102
+ assert.deepEqual(result, {join: fakeJoinResult, media: test4, multistreamEnabled: true});
2103
+
2104
+ // join() should be called twice — once for the first attempt, once for the re-join
2105
+ assert.calledTwice(meeting.join);
2106
+ assert.calledTwice(generateTurnDiscoveryRequestMessageStub);
2107
+ });
2108
+ });
2109
+
2110
+ it('should allow up to JOIN_WITH_MEDIA_RETRY_MAX_COUNT retries for 409 errors', async () => {
2111
+ const error409 = Object.assign(new Error('locus dropped us'), {statusCode: 409});
2112
+
2113
+ meeting.addMediaInternal = sinon.stub().rejects(error409);
2114
+ meeting.join = sinon.stub().callsFake(() => Promise.resolve(fakeJoinResult));
2115
+ sinon.stub(meeting, 'leave').resolves();
2116
+
2117
+ await assert.isRejected(
2118
+ meeting.joinWithMedia({joinOptions, mediaOptions})
2119
+ );
2120
+
2121
+ // JOIN_WITH_MEDIA_RETRY_MAX_COUNT is 2, so we expect 3 attempts total (initial + 2 retries)
2122
+ assert.callCount(meeting.join, 3);
2123
+ assert.callCount(meeting.addMediaInternal, 3);
2124
+ });
2125
+
2126
+ it('should not retry on 1-1 calls', async () => {
2127
+ const addMediaError = new Error('addMedia error');
2128
+
2129
+ sinon.stub(MeetingsUtil, 'isOneOnOneCall').returns(true);
2130
+
2131
+ meeting.addMediaInternal = sinon.stub().rejects(addMediaError);
2132
+ sinon.stub(meeting, 'leave').resolves();
2133
+
2134
+ await assert.isRejected(
2135
+ meeting.joinWithMedia({joinOptions, mediaOptions}),
2136
+ addMediaError
2137
+ );
2138
+
2139
+ // should not retry - only 1 attempt
2140
+ assert.calledOnce(meeting.join);
2141
+ assert.calledOnce(meeting.addMediaInternal);
2142
+ assert.calledOnceWithExactly(
2143
+ Metrics.sendBehavioralMetric,
2144
+ BEHAVIORAL_METRICS.JOIN_WITH_MEDIA_FAILURE,
2145
+ {
2146
+ correlation_id: meeting.correlationId,
2147
+ locus_id: meeting.locusUrl.split('/').pop(),
2148
+ reason: addMediaError.message,
2149
+ stack: addMediaError.stack,
2150
+ leaveErrorReason: undefined,
2151
+ isRetry: false,
2152
+ },
2153
+ {
2154
+ type: addMediaError.name,
2155
+ }
2156
+ );
2157
+ });
1408
2158
  });
1409
2159
  describe('#isTranscriptionSupported', () => {
1410
2160
  it('should return false if the feature is not supported for the meeting', () => {
@@ -1977,12 +2727,120 @@ describe('plugin-meetings', () => {
1977
2727
  fakeProcessedReaction
1978
2728
  );
1979
2729
  });
2730
+
2731
+ [
2732
+ {
2733
+ title:
2734
+ 'should skip a reaction when the default relay route does not match the LLM binding',
2735
+ isPracticeSessionConnected: false,
2736
+ route: 'wrong-default-route',
2737
+ defaultBinding: 'default-route',
2738
+ practiceBinding: 'practice-route',
2739
+ shouldProcess: false,
2740
+ expectedSessionLabel: 'default session',
2741
+ },
2742
+ {
2743
+ title: 'should process a reaction when the default relay route matches the LLM binding',
2744
+ isPracticeSessionConnected: false,
2745
+ route: 'default-route',
2746
+ defaultBinding: 'default-route',
2747
+ practiceBinding: 'practice-route',
2748
+ shouldProcess: true,
2749
+ },
2750
+ {
2751
+ title:
2752
+ 'should process a reaction when the practice-session relay route matches the practice-session LLM binding',
2753
+ isPracticeSessionConnected: true,
2754
+ route: 'practice-route',
2755
+ defaultBinding: 'default-route',
2756
+ practiceBinding: 'practice-route',
2757
+ shouldProcess: true,
2758
+ },
2759
+ {
2760
+ title:
2761
+ 'should skip a reaction when the practice-session relay route does not match the practice-session LLM binding',
2762
+ isPracticeSessionConnected: true,
2763
+ route: 'default-route',
2764
+ defaultBinding: 'default-route',
2765
+ practiceBinding: 'practice-route',
2766
+ shouldProcess: false,
2767
+ expectedSessionLabel: 'practice session',
2768
+ },
2769
+ ].forEach(
2770
+ ({
2771
+ title,
2772
+ isPracticeSessionConnected,
2773
+ route,
2774
+ defaultBinding,
2775
+ practiceBinding,
2776
+ shouldProcess,
2777
+ expectedSessionLabel,
2778
+ }) => {
2779
+ it(title, () => {
2780
+ meeting.isReactionsSupported = sinon.stub().returns(true);
2781
+ meeting.config.receiveReactions = true;
2782
+ const fakeSendersName = 'Fake reactors name';
2783
+ meeting.members.membersCollection.get = sinon.stub().returns({name: fakeSendersName});
2784
+ webex.internal.llm.isConnected = sinon.stub().callsFake((llmSessionId) => {
2785
+ return llmSessionId === LLM_PRACTICE_SESSION && isPracticeSessionConnected;
2786
+ });
2787
+ webex.internal.llm.getBinding = sinon.stub().callsFake((llmSessionId) => {
2788
+ if (llmSessionId === LLM_PRACTICE_SESSION) {
2789
+ return practiceBinding;
2790
+ }
2791
+
2792
+ return defaultBinding;
2793
+ });
2794
+ const fakeReactionPayload = {
2795
+ type: 'fake_type',
2796
+ codepoints: 'fake_codepoints',
2797
+ shortcodes: 'fake_shortcodes',
2798
+ };
2799
+ const fakeSenderPayload = {
2800
+ participantId: 'fake_participant_id',
2801
+ };
2802
+ const fakeRelayEvent = {
2803
+ headers: {route},
2804
+ data: {
2805
+ relayType: REACTION_RELAY_TYPES.REACTION,
2806
+ reaction: fakeReactionPayload,
2807
+ sender: fakeSenderPayload,
2808
+ },
2809
+ };
2810
+ const fakeProcessedReaction = {
2811
+ reaction: fakeReactionPayload,
2812
+ sender: {
2813
+ id: fakeSenderPayload.participantId,
2814
+ name: fakeSendersName,
2815
+ },
2816
+ };
2817
+
2818
+ TriggerProxy.trigger.resetHistory();
2819
+ meeting.processRelayEvent(fakeRelayEvent);
2820
+
2821
+ if (shouldProcess) {
2822
+ assert.calledWith(
2823
+ TriggerProxy.trigger,
2824
+ sinon.match.instanceOf(Meeting),
2825
+ {
2826
+ file: 'meeting/index',
2827
+ function: 'join',
2828
+ },
2829
+ EVENT_TRIGGERS.MEETING_RECEIVE_REACTIONS,
2830
+ fakeProcessedReaction
2831
+ );
2832
+ } else {
2833
+ assert.notCalled(TriggerProxy.trigger);
2834
+ }
2835
+ });
2836
+ }
2837
+ );
1980
2838
  });
1981
2839
 
1982
2840
  describe('#handleLLMOnline', () => {
1983
2841
  beforeEach(() => {
1984
2842
  webex.internal.llm.off = sinon.stub();
1985
- webex.internal.voicea.getIsCaptionBoxOn = sinon.stub().returns(false);
2843
+ webex.internal.voicea.getKeepTranscriptionSubscribed = sinon.stub().returns(false);
1986
2844
  webex.internal.voicea.updateSubchannelSubscriptions = sinon.stub();
1987
2845
  });
1988
2846
 
@@ -2000,7 +2858,7 @@ describe('plugin-meetings', () => {
2000
2858
  });
2001
2859
 
2002
2860
  it('restores transcription subscription when caption intent is enabled', () => {
2003
- webex.internal.voicea.getIsCaptionBoxOn.returns(true);
2861
+ webex.internal.voicea.getKeepTranscriptionSubscribed.returns(true);
2004
2862
 
2005
2863
  meeting.handleLLMOnline();
2006
2864
 
@@ -2010,12 +2868,20 @@ describe('plugin-meetings', () => {
2010
2868
  });
2011
2869
 
2012
2870
  it('does not restore transcription subscription when caption intent is disabled', () => {
2013
- webex.internal.voicea.getIsCaptionBoxOn.returns(false);
2871
+ webex.internal.voicea.getKeepTranscriptionSubscribed.returns(false);
2014
2872
 
2015
2873
  meeting.handleLLMOnline();
2016
2874
 
2017
2875
  assert.notCalled(webex.internal.voicea.updateSubchannelSubscriptions);
2018
2876
  });
2877
+
2878
+ it('calls syncAllHashTreeDatasets on locusInfo', () => {
2879
+ sinon.stub(meeting.locusInfo, 'syncAllHashTreeDatasets').resolves();
2880
+
2881
+ meeting.handleLLMOnline();
2882
+
2883
+ assert.calledOnceWithExactly(meeting.locusInfo.syncAllHashTreeDatasets, {onlyLLM: true});
2884
+ });
2019
2885
  });
2020
2886
 
2021
2887
  describe('#join', () => {
@@ -2096,6 +2962,8 @@ describe('plugin-meetings', () => {
2096
2962
  regionCode: 'EU',
2097
2963
  },
2098
2964
  preferTranscoding: !enableMultistream,
2965
+ getCurrentSelfUrl: sinon.match.func,
2966
+ waitForSelfUrlChange: sinon.match.func,
2099
2967
  },
2100
2968
  {
2101
2969
  parent: meeting.webex,
@@ -2340,46 +3208,261 @@ describe('plugin-meetings', () => {
2340
3208
  );
2341
3209
  });
2342
3210
 
2343
- it('clears the LLM health check timer when disconnecting LLM', async () => {
2344
- const isJoinedStub = sinon.stub(meeting, 'isJoined');
2345
- sinon.stub(meeting.webex.internal.llm, 'isConnected');
2346
- sinon.stub(meeting.webex.internal.llm, 'disconnectLLM').resolves();
2347
- sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({});
2348
- sinon
2349
- .stub(meeting.webex.internal.llm, 'getLocusUrl')
2350
- .returns('https://locus1.example.com');
2351
- sinon
2352
- .stub(meeting.webex.internal.llm, 'getDatachannelUrl')
2353
- .returns('https://datachannel1.example.com');
3211
+ it('emits breakout join response metric only once per breakoutMoveId', async () => {
3212
+ sinon.stub(meeting, 'isJoined').returns(true);
3213
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3214
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3215
+ clientLLMDatachannelResponseTime: 10,
3216
+ clientLLMWebSocketConnectTime: 20,
3217
+ });
3218
+
3219
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3220
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3221
+ meeting.breakouts.set('sessionType', 'BREAKOUT');
3222
+ meeting.breakouts.set('status', 'OPEN');
3223
+ meeting.breakouts.set('currentBreakoutSession', {
3224
+ sessionId: 'session-id-1',
3225
+ groupId: 'group-id-1',
3226
+ });
2354
3227
 
3228
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
2355
3229
  meeting.updateLLMConnection.restore();
2356
3230
 
2357
- isJoinedStub.returns(true);
2358
- meeting.webex.internal.llm.isConnected.returns(false);
3231
+ await meeting.updateLLMConnection();
2359
3232
  await meeting.updateLLMConnection();
2360
3233
 
2361
- assert.exists(meeting.llmHealthCheckTimer);
3234
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3235
+ .getCalls()
3236
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
2362
3237
 
2363
- isJoinedStub.returns(false);
2364
- meeting.webex.internal.llm.isConnected.returns(true);
3238
+ assert.lengthOf(joinResponseCalls, 1);
3239
+ assert.equal(joinResponseCalls[0].args[0].options.meetingId, meeting.id);
3240
+ });
2365
3241
 
2366
- await meeting.updateLLMConnection();
3242
+ it('does not emit breakout join response metric when breakout session is missing', async () => {
3243
+ sinon.stub(meeting, 'isJoined').returns(true);
3244
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3245
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3246
+ clientLLMDatachannelResponseTime: 10,
3247
+ clientLLMWebSocketConnectTime: 20,
3248
+ });
2367
3249
 
2368
- assert.calledOnce(meeting.webex.internal.llm.disconnectLLM);
3250
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3251
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
2369
3252
 
2370
- assert.isUndefined(meeting.llmHealthCheckTimer);
3253
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3254
+ meeting.updateLLMConnection.restore();
2371
3255
 
2372
- Metrics.sendBehavioralMetric.resetHistory();
2373
- fakeClock.tick(3 * 60 * 1000);
3256
+ await meeting.updateLLMConnection();
2374
3257
 
2375
- assert.neverCalledWith(
2376
- Metrics.sendBehavioralMetric,
2377
- BEHAVIORAL_METRICS.LLM_HEALTHCHECK_FAILURE
2378
- );
3258
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3259
+ .getCalls()
3260
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3261
+
3262
+ assert.lengthOf(joinResponseCalls, 0);
2379
3263
  });
2380
- });
2381
3264
 
2382
- describe('refreshPermissionToken', () => {
3265
+ it('does not emit failed breakout join response metric when breakout session is missing', async () => {
3266
+ sinon.stub(meeting, 'isJoined').returns(true);
3267
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3268
+ sinon
3269
+ .stub(meeting.webex.internal.llm, 'registerAndConnect')
3270
+ .rejects(new Error('failed to connect LLM'));
3271
+
3272
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3273
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3274
+
3275
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3276
+ meeting.updateLLMConnection.restore();
3277
+
3278
+ try {
3279
+ await meeting.updateLLMConnection();
3280
+ assert.fail('Expected updateLLMConnection to reject');
3281
+ } catch (error) {
3282
+ assert.equal(error.message, 'failed to connect LLM');
3283
+ }
3284
+
3285
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3286
+ .getCalls()
3287
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3288
+
3289
+ assert.lengthOf(joinResponseCalls, 0);
3290
+ });
3291
+
3292
+ it('emits llm breakout join response metric after suppressing join response without llmLatency', async () => {
3293
+ sinon.stub(meeting, 'isJoined').returns(true);
3294
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3295
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3296
+ clientLLMDatachannelResponseTime: 10,
3297
+ clientLLMWebSocketConnectTime: 20,
3298
+ });
3299
+
3300
+ meeting.config.enableAutomaticLLM = true;
3301
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3302
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3303
+ meeting.breakouts.set('sessionType', 'BREAKOUT');
3304
+ meeting.breakouts.set('status', 'OPEN');
3305
+ meeting.breakouts.set('currentBreakoutSession', {
3306
+ sessionId: 'session-id-1',
3307
+ groupId: 'group-id-1',
3308
+ });
3309
+
3310
+ assert.isFalse(meeting.shouldEmitBreakoutJoinResponseMetric('move-id-1'));
3311
+
3312
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3313
+ meeting.updateLLMConnection.restore();
3314
+
3315
+ await meeting.updateLLMConnection();
3316
+
3317
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3318
+ .getCalls()
3319
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3320
+
3321
+ assert.lengthOf(joinResponseCalls, 1);
3322
+ assert.deepEqual(joinResponseCalls[0].args[0].payload.llmLatency, {
3323
+ clientLLMDatachannelResponseTime: 10,
3324
+ clientLLMWebSocketConnectTime: 20,
3325
+ });
3326
+ });
3327
+
3328
+ it('emits breakout join response metric with llmLatency when returning to main session', async () => {
3329
+ sinon.stub(meeting, 'isJoined').returns(true);
3330
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3331
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3332
+ clientLLMDatachannelResponseTime: 10,
3333
+ clientLLMWebSocketConnectTime: 20,
3334
+ });
3335
+
3336
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3337
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3338
+ meeting.breakouts.set('sessionType', 'MAIN');
3339
+ meeting.breakouts.set('status', 'OPEN');
3340
+ meeting.breakouts.set('currentBreakoutSession', {
3341
+ sessionId: 'session-id-1',
3342
+ groupId: 'group-id-1',
3343
+ });
3344
+
3345
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3346
+ meeting.updateLLMConnection.restore();
3347
+
3348
+ await meeting.updateLLMConnection();
3349
+
3350
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3351
+ .getCalls()
3352
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3353
+
3354
+ assert.lengthOf(joinResponseCalls, 1);
3355
+ assert.deepEqual(joinResponseCalls[0].args[0].payload.llmLatency, {
3356
+ clientLLMDatachannelResponseTime: 10,
3357
+ clientLLMWebSocketConnectTime: 20,
3358
+ });
3359
+ });
3360
+
3361
+ it('uses the partial datachannel timing from the error when the websocket connect fails', async () => {
3362
+ sinon.stub(meeting, 'isJoined').returns(true);
3363
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3364
+ const connectError = new Error('failed to connect LLM');
3365
+ connectError.timing = {clientLLMDatachannelResponseTime: 42};
3366
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').rejects(connectError);
3367
+
3368
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3369
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3370
+ meeting.breakouts.set('sessionType', 'BREAKOUT');
3371
+ meeting.breakouts.set('status', 'OPEN');
3372
+ meeting.breakouts.set('currentBreakoutSession', {
3373
+ sessionId: 'session-id-1',
3374
+ groupId: 'group-id-1',
3375
+ });
3376
+
3377
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3378
+ meeting.updateLLMConnection.restore();
3379
+
3380
+ try {
3381
+ await meeting.updateLLMConnection();
3382
+ assert.fail('Expected updateLLMConnection to reject');
3383
+ } catch (error) {
3384
+ assert.equal(error, connectError);
3385
+ }
3386
+
3387
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3388
+ .getCalls()
3389
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3390
+
3391
+ assert.lengthOf(joinResponseCalls, 1);
3392
+ assert.deepEqual(joinResponseCalls[0].args[0].payload.llmLatency, {
3393
+ clientLLMDatachannelResponseTime: 42,
3394
+ clientLLMWebSocketConnectTime: 0,
3395
+ });
3396
+ });
3397
+
3398
+ it('reports the partial datachannel timing on client.llm.connect.response when the websocket connect fails during initial join', async () => {
3399
+ sinon.stub(meeting, 'isJoined').returns(true);
3400
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3401
+ const connectError = new Error('failed to connect LLM');
3402
+ connectError.timing = {clientLLMDatachannelResponseTime: 42};
3403
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').rejects(connectError);
3404
+
3405
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3406
+ meeting.updateLLMConnection.restore();
3407
+
3408
+ try {
3409
+ await meeting.updateLLMConnection({isInitialJoinPhase: true});
3410
+ assert.fail('Expected updateLLMConnection to reject');
3411
+ } catch (error) {
3412
+ assert.equal(error, connectError);
3413
+ }
3414
+
3415
+ const connectResponseCalls = webex.internal.newMetrics.submitClientEvent
3416
+ .getCalls()
3417
+ .filter((call) => call.args[0]?.name === 'client.llm.connect.response');
3418
+
3419
+ assert.lengthOf(connectResponseCalls, 1);
3420
+ assert.deepEqual(connectResponseCalls[0].args[0].payload.llmLatency, {
3421
+ clientLLMDatachannelResponseTime: 42,
3422
+ clientLLMWebSocketConnectTime: 0,
3423
+ });
3424
+ });
3425
+
3426
+ it('clears the LLM health check timer when disconnecting LLM', async () => {
3427
+ const isJoinedStub = sinon.stub(meeting, 'isJoined');
3428
+ sinon.stub(meeting.webex.internal.llm, 'isConnected');
3429
+ sinon.stub(meeting.webex.internal.llm, 'disconnectLLM').resolves();
3430
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({});
3431
+ sinon
3432
+ .stub(meeting.webex.internal.llm, 'getLocusUrl')
3433
+ .returns('https://locus1.example.com');
3434
+ sinon
3435
+ .stub(meeting.webex.internal.llm, 'getDatachannelUrl')
3436
+ .returns('https://datachannel1.example.com');
3437
+
3438
+ meeting.updateLLMConnection.restore();
3439
+
3440
+ isJoinedStub.returns(true);
3441
+ meeting.webex.internal.llm.isConnected.returns(false);
3442
+ await meeting.updateLLMConnection();
3443
+
3444
+ assert.exists(meeting.llmHealthCheckTimer);
3445
+
3446
+ isJoinedStub.returns(false);
3447
+ meeting.webex.internal.llm.isConnected.returns(true);
3448
+
3449
+ await meeting.updateLLMConnection();
3450
+
3451
+ assert.calledOnce(meeting.webex.internal.llm.disconnectLLM);
3452
+
3453
+ assert.isUndefined(meeting.llmHealthCheckTimer);
3454
+
3455
+ Metrics.sendBehavioralMetric.resetHistory();
3456
+ fakeClock.tick(3 * 60 * 1000);
3457
+
3458
+ assert.neverCalledWith(
3459
+ Metrics.sendBehavioralMetric,
3460
+ BEHAVIORAL_METRICS.LLM_HEALTHCHECK_FAILURE
3461
+ );
3462
+ });
3463
+ });
3464
+
3465
+ describe('refreshPermissionToken', () => {
2383
3466
  it('should continue if permissionTokenRefresh fails with a generic error', async () => {
2384
3467
  meeting.checkAndRefreshPermissionToken = sinon.stub().rejects(new Error('bad day'));
2385
3468
  const stateMachineFailSpy = sinon.spy(meeting.meetingFiniteStateMachine, 'fail');
@@ -2467,7 +3550,6 @@ describe('plugin-meetings', () => {
2467
3550
  });
2468
3551
  });
2469
3552
 
2470
-
2471
3553
  describe('#addMedia', () => {
2472
3554
  const muteStateStub = {
2473
3555
  handleClientRequest: sinon.stub().returns(Promise.resolve(true)),
@@ -2614,9 +3696,11 @@ describe('plugin-meetings', () => {
2614
3696
  retriedWithTurnServer: false,
2615
3697
  isMultistream: false,
2616
3698
  isJoinWithMediaRetry: false,
3699
+ iceTransportPolicy: 'all',
2617
3700
  signalingState: 'unknown',
2618
3701
  connectionState: 'unknown',
2619
3702
  iceConnectionState: 'unknown',
3703
+ connectionType: 'udp',
2620
3704
  someReachabilityMetric1: 'some value1',
2621
3705
  someReachabilityMetric2: 'some value2',
2622
3706
  selectedCandidatePairChanges: 2,
@@ -2742,9 +3826,11 @@ describe('plugin-meetings', () => {
2742
3826
  retriedWithTurnServer: false,
2743
3827
  isMultistream: false,
2744
3828
  isJoinWithMediaRetry: false,
3829
+ iceTransportPolicy: 'all',
2745
3830
  signalingState: 'unknown',
2746
3831
  connectionState: 'unknown',
2747
3832
  iceConnectionState: 'unknown',
3833
+ connectionType: 'udp',
2748
3834
  someReachabilityMetric1: 'some value1',
2749
3835
  someReachabilityMetric2: 'some value2',
2750
3836
  selectedCandidatePairChanges: 2,
@@ -3512,9 +4598,11 @@ describe('plugin-meetings', () => {
3512
4598
  retriedWithTurnServer: true,
3513
4599
  isMultistream: false,
3514
4600
  isJoinWithMediaRetry: false,
4601
+ iceTransportPolicy: 'all',
3515
4602
  signalingState: 'unknown',
3516
4603
  connectionState: 'unknown',
3517
4604
  iceConnectionState: 'unknown',
4605
+ connectionType: 'udp',
3518
4606
  selectedCandidatePairChanges: 2,
3519
4607
  numTransports: 1,
3520
4608
  iceCandidatesCount: 0,
@@ -3539,6 +4627,173 @@ describe('plugin-meetings', () => {
3539
4627
  assert.isOk(errorThrown);
3540
4628
  });
3541
4629
 
4630
+ [
4631
+ {iceConnected: true, title: 'iceConnected=true'},
4632
+ {iceConnected: false, title: 'iceConnected=false'},
4633
+ ].forEach(({iceConnected, title}) => {
4634
+ it(`should propagate ${title} from waitForMediaConnectionConnected rejection to AddMediaFailed`, async () => {
4635
+ webex.meetings.reachability = {
4636
+ isWebexMediaBackendUnreachable: sinon.stub().resolves(false),
4637
+ getReachabilityMetrics: sinon.stub().resolves({}),
4638
+ stopReachability: sinon.stub(),
4639
+ isSubnetReachable: sinon.stub().returns(true),
4640
+ };
4641
+ webex.internal.newMetrics.callDiagnosticMetrics.getErrorPayloadForClientErrorCode =
4642
+ sinon.stub().returns({fatal: true});
4643
+ sinon.stub(CallDiagnosticUtils, 'generateClientErrorCodeForIceFailure').returns(2004);
4644
+
4645
+ meeting.meetingState = 'ACTIVE';
4646
+ const rejectedResult = {iceConnected};
4647
+ meeting.mediaProperties.waitForMediaConnectionConnected = sinon
4648
+ .stub()
4649
+ .rejects(rejectedResult);
4650
+
4651
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4652
+ turnServerInfo: {urls: ['turns:fake:443'], username: 'u', password: 'p'},
4653
+ turnDiscoverySkippedReason: undefined,
4654
+ });
4655
+
4656
+ const forceRtcMetricsSend = sinon.stub().resolves();
4657
+ Media.createMediaConnection = sinon.stub().returns({
4658
+ close: sinon.stub(),
4659
+ forceRtcMetricsSend,
4660
+ getConnectionState: sinon.stub().returns(ConnectionState.Connected),
4661
+ initiateOffer: sinon.stub().resolves({}),
4662
+ on: sinon.stub(),
4663
+ });
4664
+
4665
+ let thrownError;
4666
+ await meeting.addMedia({mediaSettings: {}}).catch((err) => {
4667
+ thrownError = err;
4668
+ });
4669
+
4670
+ assert.instanceOf(thrownError, AddMediaFailed);
4671
+ assert.equal(thrownError.iceConnected, iceConnected);
4672
+ // the AddMediaFailed cause should be the MediaConnectionTimedOutError, which in turn should
4673
+ // preserve the original rejected result as its cause, so that the web client
4674
+ // can find the CA-reported error in the eventErrorCache via the cause chain
4675
+ assert.instanceOf(thrownError.cause, MediaConnectionTimedOutError);
4676
+ assert.equal(thrownError.cause.cause, rejectedResult);
4677
+ });
4678
+ });
4679
+
4680
+ describe('iceTransportPolicy=relay handling', () => {
4681
+ let createMediaConnectionStub;
4682
+
4683
+ beforeEach(() => {
4684
+ webex.meetings.reachability = {
4685
+ isWebexMediaBackendUnreachable: sinon.stub().resolves(false),
4686
+ isAnyClusterReachableViaProtocol: sinon.stub().resolves(true),
4687
+ getReachabilityMetrics: sinon.stub().resolves({}),
4688
+ stopReachability: sinon.stub(),
4689
+ isSubnetReachable: sinon.stub().returns(true),
4690
+ };
4691
+ webex.internal.newMetrics.callDiagnosticMetrics.getErrorPayloadForClientErrorCode =
4692
+ sinon.stub().returns({fatal: true});
4693
+ sinon.stub(CallDiagnosticUtils, 'generateClientErrorCodeForIceFailure').returns(2004);
4694
+
4695
+ meeting.meetingState = 'ACTIVE';
4696
+ meeting.mediaProperties.waitForMediaConnectionConnected = sinon.stub().resolves();
4697
+
4698
+ createMediaConnectionStub = sinon.stub().returns({
4699
+ close: sinon.stub(),
4700
+ forceRtcMetricsSend: sinon.stub().resolves(),
4701
+ getConnectionState: sinon.stub().returns(ConnectionState.Connected),
4702
+ initiateOffer: sinon.stub().resolves({}),
4703
+ on: sinon.stub(),
4704
+ });
4705
+ Media.createMediaConnection = createMediaConnectionStub;
4706
+ });
4707
+
4708
+ [
4709
+ {
4710
+ title:
4711
+ 'should drop iceTransportPolicy=relay when TURN discovery returns no turn server info',
4712
+ turnServerInfo: undefined,
4713
+ turnDiscoverySkippedReason: 'reachability',
4714
+ },
4715
+ {
4716
+ title:
4717
+ 'should drop iceTransportPolicy=relay when TURN discovery returns turnServerInfo with empty urls',
4718
+ turnServerInfo: {urls: [], username: 'u', password: 'p'},
4719
+ turnDiscoverySkippedReason: undefined,
4720
+ },
4721
+ ].forEach(({title, turnServerInfo, turnDiscoverySkippedReason}) => {
4722
+ it(title, async () => {
4723
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4724
+ turnServerInfo,
4725
+ turnDiscoverySkippedReason,
4726
+ });
4727
+
4728
+ await meeting.addMediaInternal(
4729
+ () => 'JOIN_MEETING_FINAL',
4730
+ false,
4731
+ undefined,
4732
+ 'relay',
4733
+ {mediaSettings: {}}
4734
+ );
4735
+
4736
+ assert.calledOnce(createMediaConnectionStub);
4737
+ const config = createMediaConnectionStub.firstCall.args[3];
4738
+ assert.isUndefined(config.iceTransportPolicy);
4739
+
4740
+ const successCall = Metrics.sendBehavioralMetric
4741
+ .getCalls()
4742
+ .find((call) => call.args[0] === BEHAVIORAL_METRICS.ADD_MEDIA_SUCCESS);
4743
+ assert.isDefined(successCall);
4744
+ assert.equal(successCall.args[1].iceTransportPolicy, 'all');
4745
+ });
4746
+ });
4747
+
4748
+ it('should send ADD_MEDIA_SUCCESS metric with iceTransportPolicy=relay when relay is used', async () => {
4749
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4750
+ turnServerInfo: {
4751
+ urls: ['turns:turn-server:443?transport=tcp'],
4752
+ username: 'u',
4753
+ password: 'p',
4754
+ },
4755
+ turnDiscoverySkippedReason: undefined,
4756
+ });
4757
+
4758
+ await meeting.addMediaInternal(() => 'JOIN_MEETING_FINAL', false, undefined, 'relay', {
4759
+ mediaSettings: {},
4760
+ });
4761
+
4762
+ const successCall = Metrics.sendBehavioralMetric
4763
+ .getCalls()
4764
+ .find((call) => call.args[0] === BEHAVIORAL_METRICS.ADD_MEDIA_SUCCESS);
4765
+ assert.isDefined(successCall);
4766
+ assert.equal(successCall.args[1].iceTransportPolicy, 'relay');
4767
+ });
4768
+
4769
+ it('should send ADD_MEDIA_FAILURE metric with iceTransportPolicy=relay when relay attempt fails', async () => {
4770
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4771
+ turnServerInfo: {
4772
+ urls: ['turns:turn-server:443?transport=tcp'],
4773
+ username: 'u',
4774
+ password: 'p',
4775
+ },
4776
+ turnDiscoverySkippedReason: undefined,
4777
+ });
4778
+
4779
+ meeting.mediaProperties.waitForMediaConnectionConnected = sinon
4780
+ .stub()
4781
+ .rejects(new MediaConnectionTimedOutError('timed out', true));
4782
+
4783
+ await assert.isRejected(
4784
+ meeting.addMediaInternal(() => 'JOIN_MEETING_FINAL', false, undefined, 'relay', {
4785
+ mediaSettings: {},
4786
+ })
4787
+ );
4788
+
4789
+ const failureCall = Metrics.sendBehavioralMetric
4790
+ .getCalls()
4791
+ .find((call) => call.args[0] === BEHAVIORAL_METRICS.ADD_MEDIA_FAILURE);
4792
+ assert.isDefined(failureCall);
4793
+ assert.equal(failureCall.args[1].iceTransportPolicy, 'relay');
4794
+ });
4795
+ });
4796
+
3542
4797
  it('should resolve if waitForMediaConnectionConnected() rejects the first time but resolves the second time', async () => {
3543
4798
  const FAKE_ERROR = {fatal: true};
3544
4799
  webex.meetings.reachability = {
@@ -3728,6 +4983,7 @@ describe('plugin-meetings', () => {
3728
4983
  isMultistream: false,
3729
4984
  retriedWithTurnServer: true,
3730
4985
  isJoinWithMediaRetry: false,
4986
+ iceTransportPolicy: 'all',
3731
4987
  iceCandidatesCount: 0,
3732
4988
  subnet_reachable: null,
3733
4989
  selected_cluster: null,
@@ -3891,6 +5147,7 @@ describe('plugin-meetings', () => {
3891
5147
  isMultistream: false,
3892
5148
  retriedWithTurnServer: false,
3893
5149
  isJoinWithMediaRetry: false,
5150
+ iceTransportPolicy: 'all',
3894
5151
  someReachabilityMetric1: 'some value1',
3895
5152
  someReachabilityMetric2: 'some value2',
3896
5153
  iceCandidatesCount: 3,
@@ -3956,9 +5213,11 @@ describe('plugin-meetings', () => {
3956
5213
  retriedWithTurnServer: false,
3957
5214
  isMultistream: false,
3958
5215
  isJoinWithMediaRetry: false,
5216
+ iceTransportPolicy: 'all',
3959
5217
  signalingState: 'unknown',
3960
5218
  connectionState: 'unknown',
3961
5219
  iceConnectionState: 'unknown',
5220
+ connectionType: 'udp',
3962
5221
  selectedCandidatePairChanges: 2,
3963
5222
  numTransports: 1,
3964
5223
  subnet_reachable: null,
@@ -4019,9 +5278,11 @@ describe('plugin-meetings', () => {
4019
5278
  retriedWithTurnServer: false,
4020
5279
  isMultistream: false,
4021
5280
  isJoinWithMediaRetry: false,
5281
+ iceTransportPolicy: 'all',
4022
5282
  signalingState: 'unknown',
4023
5283
  connectionState: 'unknown',
4024
5284
  iceConnectionState: 'unknown',
5285
+ connectionType: 'udp',
4025
5286
  selectedCandidatePairChanges: 2,
4026
5287
  numTransports: 1,
4027
5288
  '701_error': 2,
@@ -4083,6 +5344,7 @@ describe('plugin-meetings', () => {
4083
5344
  isMultistream: false,
4084
5345
  retriedWithTurnServer: false,
4085
5346
  isJoinWithMediaRetry: false,
5347
+ iceTransportPolicy: 'all',
4086
5348
  iceCandidatesCount: 0,
4087
5349
  reachability_public_udp_success: 5,
4088
5350
  subnet_reachable: false,
@@ -4148,9 +5410,11 @@ describe('plugin-meetings', () => {
4148
5410
  retriedWithTurnServer: false,
4149
5411
  isMultistream: false,
4150
5412
  isJoinWithMediaRetry: false,
5413
+ iceTransportPolicy: 'all',
4151
5414
  signalingState: 'unknown',
4152
5415
  connectionState: 'unknown',
4153
5416
  iceConnectionState: 'unknown',
5417
+ connectionType: 'udp',
4154
5418
  selectedCandidatePairChanges: 2,
4155
5419
  numTransports: 1,
4156
5420
  reachability_public_udp_success: 5,
@@ -4462,76 +5726,367 @@ describe('plugin-meetings', () => {
4462
5726
  meetingId: meeting.id,
4463
5727
  },
4464
5728
  });
4465
- });
5729
+ });
5730
+
5731
+ it('counts the number of members that are in the meeting or lobby for MEDIA_QUALITY event', async () => {
5732
+ let fakeMembersCollection = {
5733
+ members: {
5734
+ member1: {isInMeeting: true, isInLobby: false},
5735
+ member2: {isInMeeting: false, isInLobby: true},
5736
+ member3: {isInMeeting: false, isInLobby: false},
5737
+ member4: {isInMeeting: true, isInLobby: false},
5738
+ },
5739
+ };
5740
+ sinon.stub(meeting, 'getMembers').returns({membersCollection: fakeMembersCollection});
5741
+ const fakeData = {intervalMetadata: {}};
5742
+
5743
+ statsAnalyzerStub.emit(
5744
+ {file: 'test', function: 'test'},
5745
+ StatsAnalyzerEventNames.MEDIA_QUALITY,
5746
+ {data: fakeData}
5747
+ );
5748
+
5749
+ assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
5750
+ name: 'client.mediaquality.event',
5751
+ options: {
5752
+ meetingId: meeting.id,
5753
+ },
5754
+ payload: {
5755
+ intervals: [
5756
+ sinon.match.has('intervalMetadata', sinon.match.has('meetingUserCount', 3)),
5757
+ ],
5758
+ },
5759
+ });
5760
+ // Move member2 from lobby to neither in meeting nor lobby
5761
+ fakeMembersCollection.members.member2.isInLobby = false;
5762
+
5763
+ statsAnalyzerStub.emit(
5764
+ {file: 'test', function: 'test'},
5765
+ StatsAnalyzerEventNames.MEDIA_QUALITY,
5766
+ {data: fakeData}
5767
+ );
5768
+
5769
+ assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
5770
+ name: 'client.mediaquality.event',
5771
+ options: {
5772
+ meetingId: meeting.id,
5773
+ },
5774
+ payload: {
5775
+ intervals: [
5776
+ sinon.match.has('intervalMetadata', sinon.match.has('meetingUserCount', 2)),
5777
+ ],
5778
+ },
5779
+ });
5780
+ });
5781
+
5782
+ it('calls submitMQE correctly', async () => {
5783
+ const fakeData = {intervalMetadata: {bla: 'bla'}};
5784
+
5785
+ statsAnalyzerStub.emit(
5786
+ {file: 'test', function: 'test'},
5787
+ StatsAnalyzerEventNames.MEDIA_QUALITY,
5788
+ {data: fakeData}
5789
+ );
5790
+
5791
+ assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
5792
+ name: 'client.mediaquality.event',
5793
+ options: {
5794
+ meetingId: meeting.id,
5795
+ },
5796
+ payload: {
5797
+ intervals: [fakeData],
5798
+ },
5799
+ });
5800
+ });
5801
+
5802
+ describe('handles STATS_UPDATE event for SRTP cipher detection', () => {
5803
+ it('emits MEETING_SRTP_CIPHER_UPDATED event when srtpCipher is found in transport stats', async () => {
5804
+ const fakeStats = new Map([
5805
+ [
5806
+ 'transport-1',
5807
+ {
5808
+ type: 'transport',
5809
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
5810
+ dtlsCipher: 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256',
5811
+ },
5812
+ ],
5813
+ [
5814
+ 'outbound-rtp-1',
5815
+ {
5816
+ type: 'outbound-rtp',
5817
+ ssrc: 12345,
5818
+ },
5819
+ ],
5820
+ ]);
5821
+
5822
+ statsAnalyzerStub.emit(
5823
+ {file: 'test', function: 'test'},
5824
+ StatsAnalyzerEventNames.STATS_UPDATE,
5825
+ {stats: fakeStats}
5826
+ );
5827
+
5828
+ assert.calledWith(
5829
+ TriggerProxy.trigger,
5830
+ sinon.match.instanceOf(Meeting),
5831
+ {
5832
+ file: 'meeting/index',
5833
+ function: 'setupStatsAnalyzerEventHandlers',
5834
+ },
5835
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5836
+ {srtpCipher: 'AES_CM_128_HMAC_SHA1_80'}
5837
+ );
5838
+
5839
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5840
+ });
5841
+
5842
+ it('updates meeting.mediaProperties.srtpCipher when cipher changes', async () => {
5843
+ const firstStats = new Map([
5844
+ [
5845
+ 'transport-1',
5846
+ {
5847
+ type: 'transport',
5848
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
5849
+ },
5850
+ ],
5851
+ ]);
5852
+
5853
+ statsAnalyzerStub.emit(
5854
+ {file: 'test', function: 'test'},
5855
+ StatsAnalyzerEventNames.STATS_UPDATE,
5856
+ {stats: firstStats}
5857
+ );
5858
+
5859
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5860
+
5861
+ const secondStats = new Map([
5862
+ [
5863
+ 'transport-1',
5864
+ {
5865
+ type: 'transport',
5866
+ srtpCipher: 'AEAD_AES_256_GCM',
5867
+ },
5868
+ ],
5869
+ ]);
5870
+
5871
+ TriggerProxy.trigger.resetHistory();
5872
+
5873
+ statsAnalyzerStub.emit(
5874
+ {file: 'test', function: 'test'},
5875
+ StatsAnalyzerEventNames.STATS_UPDATE,
5876
+ {stats: secondStats}
5877
+ );
5878
+
5879
+ assert.calledWith(
5880
+ TriggerProxy.trigger,
5881
+ sinon.match.instanceOf(Meeting),
5882
+ {
5883
+ file: 'meeting/index',
5884
+ function: 'setupStatsAnalyzerEventHandlers',
5885
+ },
5886
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5887
+ {srtpCipher: 'AEAD_AES_256_GCM'}
5888
+ );
5889
+
5890
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AEAD_AES_256_GCM');
5891
+ });
5892
+
5893
+ it('does not emit event when srtpCipher has not changed', async () => {
5894
+ const firstStats = new Map([
5895
+ [
5896
+ 'transport-1',
5897
+ {
5898
+ type: 'transport',
5899
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
5900
+ },
5901
+ ],
5902
+ ]);
5903
+
5904
+ statsAnalyzerStub.emit(
5905
+ {file: 'test', function: 'test'},
5906
+ StatsAnalyzerEventNames.STATS_UPDATE,
5907
+ {stats: firstStats}
5908
+ );
5909
+
5910
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5911
+
5912
+ TriggerProxy.trigger.resetHistory();
5913
+
5914
+ // Emit same cipher again
5915
+ statsAnalyzerStub.emit(
5916
+ {file: 'test', function: 'test'},
5917
+ StatsAnalyzerEventNames.STATS_UPDATE,
5918
+ {stats: firstStats}
5919
+ );
5920
+
5921
+ // Should not trigger event again
5922
+ assert.neverCalledWith(
5923
+ TriggerProxy.trigger,
5924
+ sinon.match.instanceOf(Meeting),
5925
+ sinon.match.any,
5926
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5927
+ sinon.match.any
5928
+ );
5929
+
5930
+ // Cipher should remain the same
5931
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5932
+ });
5933
+
5934
+ it('does not emit event when stats contain no transport with srtpCipher', async () => {
5935
+ const fakeStats = new Map([
5936
+ [
5937
+ 'outbound-rtp-1',
5938
+ {
5939
+ type: 'outbound-rtp',
5940
+ ssrc: 12345,
5941
+ },
5942
+ ],
5943
+ [
5944
+ 'inbound-rtp-1',
5945
+ {
5946
+ type: 'inbound-rtp',
5947
+ ssrc: 67890,
5948
+ },
5949
+ ],
5950
+ ]);
5951
+
5952
+ statsAnalyzerStub.emit(
5953
+ {file: 'test', function: 'test'},
5954
+ StatsAnalyzerEventNames.STATS_UPDATE,
5955
+ {stats: fakeStats}
5956
+ );
5957
+
5958
+ assert.neverCalledWith(
5959
+ TriggerProxy.trigger,
5960
+ sinon.match.instanceOf(Meeting),
5961
+ sinon.match.any,
5962
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5963
+ sinon.match.any
5964
+ );
5965
+
5966
+ assert.isUndefined(meeting.mediaProperties.srtpCipher);
5967
+ });
5968
+
5969
+ it('does not emit event when transport stat has no srtpCipher property', async () => {
5970
+ const fakeStats = new Map([
5971
+ [
5972
+ 'transport-1',
5973
+ {
5974
+ type: 'transport',
5975
+ dtlsCipher: 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256',
5976
+ // no srtpCipher property
5977
+ },
5978
+ ],
5979
+ ]);
5980
+
5981
+ statsAnalyzerStub.emit(
5982
+ {file: 'test', function: 'test'},
5983
+ StatsAnalyzerEventNames.STATS_UPDATE,
5984
+ {stats: fakeStats}
5985
+ );
5986
+
5987
+ assert.neverCalledWith(
5988
+ TriggerProxy.trigger,
5989
+ sinon.match.instanceOf(Meeting),
5990
+ sinon.match.any,
5991
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5992
+ sinon.match.any
5993
+ );
5994
+
5995
+ assert.isUndefined(meeting.mediaProperties.srtpCipher);
5996
+ });
5997
+
5998
+ it('uses first transport with srtpCipher when multiple transports exist', async () => {
5999
+ const fakeStats = new Map([
6000
+ [
6001
+ 'transport-1',
6002
+ {
6003
+ type: 'transport',
6004
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
6005
+ },
6006
+ ],
6007
+ [
6008
+ 'transport-2',
6009
+ {
6010
+ type: 'transport',
6011
+ srtpCipher: 'AEAD_AES_256_GCM',
6012
+ },
6013
+ ],
6014
+ [
6015
+ 'outbound-rtp-1',
6016
+ {
6017
+ type: 'outbound-rtp',
6018
+ ssrc: 12345,
6019
+ },
6020
+ ],
6021
+ ]);
6022
+
6023
+ statsAnalyzerStub.emit(
6024
+ {file: 'test', function: 'test'},
6025
+ StatsAnalyzerEventNames.STATS_UPDATE,
6026
+ {stats: fakeStats}
6027
+ );
6028
+
6029
+ assert.calledWith(
6030
+ TriggerProxy.trigger,
6031
+ sinon.match.instanceOf(Meeting),
6032
+ {
6033
+ file: 'meeting/index',
6034
+ function: 'setupStatsAnalyzerEventHandlers',
6035
+ },
6036
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
6037
+ {srtpCipher: 'AES_CM_128_HMAC_SHA1_80'}
6038
+ );
6039
+
6040
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
6041
+ });
4466
6042
 
4467
- it('counts the number of members that are in the meeting or lobby for MEDIA_QUALITY event', async () => {
4468
- let fakeMembersCollection = {
4469
- members: {
4470
- member1: {isInMeeting: true, isInLobby: false},
4471
- member2: {isInMeeting: false, isInLobby: true},
4472
- member3: {isInMeeting: false, isInLobby: false},
4473
- member4: {isInMeeting: true, isInLobby: false},
4474
- },
4475
- };
4476
- sinon.stub(meeting, 'getMembers').returns({membersCollection: fakeMembersCollection});
4477
- const fakeData = {intervalMetadata: {}};
6043
+ it('handles empty stats map without errors', async () => {
6044
+ const emptyStats = new Map();
4478
6045
 
4479
- statsAnalyzerStub.emit(
4480
- {file: 'test', function: 'test'},
4481
- StatsAnalyzerEventNames.MEDIA_QUALITY,
4482
- {data: fakeData}
4483
- );
6046
+ statsAnalyzerStub.emit(
6047
+ {file: 'test', function: 'test'},
6048
+ StatsAnalyzerEventNames.STATS_UPDATE,
6049
+ {stats: emptyStats}
6050
+ );
4484
6051
 
4485
- assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
4486
- name: 'client.mediaquality.event',
4487
- options: {
4488
- meetingId: meeting.id,
4489
- },
4490
- payload: {
4491
- intervals: [
4492
- sinon.match.has('intervalMetadata', sinon.match.has('meetingUserCount', 3)),
4493
- ],
4494
- },
6052
+ assert.neverCalledWith(
6053
+ TriggerProxy.trigger,
6054
+ sinon.match.instanceOf(Meeting),
6055
+ sinon.match.any,
6056
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
6057
+ sinon.match.any
6058
+ );
6059
+
6060
+ assert.isUndefined(meeting.mediaProperties.srtpCipher);
4495
6061
  });
4496
- // Move member2 from lobby to neither in meeting nor lobby
4497
- fakeMembersCollection.members.member2.isInLobby = false;
4498
6062
 
4499
- statsAnalyzerStub.emit(
4500
- {file: 'test', function: 'test'},
4501
- StatsAnalyzerEventNames.MEDIA_QUALITY,
4502
- {data: fakeData}
4503
- );
6063
+ it('logs cipher change when cipher is updated', async () => {
6064
+ const loggerSpy = sinon.spy(LoggerProxy.logger, 'info');
4504
6065
 
4505
- assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
4506
- name: 'client.mediaquality.event',
4507
- options: {
4508
- meetingId: meeting.id,
4509
- },
4510
- payload: {
4511
- intervals: [
4512
- sinon.match.has('intervalMetadata', sinon.match.has('meetingUserCount', 2)),
6066
+ meeting.mediaProperties.srtpCipher = 'AES_CM_128_HMAC_SHA1_80';
6067
+
6068
+ const newStats = new Map([
6069
+ [
6070
+ 'transport-1',
6071
+ {
6072
+ type: 'transport',
6073
+ srtpCipher: 'AEAD_AES_256_GCM',
6074
+ },
4513
6075
  ],
4514
- },
4515
- });
4516
- });
6076
+ ]);
4517
6077
 
4518
- it('calls submitMQE correctly', async () => {
4519
- const fakeData = {intervalMetadata: {bla: 'bla'}};
6078
+ statsAnalyzerStub.emit(
6079
+ {file: 'test', function: 'test'},
6080
+ StatsAnalyzerEventNames.STATS_UPDATE,
6081
+ {stats: newStats}
6082
+ );
4520
6083
 
4521
- statsAnalyzerStub.emit(
4522
- {file: 'test', function: 'test'},
4523
- StatsAnalyzerEventNames.MEDIA_QUALITY,
4524
- {data: fakeData}
4525
- );
6084
+ assert.calledWithMatch(
6085
+ loggerSpy,
6086
+ sinon.match(/SRTP cipher changed from AES_CM_128_HMAC_SHA1_80 to AEAD_AES_256_GCM/)
6087
+ );
4526
6088
 
4527
- assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
4528
- name: 'client.mediaquality.event',
4529
- options: {
4530
- meetingId: meeting.id,
4531
- },
4532
- payload: {
4533
- intervals: [fakeData],
4534
- },
6089
+ loggerSpy.restore();
4535
6090
  });
4536
6091
  });
4537
6092
  });
@@ -4656,7 +6211,10 @@ describe('plugin-meetings', () => {
4656
6211
  meeting.mediaProperties.sendMediaIssueMetric,
4657
6212
  'inbound_audio',
4658
6213
  fakeEventData.issueSubType,
4659
- meeting.correlationId
6214
+ {
6215
+ correlationId: meeting.correlationId,
6216
+ isMultistream: meeting.isMultistream,
6217
+ }
4660
6218
  );
4661
6219
  });
4662
6220
  });
@@ -6192,13 +7750,14 @@ describe('plugin-meetings', () => {
6192
7750
  sinon.stub(meeting.locusMediaRequest, 'downgradeFromMultistreamToTranscoded');
6193
7751
  });
6194
7752
 
6195
- const runCheck = async (turnServerInfo, forceTurnDiscovery) => {
7753
+ const runCheck = async (turnServerInfo, forceTurnDiscovery, iceTransportPolicy) => {
6196
7754
  // we're calling addMediaInternal() with mic stream,
6197
7755
  // so that we also verify that audioMute, videoMute info is correctly sent to backend
6198
7756
  const addMediaPromise = meeting.addMediaInternal(
6199
7757
  () => '',
6200
- turnServerInfo,
6201
7758
  forceTurnDiscovery,
7759
+ turnServerInfo,
7760
+ iceTransportPolicy,
6202
7761
  {
6203
7762
  localStreams: {microphone: fakeMicrophoneStream},
6204
7763
  }
@@ -6252,6 +7811,10 @@ describe('plugin-meetings', () => {
6252
7811
  // at this point the meeting should have been downgraded to transcoded
6253
7812
  assert.equal(meeting.isMultistream, false);
6254
7813
 
7814
+ // iceTransportPolicy must be reset to undefined on downgrade to transcoded,
7815
+ // otherwise the transcoded retry could gather direct candidates while metrics report relay
7816
+ assert.isUndefined(meeting.addMediaData.iceTransportPolicy);
7817
+
6255
7818
  // old stats analyzer stopped and new one created
6256
7819
  assert.calledOnce(initialStatsAnalyzer.stopAnalyzer);
6257
7820
  assert.calledOnceWithExactly(
@@ -6342,6 +7905,11 @@ describe('plugin-meetings', () => {
6342
7905
  true
6343
7906
  );
6344
7907
  });
7908
+
7909
+ it('resets iceTransportPolicy to undefined when falling back from multistream (relay) to transcoded', async () => {
7910
+ // simulate a relay-only retry falling back to transcoded and verify iceTransportPolicy is reset
7911
+ await runCheck(undefined, false, 'relay');
7912
+ });
6345
7913
  });
6346
7914
  }
6347
7915
  })
@@ -6429,6 +7997,9 @@ describe('plugin-meetings', () => {
6429
7997
 
6430
7998
  meeting.annotation.deregisterEvents = sinon.stub();
6431
7999
  webex.internal.llm.off = sinon.stub();
8000
+ webex.internal.mercury.off = sinon.stub();
8001
+ meeting.mercuryOnlineHandler = sinon.stub();
8002
+ meeting.mercuryOfflineHandler = sinon.stub();
6432
8003
 
6433
8004
  // A meeting needs to be joined to leave
6434
8005
  meeting.meetingState = 'ACTIVE';
@@ -6452,6 +8023,67 @@ describe('plugin-meetings', () => {
6452
8023
  assert.calledOnce(meeting.clearMeetingData);
6453
8024
  });
6454
8025
 
8026
+ it('stops listening for LLM/Mercury and tears down transcription and annotation before calling Locus /leave', async () => {
8027
+ const onlineHandler = meeting.mercuryOnlineHandler;
8028
+ const offlineHandler = meeting.mercuryOfflineHandler;
8029
+
8030
+ await meeting.leave();
8031
+
8032
+ // All llm/mercury consumers (direct listeners, voicea transcription,
8033
+ // annotation) must be detached before the /leave request so that
8034
+ // in-flight events do not trigger unnecessary Locus syncs
8035
+ // (per Locus team recommendation).
8036
+ assert.callOrder(
8037
+ webex.internal.llm.off,
8038
+ webex.internal.mercury.off,
8039
+ meeting.stopTranscription,
8040
+ meeting.annotation.deregisterEvents,
8041
+ meeting.meetingRequest.leaveMeeting
8042
+ );
8043
+ assert.calledWithExactly(
8044
+ webex.internal.llm.off,
8045
+ 'event:relay.event',
8046
+ meeting.processRelayEvent
8047
+ );
8048
+ assert.calledWithExactly(
8049
+ webex.internal.llm.off,
8050
+ LOCUS_LLM_EVENT,
8051
+ meeting.processLocusLLMEvent
8052
+ );
8053
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
8054
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
8055
+ assert.isUndefined(meeting.mercuryOnlineHandler);
8056
+ assert.isUndefined(meeting.mercuryOfflineHandler);
8057
+ assert.calledOnceWithExactly(meeting.stopTranscription);
8058
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
8059
+ assert.isUndefined(meeting.transcription);
8060
+ });
8061
+
8062
+ it('tears down llm/mercury/transcription/annotation even when /leave rejects', async () => {
8063
+ const onlineHandler = meeting.mercuryOnlineHandler;
8064
+ const offlineHandler = meeting.mercuryOfflineHandler;
8065
+ meeting.meetingRequest.leaveMeeting = sinon
8066
+ .stub()
8067
+ .returns(Promise.reject(new Error('leave failed')));
8068
+
8069
+ await meeting.leave().catch(() => {});
8070
+
8071
+ assert.calledWithExactly(
8072
+ webex.internal.llm.off,
8073
+ 'event:relay.event',
8074
+ meeting.processRelayEvent
8075
+ );
8076
+ assert.calledWithExactly(
8077
+ webex.internal.llm.off,
8078
+ LOCUS_LLM_EVENT,
8079
+ meeting.processLocusLLMEvent
8080
+ );
8081
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
8082
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
8083
+ assert.calledOnceWithExactly(meeting.stopTranscription);
8084
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
8085
+ });
8086
+
6455
8087
  it('should reset call diagnostic latencies correctly', async () => {
6456
8088
  const leave = meeting.leave();
6457
8089
 
@@ -8459,6 +10091,9 @@ describe('plugin-meetings', () => {
8459
10091
 
8460
10092
  meeting.annotation.deregisterEvents = sinon.stub();
8461
10093
  webex.internal.llm.off = sinon.stub();
10094
+ webex.internal.mercury.off = sinon.stub();
10095
+ meeting.mercuryOnlineHandler = sinon.stub();
10096
+ meeting.mercuryOfflineHandler = sinon.stub();
8462
10097
 
8463
10098
  // A meeting needs to be joined to end
8464
10099
  meeting.meetingState = 'ACTIVE';
@@ -8481,6 +10116,66 @@ describe('plugin-meetings', () => {
8481
10116
  assert.calledOnce(meeting?.unsetPeerConnections);
8482
10117
  assert.calledOnce(meeting?.clearMeetingData);
8483
10118
  });
10119
+
10120
+ it('stops listening for LLM/Mercury and tears down transcription and annotation before calling Locus /end', async () => {
10121
+ const onlineHandler = meeting.mercuryOnlineHandler;
10122
+ const offlineHandler = meeting.mercuryOfflineHandler;
10123
+
10124
+ await meeting.endMeetingForAll();
10125
+
10126
+ // All llm/mercury consumers (direct listeners, voicea transcription,
10127
+ // annotation) must be detached before the /end request so that
10128
+ // in-flight events do not trigger unnecessary Locus syncs
10129
+ // (per Locus team recommendation).
10130
+ assert.callOrder(
10131
+ webex.internal.llm.off,
10132
+ webex.internal.mercury.off,
10133
+ meeting.stopTranscription,
10134
+ meeting.annotation.deregisterEvents,
10135
+ meeting.meetingRequest.endMeetingForAll
10136
+ );
10137
+ assert.calledWithExactly(
10138
+ webex.internal.llm.off,
10139
+ 'event:relay.event',
10140
+ meeting.processRelayEvent
10141
+ );
10142
+ assert.calledWithExactly(
10143
+ webex.internal.llm.off,
10144
+ LOCUS_LLM_EVENT,
10145
+ meeting.processLocusLLMEvent
10146
+ );
10147
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
10148
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
10149
+ assert.isUndefined(meeting.mercuryOnlineHandler);
10150
+ assert.isUndefined(meeting.mercuryOfflineHandler);
10151
+ assert.calledOnceWithExactly(meeting.stopTranscription);
10152
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
10153
+ });
10154
+
10155
+ it('tears down llm/mercury/transcription/annotation even when /end rejects', async () => {
10156
+ const onlineHandler = meeting.mercuryOnlineHandler;
10157
+ const offlineHandler = meeting.mercuryOfflineHandler;
10158
+ meeting.meetingRequest.endMeetingForAll = sinon
10159
+ .stub()
10160
+ .returns(Promise.reject(new Error('end failed')));
10161
+
10162
+ await meeting.endMeetingForAll().catch(() => {});
10163
+
10164
+ assert.calledWithExactly(
10165
+ webex.internal.llm.off,
10166
+ 'event:relay.event',
10167
+ meeting.processRelayEvent
10168
+ );
10169
+ assert.calledWithExactly(
10170
+ webex.internal.llm.off,
10171
+ LOCUS_LLM_EVENT,
10172
+ meeting.processLocusLLMEvent
10173
+ );
10174
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
10175
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
10176
+ assert.calledOnceWithExactly(meeting.stopTranscription);
10177
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
10178
+ });
8484
10179
  });
8485
10180
 
8486
10181
  describe('#moveTo', () => {
@@ -9262,7 +10957,9 @@ describe('plugin-meetings', () => {
9262
10957
  MediaCodecMimeType.OPUS,
9263
10958
  ['maxaveragebitrate', 'maxplaybackrate']
9264
10959
  );
9265
- assert.notCalled(meeting.sendSlotManager.getSlot(MediaType.AudioMain).setCustomCodecParameters);
10960
+ assert.notCalled(
10961
+ meeting.sendSlotManager.getSlot(MediaType.AudioMain).setCustomCodecParameters
10962
+ );
9266
10963
  });
9267
10964
  });
9268
10965
 
@@ -9997,11 +11694,36 @@ describe('plugin-meetings', () => {
9997
11694
  };
9998
11695
  meeting.sdpResponseTimer = '1234';
9999
11696
 
11697
+ webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp = sinon.stub();
11698
+ webex.internal.newMetrics.callDiagnosticLatencies.getLocalSDPGenRemoteSDPRecv = sinon
11699
+ .stub()
11700
+ .returns(100);
11701
+
10000
11702
  eventListeners[MediaConnectionEventNames.REMOTE_SDP_ANSWER_PROCESSED]();
10001
11703
 
11704
+ // the remote-sdp-received timestamp must be saved before the latency is computed
11705
+ // so that getLocalSDPGenRemoteSDPRecv() has an end timestamp to use
11706
+ assert.calledOnceWithExactly(
11707
+ webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp,
11708
+ {
11709
+ key: 'client.media-engine.remote-sdp-received',
11710
+ options: {meetingId: meeting.id},
11711
+ }
11712
+ );
11713
+ assert(
11714
+ webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp.calledBefore(
11715
+ webex.internal.newMetrics.callDiagnosticLatencies.getLocalSDPGenRemoteSDPRecv
11716
+ )
11717
+ );
11718
+
10002
11719
  assert.calledOnce(webex.internal.newMetrics.submitClientEvent);
10003
11720
  assert.calledWithMatch(webex.internal.newMetrics.submitClientEvent, {
10004
11721
  name: 'client.media-engine.remote-sdp-received',
11722
+ payload: {
11723
+ eventData: {
11724
+ localSDPGenRemoteSDPRecv: 100,
11725
+ },
11726
+ },
10005
11727
  options: {meetingId: meeting.id},
10006
11728
  });
10007
11729
 
@@ -10012,7 +11734,7 @@ describe('plugin-meetings', () => {
10012
11734
  {
10013
11735
  correlation_id: meeting.correlationId,
10014
11736
  meetingId: meeting.id,
10015
- latency: undefined,
11737
+ latency: 100,
10016
11738
  }
10017
11739
  );
10018
11740
 
@@ -10417,16 +12139,16 @@ describe('plugin-meetings', () => {
10417
12139
  );
10418
12140
  done();
10419
12141
  });
10420
- it('listens to the self admitted guest event without blocking on token prefetch', async () => {
12142
+ it('listens to the self admitted guest event and waits for token prefetch before reconnecting LLM', async () => {
10421
12143
  meeting.stopKeepAlive = sinon.stub();
10422
12144
  meeting.updateLLMConnection = sinon.stub();
10423
12145
  let resolvePrefetch;
10424
12146
 
10425
- meeting.ensureDefaultDatachannelTokenAfterAdmit = sinon
10426
- .stub()
10427
- .returns(new Promise((resolve) => {
12147
+ meeting.ensureDefaultDatachannelTokenAfterAdmit = sinon.stub().returns(
12148
+ new Promise((resolve) => {
10428
12149
  resolvePrefetch = resolve;
10429
- }));
12150
+ })
12151
+ );
10430
12152
  meeting.rtcMetrics = {
10431
12153
  sendNextMetrics: sinon.stub(),
10432
12154
  };
@@ -10443,7 +12165,7 @@ describe('plugin-meetings', () => {
10443
12165
  'meeting:self:guestAdmitted',
10444
12166
  {payload: test1}
10445
12167
  );
10446
- assert.calledOnce(meeting.updateLLMConnection);
12168
+ assert.notCalled(meeting.updateLLMConnection);
10447
12169
  assert.calledOnceWithExactly(meeting.rtcMetrics.sendNextMetrics);
10448
12170
 
10449
12171
  assert.calledOnceWithExactly(
@@ -10456,6 +12178,7 @@ describe('plugin-meetings', () => {
10456
12178
 
10457
12179
  resolvePrefetch(false);
10458
12180
  await Promise.resolve();
12181
+ await Promise.resolve();
10459
12182
 
10460
12183
  assert.calledOnce(meeting.updateLLMConnection);
10461
12184
  });
@@ -10971,6 +12694,106 @@ describe('plugin-meetings', () => {
10971
12694
  );
10972
12695
  });
10973
12696
 
12697
+ const recordingTestCases = [
12698
+ {
12699
+ description: 'triggers MEETING_STARTED_RECORDING when state is RECORDING',
12700
+ state: RECORDING_STATE.RECORDING,
12701
+ expectedEvent: EVENT_TRIGGERS.MEETING_STARTED_RECORDING,
12702
+ expectedRecordingState: RECORDING_STATE.RECORDING,
12703
+ },
12704
+ {
12705
+ description: 'triggers MEETING_STOPPED_RECORDING when state is IDLE',
12706
+ state: RECORDING_STATE.IDLE,
12707
+ expectedEvent: EVENT_TRIGGERS.MEETING_STOPPED_RECORDING,
12708
+ expectedRecordingState: RECORDING_STATE.IDLE,
12709
+ },
12710
+ {
12711
+ description: 'triggers MEETING_PAUSED_RECORDING when state is PAUSED',
12712
+ state: RECORDING_STATE.PAUSED,
12713
+ expectedEvent: EVENT_TRIGGERS.MEETING_PAUSED_RECORDING,
12714
+ expectedRecordingState: RECORDING_STATE.PAUSED,
12715
+ },
12716
+ {
12717
+ description:
12718
+ 'triggers MEETING_RESUMED_RECORDING and sets state to RECORDING when state is RESUMED',
12719
+ state: RECORDING_STATE.RESUMED,
12720
+ expectedEvent: EVENT_TRIGGERS.MEETING_RESUMED_RECORDING,
12721
+ expectedRecordingState: RECORDING_STATE.RECORDING,
12722
+ },
12723
+ ];
12724
+
12725
+ recordingTestCases.forEach(
12726
+ ({description, state, expectedEvent, expectedRecordingState}) => {
12727
+ it(`listens to CONTROLS_RECORDING_UPDATED - ${description}`, async () => {
12728
+ const modifiedBy = 'user-id-123';
12729
+ const lastModified = '2026-01-01T00:00:00Z';
12730
+
12731
+ await meeting.locusInfo.emitScoped(
12732
+ {function: 'test', file: 'test'},
12733
+ LOCUSINFO.EVENTS.CONTROLS_RECORDING_UPDATED,
12734
+ {
12735
+ state,
12736
+ modifiedBy,
12737
+ lastModified,
12738
+ modifiedByServiceAppName: undefined,
12739
+ modifiedByServiceAppId: undefined,
12740
+ }
12741
+ );
12742
+
12743
+ assert.deepEqual(meeting.recording, {
12744
+ state: expectedRecordingState,
12745
+ modifiedBy,
12746
+ lastModified,
12747
+ modifiedByServiceAppName: undefined,
12748
+ modifiedByServiceAppId: undefined,
12749
+ });
12750
+
12751
+ assert.calledWith(
12752
+ TriggerProxy.trigger,
12753
+ meeting,
12754
+ {file: 'meeting/index', function: 'setupLocusControlsListener'},
12755
+ expectedEvent,
12756
+ meeting.recording
12757
+ );
12758
+ });
12759
+ }
12760
+ );
12761
+
12762
+ it('listens to CONTROLS_RECORDING_UPDATED and includes modifiedByServiceAppName and modifiedByServiceAppId when present', async () => {
12763
+ const modifiedBy = 'user-id-123';
12764
+ const lastModified = '2026-01-01T00:00:00Z';
12765
+ const modifiedByServiceAppName = 'My Bot';
12766
+ const modifiedByServiceAppId = 'app-id-123';
12767
+
12768
+ await meeting.locusInfo.emitScoped(
12769
+ {function: 'test', file: 'test'},
12770
+ LOCUSINFO.EVENTS.CONTROLS_RECORDING_UPDATED,
12771
+ {
12772
+ state: RECORDING_STATE.RECORDING,
12773
+ modifiedBy,
12774
+ lastModified,
12775
+ modifiedByServiceAppName,
12776
+ modifiedByServiceAppId,
12777
+ }
12778
+ );
12779
+
12780
+ assert.deepEqual(meeting.recording, {
12781
+ state: RECORDING_STATE.RECORDING,
12782
+ modifiedBy,
12783
+ lastModified,
12784
+ modifiedByServiceAppName,
12785
+ modifiedByServiceAppId,
12786
+ });
12787
+
12788
+ assert.calledWith(
12789
+ TriggerProxy.trigger,
12790
+ meeting,
12791
+ {file: 'meeting/index', function: 'setupLocusControlsListener'},
12792
+ EVENT_TRIGGERS.MEETING_STARTED_RECORDING,
12793
+ meeting.recording
12794
+ );
12795
+ });
12796
+
10974
12797
  it('listens to the locus interpretation update event', () => {
10975
12798
  const interpretation = {
10976
12799
  siLanguages: [{languageCode: 20, languageName: 'en'}],
@@ -11024,6 +12847,7 @@ describe('plugin-meetings', () => {
11024
12847
  meeting.annotation.locusUrlUpdate = sinon.stub();
11025
12848
  meeting.simultaneousInterpretation.locusUrlUpdate = sinon.stub();
11026
12849
  meeting.webinar.locusUrlUpdate = sinon.stub();
12850
+ meeting.aiEnableRequest.locusUrlUpdate = sinon.stub();
11027
12851
 
11028
12852
  meeting.locusInfo.emit(
11029
12853
  {function: 'test', file: 'test'},
@@ -11038,6 +12862,7 @@ describe('plugin-meetings', () => {
11038
12862
  assert.calledWith(meeting.controlsOptionsManager.setLocusUrl, newLocusUrl, false);
11039
12863
  assert.calledWith(meeting.simultaneousInterpretation.locusUrlUpdate, newLocusUrl);
11040
12864
  assert.calledWith(meeting.webinar.locusUrlUpdate, newLocusUrl);
12865
+ assert.calledWith(meeting.aiEnableRequest.locusUrlUpdate, newLocusUrl);
11041
12866
  assert.equal(meeting.locusUrl, newLocusUrl);
11042
12867
  assert(meeting.locusId, '12345');
11043
12868
 
@@ -11353,6 +13178,109 @@ describe('plugin-meetings', () => {
11353
13178
  });
11354
13179
  });
11355
13180
 
13181
+ describe('#finalizeMeetingAfterInitialLocusSetup', () => {
13182
+ it('refreshes destination from synced locus when destination type is LOCUS_ID', () => {
13183
+ const syncedLocus = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13184
+
13185
+ meeting.destinationType = DESTINATION_TYPE.LOCUS_ID;
13186
+ meeting.destination = {info: {topic: 'old'}};
13187
+
13188
+ meeting.finalizeMeetingAfterInitialLocusSetup(syncedLocus);
13189
+
13190
+ assert.equal(meeting.destination, syncedLocus);
13191
+ });
13192
+
13193
+ it('does not refresh destination when destination type is not LOCUS_ID', () => {
13194
+ const syncedLocus = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13195
+ const originalDestination = {destination: 'original-destination'};
13196
+
13197
+ meeting.destinationType = DESTINATION_TYPE.CONVERSATION_URL;
13198
+ meeting.destination = originalDestination;
13199
+
13200
+ meeting.finalizeMeetingAfterInitialLocusSetup(syncedLocus);
13201
+
13202
+ assert.equal(meeting.destination, originalDestination);
13203
+ });
13204
+
13205
+ it('fetches meeting info when meetingInfo is empty and destination has info', () => {
13206
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13207
+
13208
+ meeting.meetingInfo = {};
13209
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13210
+
13211
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13212
+
13213
+ assert.calledOnceWithExactly(fetchMeetingInfoStub, {});
13214
+ });
13215
+
13216
+ it('does not fetch meeting info when destination has no info', () => {
13217
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13218
+
13219
+ meeting.meetingInfo = {};
13220
+ meeting.destination = {url: 'https://locus.example.com/locus/123'};
13221
+
13222
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13223
+
13224
+ assert.notCalled(fetchMeetingInfoStub);
13225
+ });
13226
+
13227
+ it('does not fetch meeting info when meetingInfo is already populated', () => {
13228
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13229
+
13230
+ meeting.meetingInfo = {meetingJoinUrl: 'https://example.com/join/abc'};
13231
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13232
+
13233
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13234
+
13235
+ assert.notCalled(fetchMeetingInfoStub);
13236
+ });
13237
+
13238
+ it('does not fetch meeting info when delayed fetch timer is already scheduled', () => {
13239
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13240
+
13241
+ meeting.meetingInfo = {};
13242
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13243
+ meeting.fetchMeetingInfoTimeoutId = 42;
13244
+
13245
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13246
+
13247
+ assert.notCalled(fetchMeetingInfoStub);
13248
+ });
13249
+
13250
+ ['CALL', 'SIP_BRIDGE', 'SPACE_SHARE'].forEach((fullStateType) => {
13251
+ it(`does not fetch meeting info when destination is a 1:1 call (fullState.type ${fullStateType})`, () => {
13252
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13253
+
13254
+ meeting.meetingInfo = {};
13255
+ meeting.destination = {
13256
+ url: 'https://locus.example.com/locus/123',
13257
+ info: {topic: 'x'},
13258
+ };
13259
+
13260
+ meeting.finalizeMeetingAfterInitialLocusSetup({fullState: {type: fullStateType}});
13261
+
13262
+ assert.notCalled(fetchMeetingInfoStub);
13263
+ });
13264
+ });
13265
+
13266
+ it('swallows async fetchMeetingInfo errors and logs info', async () => {
13267
+ const error = new Error('fetch failed');
13268
+
13269
+ meeting.meetingInfo = {};
13270
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13271
+ sinon.stub(meeting, 'fetchMeetingInfo').returns(Promise.reject(error));
13272
+ const loggerInfoStub = sinon.stub(LoggerProxy.logger, 'info');
13273
+
13274
+ await meeting.finalizeMeetingAfterInitialLocusSetup({});
13275
+
13276
+ assert.calledOnce(loggerInfoStub);
13277
+ assert.match(
13278
+ loggerInfoStub.firstCall.args[0],
13279
+ /Meeting:index#finalizeMeetingAfterInitialLocusSetup --> deferred fetchMeetingInfo failed: fetch failed/
13280
+ );
13281
+ });
13282
+ });
13283
+
11356
13284
  describe('#emailInput', () => {
11357
13285
  it('should set the email input', () => {
11358
13286
  assert.notOk(meeting.emailInput);
@@ -11955,6 +13883,7 @@ describe('plugin-meetings', () => {
11955
13883
  let showAutoEndMeetingWarningSpy;
11956
13884
  let canAttendeeRequestAiAssistantEnabledSpy;
11957
13885
  let attendeeRequestAiAssistantDeclinedAllSpy;
13886
+ let isAnonymizeDisplayNamesEnabledSpy;
11958
13887
  // Due to import tree issues, hasHints must be stubed within the scope of the `it`.
11959
13888
 
11960
13889
  beforeEach(() => {
@@ -12003,6 +13932,10 @@ describe('plugin-meetings', () => {
12003
13932
  MeetingUtil,
12004
13933
  'attendeeRequestAiAssistantDeclinedAll'
12005
13934
  );
13935
+ isAnonymizeDisplayNamesEnabledSpy = sinon.spy(
13936
+ MeetingUtil,
13937
+ 'isAnonymizeDisplayNamesEnabled'
13938
+ );
12006
13939
  });
12007
13940
 
12008
13941
  afterEach(() => {
@@ -12011,6 +13944,7 @@ describe('plugin-meetings', () => {
12011
13944
  showAutoEndMeetingWarningSpy.restore();
12012
13945
  canAttendeeRequestAiAssistantEnabledSpy.restore();
12013
13946
  attendeeRequestAiAssistantDeclinedAllSpy.restore();
13947
+ isAnonymizeDisplayNamesEnabledSpy.restore();
12014
13948
  });
12015
13949
 
12016
13950
  forEach(
@@ -12568,6 +14502,7 @@ describe('plugin-meetings', () => {
12568
14502
  meeting.roles
12569
14503
  );
12570
14504
  assert.calledWith(attendeeRequestAiAssistantDeclinedAllSpy, userDisplayHints);
14505
+ assert.calledWith(isAnonymizeDisplayNamesEnabledSpy, userDisplayHints);
12571
14506
 
12572
14507
  assert.calledWith(ControlsOptionsUtil.hasHints, {
12573
14508
  requiredHints: [DISPLAY_HINTS.MUTE_ALL],
@@ -12782,6 +14717,10 @@ describe('plugin-meetings', () => {
12782
14717
  describe('#saveDataChannelToken', () => {
12783
14718
  beforeEach(() => {
12784
14719
  webex.internal.llm.setDatachannelToken = sinon.stub();
14720
+ webex.internal.llm.resolveSessionOwnership = sinon
14721
+ .stub()
14722
+ .returns({currentOwner: undefined, isOwner: true});
14723
+ webex.internal.llm.isConnected = sinon.stub().returns(false);
12785
14724
  });
12786
14725
 
12787
14726
  it('saves datachannelToken into LLM as Default', () => {
@@ -12794,7 +14733,8 @@ describe('plugin-meetings', () => {
12794
14733
  assert.calledWithExactly(
12795
14734
  webex.internal.llm.setDatachannelToken,
12796
14735
  'default-token',
12797
- 'llm-default-session'
14736
+ 'llm-default-session',
14737
+ meeting.id
12798
14738
  );
12799
14739
  });
12800
14740
 
@@ -12808,7 +14748,8 @@ describe('plugin-meetings', () => {
12808
14748
  assert.calledWithExactly(
12809
14749
  webex.internal.llm.setDatachannelToken,
12810
14750
  'ps-token',
12811
- 'llm-practice-session'
14751
+ 'llm-practice-session',
14752
+ meeting.id
12812
14753
  );
12813
14754
  });
12814
14755
 
@@ -12826,12 +14767,14 @@ describe('plugin-meetings', () => {
12826
14767
  assert.calledWithExactly(
12827
14768
  webex.internal.llm.setDatachannelToken,
12828
14769
  'default-token',
12829
- 'llm-default-session'
14770
+ 'llm-default-session',
14771
+ meeting.id
12830
14772
  );
12831
14773
  assert.calledWithExactly(
12832
14774
  webex.internal.llm.setDatachannelToken,
12833
14775
  'ps-token',
12834
- 'llm-practice-session'
14776
+ 'llm-practice-session',
14777
+ meeting.id
12835
14778
  );
12836
14779
  });
12837
14780
 
@@ -12852,17 +14795,42 @@ describe('plugin-meetings', () => {
12852
14795
 
12853
14796
  assert.notCalled(webex.internal.llm.setDatachannelToken);
12854
14797
  });
14798
+
14799
+ it('writes token with meeting id as owner', () => {
14800
+ meeting.saveDataChannelToken({
14801
+ locus: {
14802
+ self: {datachannelToken: 'default-token'},
14803
+ },
14804
+ });
14805
+
14806
+ assert.calledOnceWithExactly(
14807
+ webex.internal.llm.setDatachannelToken,
14808
+ 'default-token',
14809
+ 'llm-default-session',
14810
+ meeting.id
14811
+ );
14812
+ });
12855
14813
  });
12856
14814
 
12857
14815
  describe('#clearDataChannelToken', () => {
12858
14816
  beforeEach(() => {
12859
- webex.internal.llm.resetDatachannelTokens = sinon.stub();
14817
+ webex.internal.llm.clearDatachannelToken = sinon.stub();
12860
14818
  });
12861
14819
 
12862
- it('calls resetDatachannelTokens on LLM', () => {
14820
+ it('delegates default and practice token clears to llm with meeting ownership id', () => {
12863
14821
  meeting.clearDataChannelToken();
12864
14822
 
12865
- assert.calledOnce(webex.internal.llm.resetDatachannelTokens);
14823
+ assert.calledWithExactly(
14824
+ webex.internal.llm.clearDatachannelToken,
14825
+ 'llm-default-session',
14826
+ meeting.id
14827
+ );
14828
+ assert.calledWithExactly(
14829
+ webex.internal.llm.clearDatachannelToken,
14830
+ 'llm-practice-session',
14831
+ meeting.id
14832
+ );
14833
+ assert.callCount(webex.internal.llm.clearDatachannelToken, 2);
12866
14834
  });
12867
14835
  });
12868
14836
 
@@ -12872,6 +14840,7 @@ describe('plugin-meetings', () => {
12872
14840
  webex.internal.llm.getLocusUrl = sinon.stub();
12873
14841
  webex.internal.llm.getDatachannelUrl = sinon.stub();
12874
14842
  webex.internal.llm.registerAndConnect = sinon.stub().resolves('something');
14843
+ webex.internal.llm.setRefreshHandler = sinon.stub();
12875
14844
  webex.internal.llm.disconnectLLM = sinon.stub().resolves();
12876
14845
  webex.internal.llm.on = sinon.stub();
12877
14846
  webex.internal.llm.off = sinon.stub();
@@ -12889,7 +14858,11 @@ describe('plugin-meetings', () => {
12889
14858
  meeting.joinedWith = {state: 'any other state'};
12890
14859
  webex.internal.llm.getLocusUrl.returns('a url');
12891
14860
 
12892
- meeting.locusInfo = {url: 'a url', info: {datachannelUrl: 'a datachannel url'}};
14861
+ meeting.locusInfo = {
14862
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
14863
+ url: 'a url',
14864
+ info: {datachannelUrl: 'a datachannel url'},
14865
+ };
12893
14866
 
12894
14867
  const result = await meeting.updateLLMConnection();
12895
14868
 
@@ -12901,6 +14874,7 @@ describe('plugin-meetings', () => {
12901
14874
  it('returns undefined if llm is already connected and the locus url is unchanged', async () => {
12902
14875
  meeting.joinedWith = {state: 'JOINED'};
12903
14876
  meeting.locusInfo = {
14877
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
12904
14878
  url: 'a url',
12905
14879
  info: {datachannelUrl: 'a datachannel url'},
12906
14880
  };
@@ -12937,7 +14911,11 @@ describe('plugin-meetings', () => {
12937
14911
  });
12938
14912
  it('connects if not already connected', async () => {
12939
14913
  meeting.joinedWith = {state: 'JOINED'};
12940
- meeting.locusInfo = {url: 'a url', info: {datachannelUrl: 'a datachannel url'}};
14914
+ meeting.locusInfo = {
14915
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
14916
+ url: 'a url',
14917
+ info: {datachannelUrl: 'a datachannel url'},
14918
+ };
12941
14919
 
12942
14920
  const result = await meeting.updateLLMConnection();
12943
14921
 
@@ -12948,7 +14926,14 @@ describe('plugin-meetings', () => {
12948
14926
  'a datachannel url',
12949
14927
  undefined
12950
14928
  );
14929
+ assert.calledOnceWithExactly(
14930
+ webex.internal.llm.setRefreshHandler,
14931
+ sinon.match.func,
14932
+ 'llm-default-session',
14933
+ meeting.id
14934
+ );
12951
14935
  assert.equal(result, 'something');
14936
+ assert.calledOnceWithExactly(meeting.locusInfo.syncAllHashTreeDatasets, {onlyLLM: true});
12952
14937
  });
12953
14938
  it('disconnects if the locus url has changed', async () => {
12954
14939
  meeting.joinedWith = {state: 'JOINED'};
@@ -12957,6 +14942,7 @@ describe('plugin-meetings', () => {
12957
14942
  webex.internal.llm.getLocusUrl.returns('a url');
12958
14943
 
12959
14944
  meeting.locusInfo = {
14945
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
12960
14946
  url: 'a different url',
12961
14947
  info: {datachannelUrl: 'a datachannel url'},
12962
14948
  self: {},
@@ -12964,10 +14950,15 @@ describe('plugin-meetings', () => {
12964
14950
 
12965
14951
  const result = await meeting.updateLLMConnection();
12966
14952
 
12967
- assert.calledWithExactly(webex.internal.llm.disconnectLLM, {
12968
- code: 3050,
12969
- reason: 'done (permanent)',
12970
- });
14953
+ assert.calledWithExactly(
14954
+ webex.internal.llm.disconnectLLM,
14955
+ {
14956
+ code: 3050,
14957
+ reason: 'done (permanent)',
14958
+ },
14959
+ 'llm-default-session',
14960
+ meeting.id
14961
+ );
12971
14962
 
12972
14963
  assert.calledWithExactly(
12973
14964
  webex.internal.llm.registerAndConnect,
@@ -13010,6 +15001,7 @@ describe('plugin-meetings', () => {
13010
15001
  webex.internal.llm.getLocusUrl.returns('a url');
13011
15002
 
13012
15003
  meeting.locusInfo = {
15004
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13013
15005
  url: 'a url',
13014
15006
  info: {datachannelUrl: 'a different datachannel url'},
13015
15007
  self: {},
@@ -13017,10 +15009,15 @@ describe('plugin-meetings', () => {
13017
15009
 
13018
15010
  const result = await meeting.updateLLMConnection();
13019
15011
 
13020
- assert.calledWithExactly(webex.internal.llm.disconnectLLM, {
13021
- code: 3050,
13022
- reason: 'done (permanent)',
13023
- });
15012
+ assert.calledWithExactly(
15013
+ webex.internal.llm.disconnectLLM,
15014
+ {
15015
+ code: 3050,
15016
+ reason: 'done (permanent)',
15017
+ },
15018
+ 'llm-default-session',
15019
+ meeting.id
15020
+ );
13024
15021
 
13025
15022
  assert.calledWithExactly(
13026
15023
  webex.internal.llm.registerAndConnect,
@@ -13061,14 +15058,23 @@ describe('plugin-meetings', () => {
13061
15058
  webex.internal.llm.isConnected.returns(true);
13062
15059
  webex.internal.llm.getLocusUrl.returns('a url');
13063
15060
 
13064
- meeting.locusInfo = {url: 'a url', info: {datachannelUrl: 'a datachannel url'}};
15061
+ meeting.locusInfo = {
15062
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15063
+ url: 'a url',
15064
+ info: {datachannelUrl: 'a datachannel url'},
15065
+ };
13065
15066
 
13066
15067
  const result = await meeting.updateLLMConnection();
13067
15068
 
13068
- assert.calledWith(webex.internal.llm.disconnectLLM, {
13069
- code: 3050,
13070
- reason: 'done (permanent)',
13071
- });
15069
+ assert.calledWith(
15070
+ webex.internal.llm.disconnectLLM,
15071
+ {
15072
+ code: 3050,
15073
+ reason: 'done (permanent)',
15074
+ },
15075
+ 'llm-default-session',
15076
+ meeting.id
15077
+ );
13072
15078
  assert.notCalled(webex.internal.llm.registerAndConnect);
13073
15079
  assert.equal(result, undefined);
13074
15080
  assert.isFalse(
@@ -13084,6 +15090,7 @@ describe('plugin-meetings', () => {
13084
15090
  webex.internal.llm.disconnectLLM.rejects(disconnectError);
13085
15091
 
13086
15092
  meeting.locusInfo = {
15093
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13087
15094
  url: 'a different url',
13088
15095
  info: {datachannelUrl: 'a datachannel url'},
13089
15096
  self: {},
@@ -13115,6 +15122,7 @@ describe('plugin-meetings', () => {
13115
15122
  it('still need connect main session data channel when PS started', async () => {
13116
15123
  meeting.joinedWith = {state: 'JOINED'};
13117
15124
  meeting.locusInfo = {
15125
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13118
15126
  url: 'a url',
13119
15127
  info: {
13120
15128
  datachannelUrl: 'a datachannel url',
@@ -13135,11 +15143,14 @@ describe('plugin-meetings', () => {
13135
15143
  it('passes dataChannelToken from LLM to registerAndConnect', async () => {
13136
15144
  meeting.joinedWith = {state: 'JOINED'};
13137
15145
  meeting.locusInfo = {
15146
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13138
15147
  url: 'a url',
13139
15148
  info: {datachannelUrl: 'a datachannel url'},
13140
15149
  };
13141
15150
 
13142
- webex.internal.llm.getDatachannelToken.withArgs('llm-default-session').returns('token-123');
15151
+ webex.internal.llm.getDatachannelToken
15152
+ .withArgs('llm-default-session', meeting.id)
15153
+ .returns('token-123');
13143
15154
 
13144
15155
  await meeting.updateLLMConnection();
13145
15156
 
@@ -13154,6 +15165,7 @@ describe('plugin-meetings', () => {
13154
15165
  it('passes undefined token when LLM has no token stored', async () => {
13155
15166
  meeting.joinedWith = {state: 'JOINED'};
13156
15167
  meeting.locusInfo = {
15168
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13157
15169
  url: 'a url',
13158
15170
  info: {datachannelUrl: 'a datachannel url'},
13159
15171
  };
@@ -13175,6 +15187,7 @@ describe('plugin-meetings', () => {
13175
15187
  it('does not pass token when data channel with jwt token is disabled', async () => {
13176
15188
  meeting.joinedWith = {state: 'JOINED'};
13177
15189
  meeting.locusInfo = {
15190
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13178
15191
  url: 'a url',
13179
15192
  info: {datachannelUrl: 'a datachannel url'},
13180
15193
  };
@@ -13193,6 +15206,209 @@ describe('plugin-meetings', () => {
13193
15206
  assert.notCalled(webex.internal.llm.setDatachannelToken);
13194
15207
  });
13195
15208
 
15209
+ describe('ownership tag', () => {
15210
+ beforeEach(() => {
15211
+ // Make the owner stub dynamic so setOwnerMeetingId() writes
15212
+ // propagate back to getOwnerMeetingId() reads. This mirrors the
15213
+ // real LLM singleton behavior so the finally-block release in
15214
+ // cleanupLLMConneciton is reflected in subsequent reads.
15215
+ webex.internal.llm.getOwnerMeetingId = sinon.stub().returns(undefined);
15216
+ webex.internal.llm.setOwnerMeetingId = sinon.stub().callsFake((id) => {
15217
+ webex.internal.llm.getOwnerMeetingId.returns(id);
15218
+ });
15219
+ });
15220
+
15221
+ it('skips disconnect and reconnect when LLM is connected and owned by another meeting (regardless of URL)', async () => {
15222
+ meeting.joinedWith = {state: 'JOINED'};
15223
+ webex.internal.llm.isConnected.returns(true);
15224
+ webex.internal.llm.getOwnerMeetingId.returns('some-other-meeting-id');
15225
+ // Locus/datachannel URL mismatch is the *normal* case when
15226
+ // another meeting owns the live socket -- each meeting has its
15227
+ // own locus URL. URL mismatch must NOT trigger a reclaim,
15228
+ // because doing so would tear down the owning meeting's healthy
15229
+ // LLM socket and break its data channel.
15230
+ webex.internal.llm.getLocusUrl.returns('owner-locus-url');
15231
+ webex.internal.llm.getDatachannelUrl.returns('owner-dc-url');
15232
+ meeting.locusInfo = {
15233
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15234
+ url: 'a different url',
15235
+ info: {datachannelUrl: 'a different datachannel url'},
15236
+ self: {},
15237
+ };
15238
+
15239
+ const result = await meeting.updateLLMConnection();
15240
+
15241
+ assert.equal(result, undefined);
15242
+ assert.notCalled(webex.internal.llm.disconnectLLM);
15243
+ assert.notCalled(webex.internal.llm.registerAndConnect);
15244
+ assert.notCalled(webex.internal.llm.setOwnerMeetingId);
15245
+ assert.notCalled(meeting.startLLMHealthCheckTimer);
15246
+ });
15247
+
15248
+ it('clears stale owner tag in cleanup finally block even when disconnectLLM rejects', async () => {
15249
+ meeting.joinedWith = {state: 'JOINED'};
15250
+ webex.internal.llm.isConnected.returns(true);
15251
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15252
+ webex.internal.llm.getLocusUrl.returns('a url');
15253
+ webex.internal.llm.getDatachannelUrl.returns('a datachannel url');
15254
+ webex.internal.llm.disconnectLLM.rejects(new Error('disconnect failed'));
15255
+ meeting.locusInfo = {
15256
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15257
+ url: 'a different url',
15258
+ info: {datachannelUrl: 'a datachannel url'},
15259
+ self: {},
15260
+ };
15261
+
15262
+ try {
15263
+ await meeting.updateLLMConnection();
15264
+ } catch (e) {
15265
+ /* updateLLMConnection may reject when cleanup throws */
15266
+ }
15267
+
15268
+ // The owner-eligible finally branch must release the tag so a
15269
+ // subsequent reconnect attempt from any meeting is not blocked.
15270
+ assert.calledWith(webex.internal.llm.setOwnerMeetingId, undefined);
15271
+ });
15272
+
15273
+ it('does not clear owner tag when ownership changes during cleanup disconnect await', async () => {
15274
+ meeting.joinedWith = {state: 'JOINED'};
15275
+ webex.internal.llm.isConnected.returns(true);
15276
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15277
+ webex.internal.llm.getLocusUrl.returns('a url');
15278
+ webex.internal.llm.getDatachannelUrl.returns('a datachannel url');
15279
+ webex.internal.llm.disconnectLLM.callsFake(async () => {
15280
+ webex.internal.llm.getOwnerMeetingId.returns('new-owner-id');
15281
+ throw new Error('disconnect failed');
15282
+ });
15283
+ meeting.locusInfo = {
15284
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15285
+ url: 'a different url',
15286
+ info: {datachannelUrl: 'a datachannel url'},
15287
+ self: {},
15288
+ };
15289
+
15290
+ try {
15291
+ await meeting.updateLLMConnection();
15292
+ } catch (e) {
15293
+ /* updateLLMConnection may reject when cleanup throws */
15294
+ }
15295
+
15296
+ assert.notCalled(webex.internal.llm.setOwnerMeetingId);
15297
+ assert.equal(webex.internal.llm.getOwnerMeetingId(), 'new-owner-id');
15298
+ });
15299
+
15300
+ it('proceeds normally when LLM is connected and owned by this meeting with URL change', async () => {
15301
+ meeting.joinedWith = {state: 'JOINED'};
15302
+ webex.internal.llm.isConnected.returns(true);
15303
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15304
+ webex.internal.llm.getLocusUrl.returns('a url');
15305
+ webex.internal.llm.getDatachannelUrl.returns('a datachannel url');
15306
+ meeting.locusInfo = {
15307
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15308
+ url: 'a different url',
15309
+ info: {datachannelUrl: 'a datachannel url'},
15310
+ self: {},
15311
+ };
15312
+
15313
+ await meeting.updateLLMConnection();
15314
+
15315
+ assert.calledOnceWithExactly(
15316
+ webex.internal.llm.disconnectLLM,
15317
+ {
15318
+ code: 3050,
15319
+ reason: 'done (permanent)',
15320
+ },
15321
+ 'llm-default-session',
15322
+ meeting.id
15323
+ );
15324
+ assert.calledWithExactly(
15325
+ webex.internal.llm.registerAndConnect,
15326
+ 'a different url',
15327
+ 'a datachannel url',
15328
+ undefined
15329
+ );
15330
+ // setOwnerMeetingId is called twice: first with undefined in
15331
+ // cleanupLLMConneciton's finally block (so a failed disconnect
15332
+ // cannot leave a stale owner), then with this meeting's id
15333
+ // after registerAndConnect resolves.
15334
+ assert.calledTwice(webex.internal.llm.setOwnerMeetingId);
15335
+ assert.calledWith(webex.internal.llm.setOwnerMeetingId.firstCall, undefined);
15336
+ assert.calledWith(webex.internal.llm.setOwnerMeetingId.lastCall, meeting.id);
15337
+ });
15338
+
15339
+ it('claims ownership after successful registerAndConnect on initial connect', async () => {
15340
+ meeting.joinedWith = {state: 'JOINED'};
15341
+ webex.internal.llm.isConnected.returns(false);
15342
+ webex.internal.llm.getOwnerMeetingId.returns(undefined);
15343
+ meeting.locusInfo = {
15344
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15345
+ url: 'a url',
15346
+ info: {datachannelUrl: 'a datachannel url'},
15347
+ };
15348
+
15349
+ await meeting.updateLLMConnection();
15350
+
15351
+ assert.calledOnce(webex.internal.llm.registerAndConnect);
15352
+ assert.calledOnceWithExactly(
15353
+ webex.internal.llm.setRefreshHandler,
15354
+ sinon.match.func,
15355
+ 'llm-default-session',
15356
+ meeting.id
15357
+ );
15358
+ assert.calledOnceWithExactly(webex.internal.llm.setOwnerMeetingId, meeting.id);
15359
+ });
15360
+
15361
+ it('proceeds to connect when LLM is not connected even if another ownerId lingers', async () => {
15362
+ // Defensive path: if the LLM reports not-connected but an old
15363
+ // ownerId is still present (e.g. race before a successful
15364
+ // connections.delete), this meeting can still claim a fresh
15365
+ // connection.
15366
+ meeting.joinedWith = {state: 'JOINED'};
15367
+ webex.internal.llm.isConnected.returns(false);
15368
+ webex.internal.llm.getOwnerMeetingId.returns('stale-owner-id');
15369
+ webex.internal.llm.getDatachannelToken.onFirstCall().returns(undefined);
15370
+ webex.internal.llm.getDatachannelToken.onSecondCall().returns('recovered-token');
15371
+ meeting.locusInfo = {
15372
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15373
+ url: 'a url',
15374
+ info: {datachannelUrl: 'a datachannel url'},
15375
+ };
15376
+
15377
+ await meeting.updateLLMConnection();
15378
+
15379
+ assert.calledTwice(webex.internal.llm.getDatachannelToken);
15380
+ assert.calledWithExactly(
15381
+ webex.internal.llm.getDatachannelToken.firstCall,
15382
+ 'llm-default-session',
15383
+ meeting.id
15384
+ );
15385
+ assert.calledWithExactly(
15386
+ webex.internal.llm.getDatachannelToken.secondCall,
15387
+ 'llm-default-session'
15388
+ );
15389
+ assert.calledOnceWithExactly(
15390
+ webex.internal.llm.registerAndConnect,
15391
+ 'a url',
15392
+ 'a datachannel url',
15393
+ 'recovered-token'
15394
+ );
15395
+ assert.calledWithExactly(
15396
+ webex.internal.llm.setRefreshHandler.firstCall,
15397
+ sinon.match.func,
15398
+ 'llm-default-session',
15399
+ undefined
15400
+ );
15401
+ assert.calledTwice(webex.internal.llm.setRefreshHandler);
15402
+ assert.calledWithExactly(
15403
+ webex.internal.llm.setRefreshHandler.secondCall,
15404
+ sinon.match.func,
15405
+ 'llm-default-session',
15406
+ meeting.id
15407
+ );
15408
+ assert.calledOnceWithExactly(webex.internal.llm.setOwnerMeetingId, meeting.id);
15409
+ });
15410
+ });
15411
+
13196
15412
  describe('#clearMeetingData', () => {
13197
15413
  beforeEach(() => {
13198
15414
  webex.internal.llm.isConnected = sinon.stub().returns(true);
@@ -13208,10 +15424,15 @@ describe('plugin-meetings', () => {
13208
15424
  it('disconnects llm and removes online and relay listeners during meeting data cleanup', async () => {
13209
15425
  await meeting.clearMeetingData();
13210
15426
 
13211
- assert.calledOnceWithExactly(webex.internal.llm.disconnectLLM, {
13212
- code: 3050,
13213
- reason: 'done (permanent)',
13214
- });
15427
+ assert.calledOnceWithExactly(
15428
+ webex.internal.llm.disconnectLLM,
15429
+ {
15430
+ code: 3050,
15431
+ reason: 'done (permanent)',
15432
+ },
15433
+ 'llm-default-session',
15434
+ meeting.id
15435
+ );
13215
15436
  assert.calledWithExactly(webex.internal.llm.off, 'online', meeting.handleLLMOnline);
13216
15437
  assert.calledWithExactly(
13217
15438
  webex.internal.llm.off,
@@ -13224,10 +15445,13 @@ describe('plugin-meetings', () => {
13224
15445
  meeting.processLocusLLMEvent
13225
15446
  );
13226
15447
  assert.calledOnce(meeting.clearLLMHealthCheckTimer);
13227
- assert.calledOnce(meeting.stopTranscription);
13228
- assert.isUndefined(meeting.transcription);
13229
15448
  assert.calledOnce(meeting.clearDataChannelToken);
13230
- assert.calledOnce(meeting.annotation.deregisterEvents);
15449
+ // stopTranscription and annotation.deregisterEvents are not
15450
+ // called here: they run in stopListeningForMeetingEvents()
15451
+ // before /leave to avoid double-emitting
15452
+ // MEETING_STOPPED_RECEIVING_TRANSCRIPTION.
15453
+ assert.notCalled(meeting.stopTranscription);
15454
+ assert.notCalled(meeting.annotation.deregisterEvents);
13231
15455
  });
13232
15456
  it('continues cleanup when disconnectLLM fails during meeting data cleanup', async () => {
13233
15457
  webex.internal.llm.disconnectLLM.rejects(new Error('disconnect failed'));
@@ -13246,19 +15470,249 @@ describe('plugin-meetings', () => {
13246
15470
  meeting.processLocusLLMEvent
13247
15471
  );
13248
15472
  assert.calledOnce(meeting.clearLLMHealthCheckTimer);
13249
- assert.calledOnce(meeting.stopTranscription);
13250
- assert.isUndefined(meeting.transcription);
13251
15473
  assert.calledOnce(meeting.clearDataChannelToken);
13252
- assert.calledOnce(meeting.annotation.deregisterEvents);
15474
+ assert.notCalled(meeting.stopTranscription);
15475
+ assert.notCalled(meeting.annotation.deregisterEvents);
13253
15476
  });
13254
- it('always calls stopTranscription even when transcription is undefined', async () => {
13255
- meeting.transcription = undefined;
13256
15477
 
13257
- await meeting.clearMeetingData();
15478
+ describe('ownership tag', () => {
15479
+ beforeEach(() => {
15480
+ webex.internal.llm.getOwnerMeetingId = sinon.stub();
15481
+ });
13258
15482
 
13259
- assert.calledOnce(meeting.stopTranscription);
13260
- assert.isUndefined(meeting.transcription);
13261
- assert.calledOnce(meeting.clearDataChannelToken);
15483
+ it('skips disconnectLLM but still removes this meeting listeners when another meeting owns the LLM', async () => {
15484
+ webex.internal.llm.getOwnerMeetingId.returns('some-other-meeting-id');
15485
+
15486
+ await meeting.clearMeetingData();
15487
+
15488
+ assert.notCalled(webex.internal.llm.disconnectLLM);
15489
+ // clearDataChannelToken is always delegated; llm enforces
15490
+ // ownership and no-ops for non-owners internally.
15491
+ assert.calledOnce(meeting.clearDataChannelToken);
15492
+ // Listeners owned by *this* Meeting instance must still be
15493
+ // removed so a leaving subordinate meeting stops receiving
15494
+ // relay/locus events from the shared singleton.
15495
+ assert.calledWithExactly(webex.internal.llm.off, 'online', meeting.handleLLMOnline);
15496
+ assert.calledWithExactly(
15497
+ webex.internal.llm.off,
15498
+ 'event:relay.event',
15499
+ meeting.processRelayEvent
15500
+ );
15501
+ assert.calledWithExactly(
15502
+ webex.internal.llm.off,
15503
+ 'event:locus.state_message',
15504
+ meeting.processLocusLLMEvent
15505
+ );
15506
+ assert.calledOnce(meeting.clearLLMHealthCheckTimer);
15507
+ });
15508
+
15509
+ it('calls disconnectLLM and clears data channel token when this meeting is the owner', async () => {
15510
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15511
+
15512
+ await meeting.clearMeetingData();
15513
+
15514
+ assert.calledOnceWithExactly(
15515
+ webex.internal.llm.disconnectLLM,
15516
+ {
15517
+ code: 3050,
15518
+ reason: 'done (permanent)',
15519
+ },
15520
+ 'llm-default-session',
15521
+ meeting.id
15522
+ );
15523
+ assert.calledOnce(meeting.clearDataChannelToken);
15524
+ });
15525
+
15526
+ it('calls disconnectLLM and clears data channel token when no owner is recorded (first-claim / legacy)', async () => {
15527
+ webex.internal.llm.getOwnerMeetingId.returns(undefined);
15528
+
15529
+ await meeting.clearMeetingData();
15530
+
15531
+ assert.calledOnceWithExactly(
15532
+ webex.internal.llm.disconnectLLM,
15533
+ {
15534
+ code: 3050,
15535
+ reason: 'done (permanent)',
15536
+ },
15537
+ 'llm-default-session',
15538
+ meeting.id
15539
+ );
15540
+ assert.calledOnce(meeting.clearDataChannelToken);
15541
+ });
15542
+ });
15543
+ });
15544
+ });
15545
+
15546
+ describe('#processLocusLLMEvent', () => {
15547
+ it('routes the LLM event through locusInfo.parse and records the LLM message with the top-level tracking id', () => {
15548
+ const event = {
15549
+ data: {
15550
+ eventType: 'locus.state_message',
15551
+ dataSets: [],
15552
+ },
15553
+ trackingId: 'envelope-tracking-id',
15554
+ };
15555
+
15556
+ meeting.locusInfo.parse = sinon.stub();
15557
+ meeting.onLocusSyncLlmMessage = sinon.stub();
15558
+
15559
+ meeting.processLocusLLMEvent(event);
15560
+
15561
+ // The LLM message is parsed without the tracking id - completion is driven from the
15562
+ // meeting's LLM handler, not threaded through locusInfo.
15563
+ assert.calledOnceWithExactly(meeting.locusInfo.parse, meeting, event.data);
15564
+ // Only the client whose /sync request tracking id matches the tracking id echoed back on
15565
+ // the top-level LLM event envelope records the LLM arrival; onLocusSyncLlmMessage is a
15566
+ // no-op otherwise.
15567
+ assert.calledOnceWithExactly(
15568
+ meeting.onLocusSyncLlmMessage,
15569
+ meeting.id,
15570
+ event.trackingId
15571
+ );
15572
+ });
15573
+
15574
+ it('does not attempt sync completion when the tracking id is missing', () => {
15575
+ const event = {
15576
+ data: {
15577
+ eventType: 'locus.state_message',
15578
+ dataSets: [],
15579
+ },
15580
+ };
15581
+
15582
+ meeting.locusInfo.parse = sinon.stub();
15583
+ meeting.onLocusSyncLlmMessage = sinon.stub();
15584
+
15585
+ meeting.processLocusLLMEvent(event);
15586
+
15587
+ assert.calledOnceWithExactly(meeting.locusInfo.parse, meeting, event.data);
15588
+ assert.notCalled(meeting.onLocusSyncLlmMessage);
15589
+ });
15590
+
15591
+ });
15592
+
15593
+ describe('#onLocusSyncLlmMessage', () => {
15594
+ it('records the LLM arrival time and then tries to complete the metric', () => {
15595
+ webex.internal.newMetrics.callDiagnosticLatencies.recordLocusSyncMessageReceived =
15596
+ sinon.stub();
15597
+ meeting.tryCompleteLocusSyncLatency = sinon.stub();
15598
+
15599
+ meeting.onLocusSyncLlmMessage('meeting-1', 'sync-tracking-id');
15600
+
15601
+ assert.calledOnceWithExactly(
15602
+ webex.internal.newMetrics.callDiagnosticLatencies.recordLocusSyncMessageReceived,
15603
+ 'meeting-1',
15604
+ 'sync-tracking-id'
15605
+ );
15606
+ assert.calledOnceWithExactly(
15607
+ meeting.tryCompleteLocusSyncLatency,
15608
+ 'meeting-1',
15609
+ 'sync-tracking-id'
15610
+ );
15611
+ // the arrival time must be recorded before completion is attempted
15612
+ assert.callOrder(
15613
+ webex.internal.newMetrics.callDiagnosticLatencies.recordLocusSyncMessageReceived,
15614
+ meeting.tryCompleteLocusSyncLatency
15615
+ );
15616
+ });
15617
+ });
15618
+
15619
+ describe('#tryCompleteLocusSyncLatency', () => {
15620
+ beforeEach(() => {
15621
+ meeting.emitLocusSyncCompleteMetric = sinon.stub();
15622
+ });
15623
+
15624
+ it('emits the metric when both milestones are in (completion succeeds)', () => {
15625
+ const completed = {dataSet: 'main', syncLatency: {totalTime: 50}};
15626
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency = sinon
15627
+ .stub()
15628
+ .returns(completed);
15629
+
15630
+ meeting.tryCompleteLocusSyncLatency('meeting-1', 'sync-tracking-id');
15631
+
15632
+ assert.calledOnceWithExactly(
15633
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency,
15634
+ 'meeting-1',
15635
+ 'sync-tracking-id'
15636
+ );
15637
+ assert.calledOnceWithExactly(
15638
+ meeting.emitLocusSyncCompleteMetric,
15639
+ 'meeting-1',
15640
+ completed
15641
+ );
15642
+ });
15643
+
15644
+ it('does not emit when completion returns undefined (only one milestone is in)', () => {
15645
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency = sinon
15646
+ .stub()
15647
+ .returns(undefined);
15648
+
15649
+ meeting.tryCompleteLocusSyncLatency('meeting-1', 'sync-tracking-id');
15650
+
15651
+ assert.calledOnceWithExactly(
15652
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency,
15653
+ 'meeting-1',
15654
+ 'sync-tracking-id'
15655
+ );
15656
+ assert.notCalled(meeting.emitLocusSyncCompleteMetric);
15657
+ });
15658
+ });
15659
+
15660
+ describe('#emitLocusSyncCompleteMetric', () => {
15661
+ it('submits client.locus.sync.complete with the llm websocket url and sync latency', () => {
15662
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
15663
+ webex.internal.llm.getWebSocketUrl = sinon.stub().returns('wss://llm-websocket-url');
15664
+
15665
+ meeting.emitLocusSyncCompleteMetric(
15666
+ 'meeting-1',
15667
+ {
15668
+ dataSet: 'main',
15669
+ syncLatency: {totalTime: 50},
15670
+ }
15671
+ );
15672
+
15673
+ assert.calledOnceWithExactly(webex.internal.newMetrics.submitClientEvent, {
15674
+ name: 'client.locus.sync.complete',
15675
+ payload: {
15676
+ identifiers: {
15677
+ llmWebsocketUrl: 'wss://llm-websocket-url',
15678
+ },
15679
+ llmInfo: {
15680
+ dataSet: 'main',
15681
+ },
15682
+ syncLatency: {totalTime: 50},
15683
+ },
15684
+ options: {
15685
+ meetingId: 'meeting-1',
15686
+ },
15687
+ });
15688
+ });
15689
+
15690
+ it('submits with an undefined llm websocket url when it is unavailable', () => {
15691
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
15692
+ webex.internal.llm.getWebSocketUrl = sinon.stub().returns(undefined);
15693
+
15694
+ meeting.emitLocusSyncCompleteMetric(
15695
+ 'meeting-1',
15696
+ {
15697
+ dataSet: 'main',
15698
+ syncLatency: {totalTime: 50},
15699
+ }
15700
+ );
15701
+
15702
+ assert.calledOnceWithExactly(webex.internal.newMetrics.submitClientEvent, {
15703
+ name: 'client.locus.sync.complete',
15704
+ payload: {
15705
+ identifiers: {
15706
+ llmWebsocketUrl: undefined,
15707
+ },
15708
+ llmInfo: {
15709
+ dataSet: 'main',
15710
+ },
15711
+ syncLatency: {totalTime: 50},
15712
+ },
15713
+ options: {
15714
+ meetingId: 'meeting-1',
15715
+ },
13262
15716
  });
13263
15717
  });
13264
15718
  });
@@ -13298,6 +15752,71 @@ describe('plugin-meetings', () => {
13298
15752
  });
13299
15753
  });
13300
15754
 
15755
+ describe('#waitForSelfUrlChange', () => {
15756
+ let waitForSelfUrlChange;
15757
+ let locusMediaRequestStub;
15758
+
15759
+ beforeEach(async () => {
15760
+ locusMediaRequestStub = sinon
15761
+ .stub(LocusMediaRequestModule, 'LocusMediaRequest')
15762
+ .returns({id: 'fake LocusMediaRequest instance'});
15763
+
15764
+ meeting.setLocus = sinon.stub().returns(true);
15765
+ webex.meetings.registered = true;
15766
+ sandbox.stub(MeetingUtil, 'joinMeeting').returns(Promise.resolve('JOIN_RESULT'));
15767
+ sinon.stub(meeting, 'updateLLMConnection').returns(Promise.resolve());
15768
+
15769
+ await meeting.join();
15770
+
15771
+ waitForSelfUrlChange = locusMediaRequestStub.firstCall.args[0].waitForSelfUrlChange;
15772
+ });
15773
+
15774
+ it('should resolve immediately when joinWithMediaRetryInfo.retryCount > 0', async () => {
15775
+ meeting.joinWithMediaRetryInfo = {retryCount: 1, prevJoinResponse: undefined};
15776
+
15777
+ const result = waitForSelfUrlChange();
15778
+
15779
+ assert.instanceOf(result, Promise);
15780
+ await result;
15781
+ });
15782
+
15783
+ it('should not resolve before the timeout when retryCount is 0', async () => {
15784
+ meeting.joinWithMediaRetryInfo = {retryCount: 0, prevJoinResponse: undefined};
15785
+
15786
+ let resolved = false;
15787
+ waitForSelfUrlChange().then(() => {
15788
+ resolved = true;
15789
+ });
15790
+
15791
+ await testUtils.flushPromises();
15792
+ assert.isFalse(resolved);
15793
+ });
15794
+
15795
+ it('should resolve after the 5s timeout when retryCount is 0', async () => {
15796
+ meeting.joinWithMediaRetryInfo = {retryCount: 0, prevJoinResponse: undefined};
15797
+
15798
+ let resolved = false;
15799
+ const promise = waitForSelfUrlChange();
15800
+ promise.then(() => {
15801
+ resolved = true;
15802
+ });
15803
+
15804
+ fakeClock.tick(5000);
15805
+ await promise;
15806
+
15807
+ assert.isTrue(resolved);
15808
+ });
15809
+
15810
+ it('should return the same promise when called multiple times', () => {
15811
+ meeting.joinWithMediaRetryInfo = {retryCount: 0, prevJoinResponse: undefined};
15812
+
15813
+ const firstPromise = waitForSelfUrlChange();
15814
+ const secondPromise = waitForSelfUrlChange();
15815
+
15816
+ assert.equal(firstPromise, secondPromise);
15817
+ });
15818
+ });
15819
+
13301
15820
  describe('preferred video device', () => {
13302
15821
  describe('#getVideoDeviceId', () => {
13303
15822
  it('returns the preferred video device', () => {
@@ -15012,16 +17531,25 @@ describe('plugin-meetings', () => {
15012
17531
  assert.notCalled(meeting.meetingRequest.sendReaction);
15013
17532
  });
15014
17533
 
15015
- it('should fail sending a reaction if reactionType is invalid ', async () => {
17534
+ it('should send a custom reaction type not in the known list', async () => {
15016
17535
  meeting.locusInfo.controls = {reactions: {reactionChannelUrl: 'Fake URL'}};
15017
17536
 
15018
- await assert.isRejected(
15019
- meeting.sendReaction('invalid_reaction', 'light'),
15020
- Error,
15021
- 'invalid_reaction is not a valid reaction.'
15022
- );
17537
+ const reactionPromise = meeting.sendReaction('custom_reaction', 'light');
15023
17538
 
15024
- assert.notCalled(meeting.meetingRequest.sendReaction);
17539
+ assert.exists(reactionPromise.then);
17540
+ await reactionPromise;
17541
+ assert.calledOnceWithExactly(meeting.meetingRequest.sendReaction, {
17542
+ reactionChannelUrl: 'Fake URL',
17543
+ reaction: {
17544
+ type: 'custom_reaction',
17545
+ tone: {
17546
+ type: 'light_skin_tone',
17547
+ codepoints: '1F3FB',
17548
+ shortcodes: ':skin-tone-2:',
17549
+ },
17550
+ },
17551
+ participantId: meeting.members.selfId,
17552
+ });
15025
17553
  });
15026
17554
 
15027
17555
  it('should send a reaction with default skin tone if provided skinToneType is invalid ', async () => {