@webex/plugin-meetings 3.12.0-next.12 → 3.12.0-next.121

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 (227) 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/index.js +46 -10
  17. package/dist/controls-options-manager/index.js.map +1 -1
  18. package/dist/hashTree/constants.js +4 -1
  19. package/dist/hashTree/constants.js.map +1 -1
  20. package/dist/hashTree/hashTreeParser.js +1045 -393
  21. package/dist/hashTree/hashTreeParser.js.map +1 -1
  22. package/dist/hashTree/utils.js +20 -0
  23. package/dist/hashTree/utils.js.map +1 -1
  24. package/dist/index.js +7 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/interceptors/dataChannelAuthToken.js +75 -15
  27. package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
  28. package/dist/interceptors/locusRetry.js +23 -8
  29. package/dist/interceptors/locusRetry.js.map +1 -1
  30. package/dist/interpretation/index.js +10 -1
  31. package/dist/interpretation/index.js.map +1 -1
  32. package/dist/interpretation/interpretation.types.js +7 -0
  33. package/dist/interpretation/interpretation.types.js.map +1 -0
  34. package/dist/interpretation/siLanguage.js +1 -1
  35. package/dist/locus-info/controlsUtils.js +4 -1
  36. package/dist/locus-info/controlsUtils.js.map +1 -1
  37. package/dist/locus-info/index.js +406 -121
  38. package/dist/locus-info/index.js.map +1 -1
  39. package/dist/locus-info/infoUtils.js +36 -5
  40. package/dist/locus-info/infoUtils.js.map +1 -1
  41. package/dist/locus-info/types.js +19 -0
  42. package/dist/locus-info/types.js.map +1 -1
  43. package/dist/media/MediaConnectionAwaiter.js +15 -2
  44. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  45. package/dist/media/index.js +8 -2
  46. package/dist/media/index.js.map +1 -1
  47. package/dist/media/properties.js +4 -5
  48. package/dist/media/properties.js.map +1 -1
  49. package/dist/meeting/in-meeting-actions.js +5 -1
  50. package/dist/meeting/in-meeting-actions.js.map +1 -1
  51. package/dist/meeting/index.js +1667 -834
  52. package/dist/meeting/index.js.map +1 -1
  53. package/dist/meeting/locusMediaRequest.js +229 -82
  54. package/dist/meeting/locusMediaRequest.js.map +1 -1
  55. package/dist/meeting/muteState.js +10 -1
  56. package/dist/meeting/muteState.js.map +1 -1
  57. package/dist/meeting/request.js +5 -2
  58. package/dist/meeting/request.js.map +1 -1
  59. package/dist/meeting/util.js +34 -2
  60. package/dist/meeting/util.js.map +1 -1
  61. package/dist/meeting-info/meeting-info-v2.js +2 -2
  62. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  63. package/dist/meetings/index.js +256 -118
  64. package/dist/meetings/index.js.map +1 -1
  65. package/dist/meetings/meetings.types.js +6 -1
  66. package/dist/meetings/meetings.types.js.map +1 -1
  67. package/dist/meetings/request.js +39 -0
  68. package/dist/meetings/request.js.map +1 -1
  69. package/dist/meetings/util.js +116 -18
  70. package/dist/meetings/util.js.map +1 -1
  71. package/dist/member/index.js +10 -0
  72. package/dist/member/index.js.map +1 -1
  73. package/dist/member/types.js.map +1 -1
  74. package/dist/member/util.js +30 -0
  75. package/dist/member/util.js.map +1 -1
  76. package/dist/members/index.js +101 -43
  77. package/dist/members/index.js.map +1 -1
  78. package/dist/members/util.js +8 -1
  79. package/dist/members/util.js.map +1 -1
  80. package/dist/metrics/constants.js +7 -1
  81. package/dist/metrics/constants.js.map +1 -1
  82. package/dist/multistream/codec/constants.js +63 -0
  83. package/dist/multistream/codec/constants.js.map +1 -0
  84. package/dist/multistream/mediaRequestManager.js +62 -15
  85. package/dist/multistream/mediaRequestManager.js.map +1 -1
  86. package/dist/multistream/receiveSlot.js +9 -0
  87. package/dist/multistream/receiveSlot.js.map +1 -1
  88. package/dist/reachability/clusterReachability.js.map +1 -1
  89. package/dist/reachability/index.js +121 -83
  90. package/dist/reachability/index.js.map +1 -1
  91. package/dist/reachability/reachability.types.js +2 -0
  92. package/dist/reachability/reachability.types.js.map +1 -1
  93. package/dist/reachability/util.js +45 -0
  94. package/dist/reachability/util.js.map +1 -1
  95. package/dist/reactions/reactions.type.js.map +1 -1
  96. package/dist/recording-controller/index.js +1 -3
  97. package/dist/recording-controller/index.js.map +1 -1
  98. package/dist/roap/turnDiscovery.js +8 -1
  99. package/dist/roap/turnDiscovery.js.map +1 -1
  100. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  101. package/dist/types/config.d.ts +2 -2
  102. package/dist/types/constants.d.ts +13 -1
  103. package/dist/types/controls-options-manager/index.d.ts +16 -0
  104. package/dist/types/hashTree/constants.d.ts +1 -0
  105. package/dist/types/hashTree/hashTreeParser.d.ts +189 -22
  106. package/dist/types/hashTree/utils.d.ts +7 -0
  107. package/dist/types/index.d.ts +3 -0
  108. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  109. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  110. package/dist/types/locus-info/index.d.ts +61 -7
  111. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  112. package/dist/types/locus-info/types.d.ts +21 -1
  113. package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
  114. package/dist/types/media/properties.d.ts +6 -2
  115. package/dist/types/meeting/in-meeting-actions.d.ts +4 -0
  116. package/dist/types/meeting/index.d.ts +175 -11
  117. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  118. package/dist/types/meeting/request.d.ts +1 -0
  119. package/dist/types/meeting/util.d.ts +9 -0
  120. package/dist/types/meetings/index.d.ts +38 -18
  121. package/dist/types/meetings/meetings.types.d.ts +15 -0
  122. package/dist/types/meetings/request.d.ts +14 -0
  123. package/dist/types/member/index.d.ts +1 -0
  124. package/dist/types/member/types.d.ts +1 -0
  125. package/dist/types/member/util.d.ts +9 -0
  126. package/dist/types/members/index.d.ts +15 -2
  127. package/dist/types/members/util.d.ts +1 -5
  128. package/dist/types/metrics/constants.d.ts +6 -0
  129. package/dist/types/multistream/codec/constants.d.ts +7 -0
  130. package/dist/types/multistream/mediaRequestManager.d.ts +22 -5
  131. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  132. package/dist/types/reachability/index.d.ts +10 -3
  133. package/dist/types/reachability/reachability.types.d.ts +7 -0
  134. package/dist/types/reachability/util.d.ts +17 -0
  135. package/dist/types/reactions/reactions.type.d.ts +3 -0
  136. package/dist/webinar/index.js +307 -161
  137. package/dist/webinar/index.js.map +1 -1
  138. package/package.json +23 -23
  139. package/src/aiEnableRequest/index.ts +16 -0
  140. package/src/breakouts/breakout.ts +3 -1
  141. package/src/breakouts/events.ts +33 -11
  142. package/src/breakouts/index.ts +110 -1
  143. package/src/common/errors/webex-errors.ts +50 -3
  144. package/src/config.ts +2 -2
  145. package/src/constants.ts +21 -3
  146. package/src/controls-options-manager/index.ts +62 -10
  147. package/src/hashTree/constants.ts +7 -0
  148. package/src/hashTree/hashTreeParser.ts +796 -192
  149. package/src/hashTree/utils.ts +19 -0
  150. package/src/index.ts +6 -0
  151. package/src/interceptors/dataChannelAuthToken.ts +88 -12
  152. package/src/interceptors/locusRetry.ts +25 -4
  153. package/src/interpretation/index.ts +27 -9
  154. package/src/interpretation/interpretation.types.ts +11 -0
  155. package/src/locus-info/controlsUtils.ts +3 -1
  156. package/src/locus-info/index.ts +412 -130
  157. package/src/locus-info/infoUtils.ts +41 -6
  158. package/src/locus-info/types.ts +25 -1
  159. package/src/media/MediaConnectionAwaiter.ts +21 -4
  160. package/src/media/index.ts +10 -1
  161. package/src/media/properties.ts +8 -3
  162. package/src/meeting/in-meeting-actions.ts +8 -0
  163. package/src/meeting/index.ts +922 -116
  164. package/src/meeting/locusMediaRequest.ts +106 -6
  165. package/src/meeting/muteState.ts +10 -1
  166. package/src/meeting/request.ts +11 -0
  167. package/src/meeting/util.ts +46 -5
  168. package/src/meeting-info/meeting-info-v2.ts +4 -2
  169. package/src/meetings/index.ts +168 -79
  170. package/src/meetings/meetings.types.ts +19 -0
  171. package/src/meetings/request.ts +43 -0
  172. package/src/meetings/util.ts +117 -4
  173. package/src/member/index.ts +10 -0
  174. package/src/member/types.ts +1 -0
  175. package/src/member/util.ts +29 -0
  176. package/src/members/index.ts +70 -7
  177. package/src/members/util.ts +12 -4
  178. package/src/metrics/constants.ts +6 -0
  179. package/src/multistream/codec/constants.ts +58 -0
  180. package/src/multistream/mediaRequestManager.ts +119 -28
  181. package/src/multistream/receiveSlot.ts +18 -0
  182. package/src/reachability/clusterReachability.ts +3 -2
  183. package/src/reachability/index.ts +47 -16
  184. package/src/reachability/reachability.types.ts +11 -0
  185. package/src/reachability/util.ts +36 -0
  186. package/src/reactions/reactions.type.ts +3 -0
  187. package/src/recording-controller/index.ts +1 -2
  188. package/src/roap/turnDiscovery.ts +9 -1
  189. package/src/webinar/index.ts +216 -38
  190. package/test/unit/spec/aiEnableRequest/index.ts +86 -0
  191. package/test/unit/spec/breakouts/breakout.ts +9 -3
  192. package/test/unit/spec/breakouts/events.ts +120 -2
  193. package/test/unit/spec/breakouts/index.ts +191 -2
  194. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  195. package/test/unit/spec/controls-options-manager/index.js +139 -32
  196. package/test/unit/spec/hashTree/hashTreeParser.ts +2299 -243
  197. package/test/unit/spec/hashTree/utils.ts +37 -0
  198. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +196 -0
  199. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  200. package/test/unit/spec/interpretation/index.ts +26 -4
  201. package/test/unit/spec/locus-info/controlsUtils.js +172 -57
  202. package/test/unit/spec/locus-info/index.js +643 -63
  203. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  204. package/test/unit/spec/media/MediaConnectionAwaiter.ts +55 -0
  205. package/test/unit/spec/media/index.ts +92 -0
  206. package/test/unit/spec/media/properties.ts +23 -23
  207. package/test/unit/spec/meeting/in-meeting-actions.ts +4 -0
  208. package/test/unit/spec/meeting/index.js +2704 -135
  209. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  210. package/test/unit/spec/meeting/muteState.js +81 -0
  211. package/test/unit/spec/meeting/request.js +12 -0
  212. package/test/unit/spec/meeting/utils.js +153 -1
  213. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  214. package/test/unit/spec/meetings/index.js +479 -48
  215. package/test/unit/spec/meetings/request.js +141 -0
  216. package/test/unit/spec/meetings/utils.js +402 -51
  217. package/test/unit/spec/member/index.js +7 -0
  218. package/test/unit/spec/member/util.js +89 -0
  219. package/test/unit/spec/members/index.js +216 -0
  220. package/test/unit/spec/members/request.js +37 -1
  221. package/test/unit/spec/members/utils.js +63 -0
  222. package/test/unit/spec/multistream/mediaRequestManager.ts +501 -37
  223. package/test/unit/spec/reachability/index.ts +128 -46
  224. package/test/unit/spec/reachability/util.ts +31 -0
  225. package/test/unit/spec/recording-controller/index.js +9 -8
  226. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  227. 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,9 +1167,84 @@ describe('plugin-meetings', () => {
902
1167
 
903
1168
  // resets joinWithMediaRetryInfo
904
1169
  assert.deepEqual(meeting.joinWithMediaRetryInfo, {
905
- isRetry: false,
1170
+ retryCount: 0,
906
1171
  prevJoinResponse: undefined,
1172
+ firstError: undefined,
1173
+ prevError: undefined,
907
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,
1224
+ prevJoinResponse: undefined,
1225
+ firstError: undefined,
1226
+ prevError: undefined,
1227
+ });
1228
+ });
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);
908
1248
  });
909
1249
 
910
1250
  it('should resolve if join() fails the first time but succeeds the second time', async () => {
@@ -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);
@@ -1253,25 +1716,136 @@ describe('plugin-meetings', () => {
1253
1716
  mediaOptions,
1254
1717
  });
1255
1718
 
1256
- await testUtils.flushPromises();
1719
+ await testUtils.flushPromises();
1720
+
1721
+ // check the callback works correctly on the 1st attempt
1722
+ assert.equal(icePhaseCallbacks.length, 1);
1723
+ assert.equal(icePhaseCallbacks[0](), 'JOIN_MEETING_RETRY');
1724
+
1725
+ // now trigger the failure, so that joinWithMedia() does a retry
1726
+ addMediaInternalResults[0].reject(addMediaError);
1727
+
1728
+ await testUtils.flushPromises();
1729
+
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
1732
+ assert.equal(icePhaseCallbacks.length, 2);
1733
+ assert.equal(icePhaseCallbacks[1](), 'JOIN_MEETING_FINAL');
1734
+
1735
+ // trigger 2nd failure
1736
+ addMediaInternalResults[1].reject(addMediaError);
1737
+
1738
+ await assert.isRejected(result);
1739
+ });
1740
+
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');
1745
+
1746
+ const icePhaseCallbacks = [];
1747
+ const addMediaInternalResults = [];
1748
+
1749
+ meeting.addMediaInternal = sinon.stub().callsFake((icePhaseCallback) => {
1750
+ const defer = new Defer();
1751
+
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');
1257
1828
 
1258
- // check the callback works correctly on the 1st attempt
1259
- assert.equal(icePhaseCallbacks.length, 1);
1260
- assert.equal(icePhaseCallbacks[0](), 'JOIN_MEETING_RETRY');
1829
+ sinon.stub(MeetingUtil, 'isUserInLeftState').returns(true);
1261
1830
 
1262
- // now trigger the failure, so that joinWithMedia() does a retry
1263
- addMediaInternalResults[0].reject(addMediaError);
1831
+ const leaveStub = sinon.stub(meeting, 'leave').resolves();
1264
1832
 
1265
- await testUtils.flushPromises();
1833
+ meeting.addMediaInternal = sinon
1834
+ .stub()
1835
+ .onFirstCall()
1836
+ .rejects(addMediaError)
1837
+ .onSecondCall()
1838
+ .resolves(test4);
1266
1839
 
1267
- // check the callback works correctly on the 2nd attempt
1268
- assert.equal(icePhaseCallbacks.length, 2);
1269
- assert.equal(icePhaseCallbacks[1](), 'JOIN_MEETING_FINAL');
1840
+ const result = await meeting.joinWithMedia({joinOptions, mediaOptions});
1270
1841
 
1271
- // trigger 2nd failure
1272
- addMediaInternalResults[1].reject(addMediaError);
1842
+ assert.deepEqual(result, {join: fakeJoinResult, media: test4, multistreamEnabled: true});
1273
1843
 
1274
- await assert.isRejected(result);
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);
1275
1849
  });
1276
1850
 
1277
1851
  [
@@ -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,97 @@ 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
+ {
2086
+ description: '409 error in cause (e.g. AddMediaFailed)',
2087
+ statusCode: 409,
2088
+ useCause: true,
2089
+ },
2090
+ {
2091
+ description: '403 error in cause (e.g. AddMediaFailed)',
2092
+ statusCode: 403,
2093
+ useCause: true,
2094
+ },
2095
+ ].forEach(({description, statusCode, useCause}) => {
2096
+ it(`should re-join on retry when ${description}`, async () => {
2097
+ const error = useCause
2098
+ ? Object.assign(new Error('wrapped error'), {cause: {statusCode}})
2099
+ : Object.assign(new Error('locus error'), {statusCode});
2100
+
2101
+ meeting.addMediaInternal = sinon
2102
+ .stub()
2103
+ .onFirstCall()
2104
+ .rejects(error)
2105
+ .onSecondCall()
2106
+ .resolves(test4);
2107
+
2108
+ const result = await meeting.joinWithMedia({joinOptions, mediaOptions});
2109
+
2110
+ assert.deepEqual(result, {
2111
+ join: fakeJoinResult,
2112
+ media: test4,
2113
+ multistreamEnabled: true,
2114
+ });
2115
+
2116
+ // join() should be called twice — once for the first attempt, once for the re-join
2117
+ assert.calledTwice(meeting.join);
2118
+ assert.calledTwice(generateTurnDiscoveryRequestMessageStub);
2119
+ });
2120
+ });
2121
+
2122
+ it('should allow up to JOIN_WITH_MEDIA_RETRY_MAX_COUNT retries for 409 errors', async () => {
2123
+ const error409 = Object.assign(new Error('locus dropped us'), {statusCode: 409});
2124
+
2125
+ meeting.addMediaInternal = sinon.stub().rejects(error409);
2126
+ meeting.join = sinon.stub().callsFake(() => Promise.resolve(fakeJoinResult));
2127
+ sinon.stub(meeting, 'leave').resolves();
2128
+
2129
+ await assert.isRejected(meeting.joinWithMedia({joinOptions, mediaOptions}));
2130
+
2131
+ // JOIN_WITH_MEDIA_RETRY_MAX_COUNT is 2, so we expect 3 attempts total (initial + 2 retries)
2132
+ assert.callCount(meeting.join, 3);
2133
+ assert.callCount(meeting.addMediaInternal, 3);
2134
+ });
2135
+
2136
+ it('should not retry on 1-1 calls', async () => {
2137
+ const addMediaError = new Error('addMedia error');
2138
+
2139
+ sinon.stub(MeetingsUtil, 'isOneOnOneCall').returns(true);
2140
+
2141
+ meeting.addMediaInternal = sinon.stub().rejects(addMediaError);
2142
+ sinon.stub(meeting, 'leave').resolves();
2143
+
2144
+ await assert.isRejected(
2145
+ meeting.joinWithMedia({joinOptions, mediaOptions}),
2146
+ addMediaError
2147
+ );
2148
+
2149
+ // should not retry - only 1 attempt
2150
+ assert.calledOnce(meeting.join);
2151
+ assert.calledOnce(meeting.addMediaInternal);
2152
+ assert.calledOnceWithExactly(
2153
+ Metrics.sendBehavioralMetric,
2154
+ BEHAVIORAL_METRICS.JOIN_WITH_MEDIA_FAILURE,
2155
+ {
2156
+ correlation_id: meeting.correlationId,
2157
+ locus_id: meeting.locusUrl.split('/').pop(),
2158
+ reason: addMediaError.message,
2159
+ stack: addMediaError.stack,
2160
+ leaveErrorReason: undefined,
2161
+ isRetry: false,
2162
+ },
2163
+ {
2164
+ type: addMediaError.name,
2165
+ }
2166
+ );
2167
+ });
1408
2168
  });
1409
2169
  describe('#isTranscriptionSupported', () => {
1410
2170
  it('should return false if the feature is not supported for the meeting', () => {
@@ -1977,12 +2737,120 @@ describe('plugin-meetings', () => {
1977
2737
  fakeProcessedReaction
1978
2738
  );
1979
2739
  });
2740
+
2741
+ [
2742
+ {
2743
+ title:
2744
+ 'should skip a reaction when the default relay route does not match the LLM binding',
2745
+ isPracticeSessionConnected: false,
2746
+ route: 'wrong-default-route',
2747
+ defaultBinding: 'default-route',
2748
+ practiceBinding: 'practice-route',
2749
+ shouldProcess: false,
2750
+ expectedSessionLabel: 'default session',
2751
+ },
2752
+ {
2753
+ title: 'should process a reaction when the default relay route matches the LLM binding',
2754
+ isPracticeSessionConnected: false,
2755
+ route: 'default-route',
2756
+ defaultBinding: 'default-route',
2757
+ practiceBinding: 'practice-route',
2758
+ shouldProcess: true,
2759
+ },
2760
+ {
2761
+ title:
2762
+ 'should process a reaction when the practice-session relay route matches the practice-session LLM binding',
2763
+ isPracticeSessionConnected: true,
2764
+ route: 'practice-route',
2765
+ defaultBinding: 'default-route',
2766
+ practiceBinding: 'practice-route',
2767
+ shouldProcess: true,
2768
+ },
2769
+ {
2770
+ title:
2771
+ 'should skip a reaction when the practice-session relay route does not match the practice-session LLM binding',
2772
+ isPracticeSessionConnected: true,
2773
+ route: 'default-route',
2774
+ defaultBinding: 'default-route',
2775
+ practiceBinding: 'practice-route',
2776
+ shouldProcess: false,
2777
+ expectedSessionLabel: 'practice session',
2778
+ },
2779
+ ].forEach(
2780
+ ({
2781
+ title,
2782
+ isPracticeSessionConnected,
2783
+ route,
2784
+ defaultBinding,
2785
+ practiceBinding,
2786
+ shouldProcess,
2787
+ expectedSessionLabel,
2788
+ }) => {
2789
+ it(title, () => {
2790
+ meeting.isReactionsSupported = sinon.stub().returns(true);
2791
+ meeting.config.receiveReactions = true;
2792
+ const fakeSendersName = 'Fake reactors name';
2793
+ meeting.members.membersCollection.get = sinon.stub().returns({name: fakeSendersName});
2794
+ webex.internal.llm.isConnected = sinon.stub().callsFake((llmSessionId) => {
2795
+ return llmSessionId === LLM_PRACTICE_SESSION && isPracticeSessionConnected;
2796
+ });
2797
+ webex.internal.llm.getBinding = sinon.stub().callsFake((llmSessionId) => {
2798
+ if (llmSessionId === LLM_PRACTICE_SESSION) {
2799
+ return practiceBinding;
2800
+ }
2801
+
2802
+ return defaultBinding;
2803
+ });
2804
+ const fakeReactionPayload = {
2805
+ type: 'fake_type',
2806
+ codepoints: 'fake_codepoints',
2807
+ shortcodes: 'fake_shortcodes',
2808
+ };
2809
+ const fakeSenderPayload = {
2810
+ participantId: 'fake_participant_id',
2811
+ };
2812
+ const fakeRelayEvent = {
2813
+ headers: {route},
2814
+ data: {
2815
+ relayType: REACTION_RELAY_TYPES.REACTION,
2816
+ reaction: fakeReactionPayload,
2817
+ sender: fakeSenderPayload,
2818
+ },
2819
+ };
2820
+ const fakeProcessedReaction = {
2821
+ reaction: fakeReactionPayload,
2822
+ sender: {
2823
+ id: fakeSenderPayload.participantId,
2824
+ name: fakeSendersName,
2825
+ },
2826
+ };
2827
+
2828
+ TriggerProxy.trigger.resetHistory();
2829
+ meeting.processRelayEvent(fakeRelayEvent);
2830
+
2831
+ if (shouldProcess) {
2832
+ assert.calledWith(
2833
+ TriggerProxy.trigger,
2834
+ sinon.match.instanceOf(Meeting),
2835
+ {
2836
+ file: 'meeting/index',
2837
+ function: 'join',
2838
+ },
2839
+ EVENT_TRIGGERS.MEETING_RECEIVE_REACTIONS,
2840
+ fakeProcessedReaction
2841
+ );
2842
+ } else {
2843
+ assert.notCalled(TriggerProxy.trigger);
2844
+ }
2845
+ });
2846
+ }
2847
+ );
1980
2848
  });
1981
2849
 
1982
2850
  describe('#handleLLMOnline', () => {
1983
2851
  beforeEach(() => {
1984
2852
  webex.internal.llm.off = sinon.stub();
1985
- webex.internal.voicea.getIsCaptionBoxOn = sinon.stub().returns(false);
2853
+ webex.internal.voicea.getKeepTranscriptionSubscribed = sinon.stub().returns(false);
1986
2854
  webex.internal.voicea.updateSubchannelSubscriptions = sinon.stub();
1987
2855
  });
1988
2856
 
@@ -2000,7 +2868,7 @@ describe('plugin-meetings', () => {
2000
2868
  });
2001
2869
 
2002
2870
  it('restores transcription subscription when caption intent is enabled', () => {
2003
- webex.internal.voicea.getIsCaptionBoxOn.returns(true);
2871
+ webex.internal.voicea.getKeepTranscriptionSubscribed.returns(true);
2004
2872
 
2005
2873
  meeting.handleLLMOnline();
2006
2874
 
@@ -2010,12 +2878,20 @@ describe('plugin-meetings', () => {
2010
2878
  });
2011
2879
 
2012
2880
  it('does not restore transcription subscription when caption intent is disabled', () => {
2013
- webex.internal.voicea.getIsCaptionBoxOn.returns(false);
2881
+ webex.internal.voicea.getKeepTranscriptionSubscribed.returns(false);
2014
2882
 
2015
2883
  meeting.handleLLMOnline();
2016
2884
 
2017
2885
  assert.notCalled(webex.internal.voicea.updateSubchannelSubscriptions);
2018
2886
  });
2887
+
2888
+ it('calls syncAllHashTreeDatasets on locusInfo', () => {
2889
+ sinon.stub(meeting.locusInfo, 'syncAllHashTreeDatasets').resolves();
2890
+
2891
+ meeting.handleLLMOnline();
2892
+
2893
+ assert.calledOnceWithExactly(meeting.locusInfo.syncAllHashTreeDatasets, {onlyLLM: true});
2894
+ });
2019
2895
  });
2020
2896
 
2021
2897
  describe('#join', () => {
@@ -2096,6 +2972,8 @@ describe('plugin-meetings', () => {
2096
2972
  regionCode: 'EU',
2097
2973
  },
2098
2974
  preferTranscoding: !enableMultistream,
2975
+ getCurrentSelfUrl: sinon.match.func,
2976
+ waitForSelfUrlChange: sinon.match.func,
2099
2977
  },
2100
2978
  {
2101
2979
  parent: meeting.webex,
@@ -2313,31 +3191,246 @@ describe('plugin-meetings', () => {
2313
3191
  },
2314
3192
  };
2315
3193
 
2316
- locusLLMEventListener({data: eventData});
3194
+ locusLLMEventListener({data: eventData});
3195
+
3196
+ assert.calledOnceWithExactly(locusInfoParseStub, meeting, eventData);
3197
+ });
3198
+
3199
+ it('UpdateLLMConnection sends a metric if not connected after timeout', async () => {
3200
+ sinon.stub(meeting, 'isJoined').returns(true);
3201
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3202
+ sinon.stub(meeting.webex.internal.llm, 'hasEverConnected').value(true);
3203
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({});
3204
+
3205
+ meeting.updateLLMConnection.restore();
3206
+
3207
+ await meeting.updateLLMConnection();
3208
+
3209
+ fakeClock.tick(3 * 60 * 1000);
3210
+
3211
+ assert.calledWith(
3212
+ Metrics.sendBehavioralMetric,
3213
+ BEHAVIORAL_METRICS.LLM_HEALTHCHECK_FAILURE,
3214
+ {
3215
+ correlation_id: meeting.correlationId,
3216
+ hasEverConnected: true,
3217
+ }
3218
+ );
3219
+ });
3220
+
3221
+ it('emits breakout join response metric only once per breakoutMoveId', async () => {
3222
+ sinon.stub(meeting, 'isJoined').returns(true);
3223
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3224
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3225
+ clientLLMDatachannelResponseTime: 10,
3226
+ clientLLMWebSocketConnectTime: 20,
3227
+ });
3228
+
3229
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3230
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3231
+ meeting.breakouts.set('sessionType', 'BREAKOUT');
3232
+ meeting.breakouts.set('status', 'OPEN');
3233
+ meeting.breakouts.set('currentBreakoutSession', {
3234
+ sessionId: 'session-id-1',
3235
+ groupId: 'group-id-1',
3236
+ });
3237
+
3238
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3239
+ meeting.updateLLMConnection.restore();
3240
+
3241
+ await meeting.updateLLMConnection();
3242
+ await meeting.updateLLMConnection();
3243
+
3244
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3245
+ .getCalls()
3246
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3247
+
3248
+ assert.lengthOf(joinResponseCalls, 1);
3249
+ assert.equal(joinResponseCalls[0].args[0].options.meetingId, meeting.id);
3250
+ });
3251
+
3252
+ it('does not emit breakout join response metric when breakout session is missing', async () => {
3253
+ sinon.stub(meeting, 'isJoined').returns(true);
3254
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3255
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3256
+ clientLLMDatachannelResponseTime: 10,
3257
+ clientLLMWebSocketConnectTime: 20,
3258
+ });
3259
+
3260
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3261
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3262
+
3263
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3264
+ meeting.updateLLMConnection.restore();
3265
+
3266
+ await meeting.updateLLMConnection();
3267
+
3268
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3269
+ .getCalls()
3270
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3271
+
3272
+ assert.lengthOf(joinResponseCalls, 0);
3273
+ });
3274
+
3275
+ it('does not emit failed breakout join response metric when breakout session is missing', async () => {
3276
+ sinon.stub(meeting, 'isJoined').returns(true);
3277
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3278
+ sinon
3279
+ .stub(meeting.webex.internal.llm, 'registerAndConnect')
3280
+ .rejects(new Error('failed to connect LLM'));
3281
+
3282
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3283
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3284
+
3285
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3286
+ meeting.updateLLMConnection.restore();
3287
+
3288
+ try {
3289
+ await meeting.updateLLMConnection();
3290
+ assert.fail('Expected updateLLMConnection to reject');
3291
+ } catch (error) {
3292
+ assert.equal(error.message, 'failed to connect LLM');
3293
+ }
3294
+
3295
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3296
+ .getCalls()
3297
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3298
+
3299
+ assert.lengthOf(joinResponseCalls, 0);
3300
+ });
3301
+
3302
+ it('emits llm breakout join response metric after suppressing join response without llmLatency', async () => {
3303
+ sinon.stub(meeting, 'isJoined').returns(true);
3304
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3305
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3306
+ clientLLMDatachannelResponseTime: 10,
3307
+ clientLLMWebSocketConnectTime: 20,
3308
+ });
3309
+
3310
+ meeting.config.enableAutomaticLLM = true;
3311
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3312
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3313
+ meeting.breakouts.set('sessionType', 'BREAKOUT');
3314
+ meeting.breakouts.set('status', 'OPEN');
3315
+ meeting.breakouts.set('currentBreakoutSession', {
3316
+ sessionId: 'session-id-1',
3317
+ groupId: 'group-id-1',
3318
+ });
3319
+
3320
+ assert.isFalse(meeting.shouldEmitBreakoutJoinResponseMetric('move-id-1'));
3321
+
3322
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3323
+ meeting.updateLLMConnection.restore();
3324
+
3325
+ await meeting.updateLLMConnection();
3326
+
3327
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3328
+ .getCalls()
3329
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3330
+
3331
+ assert.lengthOf(joinResponseCalls, 1);
3332
+ assert.deepEqual(joinResponseCalls[0].args[0].payload.llmLatency, {
3333
+ clientLLMDatachannelResponseTime: 10,
3334
+ clientLLMWebSocketConnectTime: 20,
3335
+ });
3336
+ });
3337
+
3338
+ it('emits breakout join response metric with llmLatency when returning to main session', async () => {
3339
+ sinon.stub(meeting, 'isJoined').returns(true);
3340
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3341
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({
3342
+ clientLLMDatachannelResponseTime: 10,
3343
+ clientLLMWebSocketConnectTime: 20,
3344
+ });
3345
+
3346
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3347
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3348
+ meeting.breakouts.set('sessionType', 'MAIN');
3349
+ meeting.breakouts.set('status', 'OPEN');
3350
+ meeting.breakouts.set('currentBreakoutSession', {
3351
+ sessionId: 'session-id-1',
3352
+ groupId: 'group-id-1',
3353
+ });
3354
+
3355
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3356
+ meeting.updateLLMConnection.restore();
3357
+
3358
+ await meeting.updateLLMConnection();
3359
+
3360
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3361
+ .getCalls()
3362
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
3363
+
3364
+ assert.lengthOf(joinResponseCalls, 1);
3365
+ assert.deepEqual(joinResponseCalls[0].args[0].payload.llmLatency, {
3366
+ clientLLMDatachannelResponseTime: 10,
3367
+ clientLLMWebSocketConnectTime: 20,
3368
+ });
3369
+ });
3370
+
3371
+ it('uses the partial datachannel timing from the error when the websocket connect fails', async () => {
3372
+ sinon.stub(meeting, 'isJoined').returns(true);
3373
+ sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
3374
+ const connectError = new Error('failed to connect LLM');
3375
+ connectError.timing = {clientLLMDatachannelResponseTime: 42};
3376
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').rejects(connectError);
3377
+
3378
+ meeting.meetingInfo.enableConvergedArchitecture = true;
3379
+ meeting.breakouts.set('breakoutMoveId', 'move-id-1');
3380
+ meeting.breakouts.set('sessionType', 'BREAKOUT');
3381
+ meeting.breakouts.set('status', 'OPEN');
3382
+ meeting.breakouts.set('currentBreakoutSession', {
3383
+ sessionId: 'session-id-1',
3384
+ groupId: 'group-id-1',
3385
+ });
3386
+
3387
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
3388
+ meeting.updateLLMConnection.restore();
3389
+
3390
+ try {
3391
+ await meeting.updateLLMConnection();
3392
+ assert.fail('Expected updateLLMConnection to reject');
3393
+ } catch (error) {
3394
+ assert.equal(error, connectError);
3395
+ }
3396
+
3397
+ const joinResponseCalls = webex.internal.newMetrics.submitClientEvent
3398
+ .getCalls()
3399
+ .filter((call) => call.args[0]?.name === 'client.breakout-session.join.response');
2317
3400
 
2318
- assert.calledOnceWithExactly(locusInfoParseStub, meeting, eventData);
3401
+ assert.lengthOf(joinResponseCalls, 1);
3402
+ assert.deepEqual(joinResponseCalls[0].args[0].payload.llmLatency, {
3403
+ clientLLMDatachannelResponseTime: 42,
3404
+ clientLLMWebSocketConnectTime: 0,
3405
+ });
2319
3406
  });
2320
3407
 
2321
- it('UpdateLLMConnection sends a metric if not connected after timeout', async () => {
3408
+ it('reports the partial datachannel timing on client.llm.connect.response when the websocket connect fails during initial join', async () => {
2322
3409
  sinon.stub(meeting, 'isJoined').returns(true);
2323
3410
  sinon.stub(meeting.webex.internal.llm, 'isConnected').returns(false);
2324
- sinon.stub(meeting.webex.internal.llm, 'hasEverConnected').value(true);
2325
- sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').resolves({});
3411
+ const connectError = new Error('failed to connect LLM');
3412
+ connectError.timing = {clientLLMDatachannelResponseTime: 42};
3413
+ sinon.stub(meeting.webex.internal.llm, 'registerAndConnect').rejects(connectError);
2326
3414
 
3415
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
2327
3416
  meeting.updateLLMConnection.restore();
2328
3417
 
2329
- await meeting.updateLLMConnection();
3418
+ try {
3419
+ await meeting.updateLLMConnection({isInitialJoinPhase: true});
3420
+ assert.fail('Expected updateLLMConnection to reject');
3421
+ } catch (error) {
3422
+ assert.equal(error, connectError);
3423
+ }
2330
3424
 
2331
- fakeClock.tick(3 * 60 * 1000);
3425
+ const connectResponseCalls = webex.internal.newMetrics.submitClientEvent
3426
+ .getCalls()
3427
+ .filter((call) => call.args[0]?.name === 'client.llm.connect.response');
2332
3428
 
2333
- assert.calledWith(
2334
- Metrics.sendBehavioralMetric,
2335
- BEHAVIORAL_METRICS.LLM_HEALTHCHECK_FAILURE,
2336
- {
2337
- correlation_id: meeting.correlationId,
2338
- hasEverConnected: true,
2339
- }
2340
- );
3429
+ assert.lengthOf(connectResponseCalls, 1);
3430
+ assert.deepEqual(connectResponseCalls[0].args[0].payload.llmLatency, {
3431
+ clientLLMDatachannelResponseTime: 42,
3432
+ clientLLMWebSocketConnectTime: 0,
3433
+ });
2341
3434
  });
2342
3435
 
2343
3436
  it('clears the LLM health check timer when disconnecting LLM', async () => {
@@ -2467,7 +3560,6 @@ describe('plugin-meetings', () => {
2467
3560
  });
2468
3561
  });
2469
3562
 
2470
-
2471
3563
  describe('#addMedia', () => {
2472
3564
  const muteStateStub = {
2473
3565
  handleClientRequest: sinon.stub().returns(Promise.resolve(true)),
@@ -2614,9 +3706,11 @@ describe('plugin-meetings', () => {
2614
3706
  retriedWithTurnServer: false,
2615
3707
  isMultistream: false,
2616
3708
  isJoinWithMediaRetry: false,
3709
+ iceTransportPolicy: 'all',
2617
3710
  signalingState: 'unknown',
2618
3711
  connectionState: 'unknown',
2619
3712
  iceConnectionState: 'unknown',
3713
+ connectionType: 'udp',
2620
3714
  someReachabilityMetric1: 'some value1',
2621
3715
  someReachabilityMetric2: 'some value2',
2622
3716
  selectedCandidatePairChanges: 2,
@@ -2742,9 +3836,11 @@ describe('plugin-meetings', () => {
2742
3836
  retriedWithTurnServer: false,
2743
3837
  isMultistream: false,
2744
3838
  isJoinWithMediaRetry: false,
3839
+ iceTransportPolicy: 'all',
2745
3840
  signalingState: 'unknown',
2746
3841
  connectionState: 'unknown',
2747
3842
  iceConnectionState: 'unknown',
3843
+ connectionType: 'udp',
2748
3844
  someReachabilityMetric1: 'some value1',
2749
3845
  someReachabilityMetric2: 'some value2',
2750
3846
  selectedCandidatePairChanges: 2,
@@ -3178,6 +4274,7 @@ describe('plugin-meetings', () => {
3178
4274
  unpublishStream: sinon.stub(),
3179
4275
  setNamedMediaGroups: sinon.stub(),
3180
4276
  });
4277
+ sinon.spy(meeting.sendSlotManager, 'reset');
3181
4278
 
3182
4279
  await meeting.addMedia({
3183
4280
  allowMediaInLobby: true,
@@ -3190,6 +4287,7 @@ describe('plugin-meetings', () => {
3190
4287
  },
3191
4288
  });
3192
4289
 
4290
+ assert.calledOnce(meeting.sendSlotManager.reset);
3193
4291
  assert.notCalled(publishStreamStub);
3194
4292
  });
3195
4293
 
@@ -3213,6 +4311,7 @@ describe('plugin-meetings', () => {
3213
4311
  }
3214
4312
  return videoSlot;
3215
4313
  });
4314
+ sinon.spy(meeting.sendSlotManager, 'reset');
3216
4315
 
3217
4316
  await meeting.addMedia({
3218
4317
  allowMediaInLobby: true,
@@ -3225,6 +4324,7 @@ describe('plugin-meetings', () => {
3225
4324
  },
3226
4325
  });
3227
4326
 
4327
+ assert.calledOnce(meeting.sendSlotManager.reset);
3228
4328
  assert.calledOnceWithExactly(audioSlot.publishStream, fakeMicrophoneStream);
3229
4329
  assert.calledOnceWithExactly(videoSlot.publishStream, fakeCameraStream);
3230
4330
  });
@@ -3247,11 +4347,13 @@ describe('plugin-meetings', () => {
3247
4347
 
3248
4348
  meeting.meetingState = 'ACTIVE';
3249
4349
  meeting.isMultistream = true;
4350
+ sinon.spy(meeting.sendSlotManager, 'reset');
3250
4351
 
3251
4352
  await meeting.addMedia({
3252
4353
  mediaSettings: {},
3253
4354
  });
3254
4355
 
4356
+ assert.calledOnce(meeting.sendSlotManager.reset);
3255
4357
  // check that rtcMetrics was passed to Media.createMediaConnection
3256
4358
  assert.calledOnce(Media.createMediaConnection);
3257
4359
  assert.calledWith(
@@ -3512,9 +4614,11 @@ describe('plugin-meetings', () => {
3512
4614
  retriedWithTurnServer: true,
3513
4615
  isMultistream: false,
3514
4616
  isJoinWithMediaRetry: false,
4617
+ iceTransportPolicy: 'all',
3515
4618
  signalingState: 'unknown',
3516
4619
  connectionState: 'unknown',
3517
4620
  iceConnectionState: 'unknown',
4621
+ connectionType: 'udp',
3518
4622
  selectedCandidatePairChanges: 2,
3519
4623
  numTransports: 1,
3520
4624
  iceCandidatesCount: 0,
@@ -3539,6 +4643,173 @@ describe('plugin-meetings', () => {
3539
4643
  assert.isOk(errorThrown);
3540
4644
  });
3541
4645
 
4646
+ [
4647
+ {iceConnected: true, title: 'iceConnected=true'},
4648
+ {iceConnected: false, title: 'iceConnected=false'},
4649
+ ].forEach(({iceConnected, title}) => {
4650
+ it(`should propagate ${title} from waitForMediaConnectionConnected rejection to AddMediaFailed`, async () => {
4651
+ webex.meetings.reachability = {
4652
+ isWebexMediaBackendUnreachable: sinon.stub().resolves(false),
4653
+ getReachabilityMetrics: sinon.stub().resolves({}),
4654
+ stopReachability: sinon.stub(),
4655
+ isSubnetReachable: sinon.stub().returns(true),
4656
+ };
4657
+ webex.internal.newMetrics.callDiagnosticMetrics.getErrorPayloadForClientErrorCode =
4658
+ sinon.stub().returns({fatal: true});
4659
+ sinon.stub(CallDiagnosticUtils, 'generateClientErrorCodeForIceFailure').returns(2004);
4660
+
4661
+ meeting.meetingState = 'ACTIVE';
4662
+ const rejectedResult = {iceConnected};
4663
+ meeting.mediaProperties.waitForMediaConnectionConnected = sinon
4664
+ .stub()
4665
+ .rejects(rejectedResult);
4666
+
4667
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4668
+ turnServerInfo: {urls: ['turns:fake:443'], username: 'u', password: 'p'},
4669
+ turnDiscoverySkippedReason: undefined,
4670
+ });
4671
+
4672
+ const forceRtcMetricsSend = sinon.stub().resolves();
4673
+ Media.createMediaConnection = sinon.stub().returns({
4674
+ close: sinon.stub(),
4675
+ forceRtcMetricsSend,
4676
+ getConnectionState: sinon.stub().returns(ConnectionState.Connected),
4677
+ initiateOffer: sinon.stub().resolves({}),
4678
+ on: sinon.stub(),
4679
+ });
4680
+
4681
+ let thrownError;
4682
+ await meeting.addMedia({mediaSettings: {}}).catch((err) => {
4683
+ thrownError = err;
4684
+ });
4685
+
4686
+ assert.instanceOf(thrownError, AddMediaFailed);
4687
+ assert.equal(thrownError.iceConnected, iceConnected);
4688
+ // the AddMediaFailed cause should be the MediaConnectionTimedOutError, which in turn should
4689
+ // preserve the original rejected result as its cause, so that the web client
4690
+ // can find the CA-reported error in the eventErrorCache via the cause chain
4691
+ assert.instanceOf(thrownError.cause, MediaConnectionTimedOutError);
4692
+ assert.equal(thrownError.cause.cause, rejectedResult);
4693
+ });
4694
+ });
4695
+
4696
+ describe('iceTransportPolicy=relay handling', () => {
4697
+ let createMediaConnectionStub;
4698
+
4699
+ beforeEach(() => {
4700
+ webex.meetings.reachability = {
4701
+ isWebexMediaBackendUnreachable: sinon.stub().resolves(false),
4702
+ isAnyClusterReachableViaProtocol: sinon.stub().resolves(true),
4703
+ getReachabilityMetrics: sinon.stub().resolves({}),
4704
+ stopReachability: sinon.stub(),
4705
+ isSubnetReachable: sinon.stub().returns(true),
4706
+ };
4707
+ webex.internal.newMetrics.callDiagnosticMetrics.getErrorPayloadForClientErrorCode =
4708
+ sinon.stub().returns({fatal: true});
4709
+ sinon.stub(CallDiagnosticUtils, 'generateClientErrorCodeForIceFailure').returns(2004);
4710
+
4711
+ meeting.meetingState = 'ACTIVE';
4712
+ meeting.mediaProperties.waitForMediaConnectionConnected = sinon.stub().resolves();
4713
+
4714
+ createMediaConnectionStub = sinon.stub().returns({
4715
+ close: sinon.stub(),
4716
+ forceRtcMetricsSend: sinon.stub().resolves(),
4717
+ getConnectionState: sinon.stub().returns(ConnectionState.Connected),
4718
+ initiateOffer: sinon.stub().resolves({}),
4719
+ on: sinon.stub(),
4720
+ });
4721
+ Media.createMediaConnection = createMediaConnectionStub;
4722
+ });
4723
+
4724
+ [
4725
+ {
4726
+ title:
4727
+ 'should drop iceTransportPolicy=relay when TURN discovery returns no turn server info',
4728
+ turnServerInfo: undefined,
4729
+ turnDiscoverySkippedReason: 'reachability',
4730
+ },
4731
+ {
4732
+ title:
4733
+ 'should drop iceTransportPolicy=relay when TURN discovery returns turnServerInfo with empty urls',
4734
+ turnServerInfo: {urls: [], username: 'u', password: 'p'},
4735
+ turnDiscoverySkippedReason: undefined,
4736
+ },
4737
+ ].forEach(({title, turnServerInfo, turnDiscoverySkippedReason}) => {
4738
+ it(title, async () => {
4739
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4740
+ turnServerInfo,
4741
+ turnDiscoverySkippedReason,
4742
+ });
4743
+
4744
+ await meeting.addMediaInternal(
4745
+ () => 'JOIN_MEETING_FINAL',
4746
+ false,
4747
+ undefined,
4748
+ 'relay',
4749
+ {mediaSettings: {}}
4750
+ );
4751
+
4752
+ assert.calledOnce(createMediaConnectionStub);
4753
+ const config = createMediaConnectionStub.firstCall.args[3];
4754
+ assert.isUndefined(config.iceTransportPolicy);
4755
+
4756
+ const successCall = Metrics.sendBehavioralMetric
4757
+ .getCalls()
4758
+ .find((call) => call.args[0] === BEHAVIORAL_METRICS.ADD_MEDIA_SUCCESS);
4759
+ assert.isDefined(successCall);
4760
+ assert.equal(successCall.args[1].iceTransportPolicy, 'all');
4761
+ });
4762
+ });
4763
+
4764
+ it('should send ADD_MEDIA_SUCCESS metric with iceTransportPolicy=relay when relay is used', async () => {
4765
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4766
+ turnServerInfo: {
4767
+ urls: ['turns:turn-server:443?transport=tcp'],
4768
+ username: 'u',
4769
+ password: 'p',
4770
+ },
4771
+ turnDiscoverySkippedReason: undefined,
4772
+ });
4773
+
4774
+ await meeting.addMediaInternal(() => 'JOIN_MEETING_FINAL', false, undefined, 'relay', {
4775
+ mediaSettings: {},
4776
+ });
4777
+
4778
+ const successCall = Metrics.sendBehavioralMetric
4779
+ .getCalls()
4780
+ .find((call) => call.args[0] === BEHAVIORAL_METRICS.ADD_MEDIA_SUCCESS);
4781
+ assert.isDefined(successCall);
4782
+ assert.equal(successCall.args[1].iceTransportPolicy, 'relay');
4783
+ });
4784
+
4785
+ it('should send ADD_MEDIA_FAILURE metric with iceTransportPolicy=relay when relay attempt fails', async () => {
4786
+ meeting.roap.doTurnDiscovery = sinon.stub().returns({
4787
+ turnServerInfo: {
4788
+ urls: ['turns:turn-server:443?transport=tcp'],
4789
+ username: 'u',
4790
+ password: 'p',
4791
+ },
4792
+ turnDiscoverySkippedReason: undefined,
4793
+ });
4794
+
4795
+ meeting.mediaProperties.waitForMediaConnectionConnected = sinon
4796
+ .stub()
4797
+ .rejects(new MediaConnectionTimedOutError('timed out', true));
4798
+
4799
+ await assert.isRejected(
4800
+ meeting.addMediaInternal(() => 'JOIN_MEETING_FINAL', false, undefined, 'relay', {
4801
+ mediaSettings: {},
4802
+ })
4803
+ );
4804
+
4805
+ const failureCall = Metrics.sendBehavioralMetric
4806
+ .getCalls()
4807
+ .find((call) => call.args[0] === BEHAVIORAL_METRICS.ADD_MEDIA_FAILURE);
4808
+ assert.isDefined(failureCall);
4809
+ assert.equal(failureCall.args[1].iceTransportPolicy, 'relay');
4810
+ });
4811
+ });
4812
+
3542
4813
  it('should resolve if waitForMediaConnectionConnected() rejects the first time but resolves the second time', async () => {
3543
4814
  const FAKE_ERROR = {fatal: true};
3544
4815
  webex.meetings.reachability = {
@@ -3728,6 +4999,7 @@ describe('plugin-meetings', () => {
3728
4999
  isMultistream: false,
3729
5000
  retriedWithTurnServer: true,
3730
5001
  isJoinWithMediaRetry: false,
5002
+ iceTransportPolicy: 'all',
3731
5003
  iceCandidatesCount: 0,
3732
5004
  subnet_reachable: null,
3733
5005
  selected_cluster: null,
@@ -3891,6 +5163,7 @@ describe('plugin-meetings', () => {
3891
5163
  isMultistream: false,
3892
5164
  retriedWithTurnServer: false,
3893
5165
  isJoinWithMediaRetry: false,
5166
+ iceTransportPolicy: 'all',
3894
5167
  someReachabilityMetric1: 'some value1',
3895
5168
  someReachabilityMetric2: 'some value2',
3896
5169
  iceCandidatesCount: 3,
@@ -3956,9 +5229,11 @@ describe('plugin-meetings', () => {
3956
5229
  retriedWithTurnServer: false,
3957
5230
  isMultistream: false,
3958
5231
  isJoinWithMediaRetry: false,
5232
+ iceTransportPolicy: 'all',
3959
5233
  signalingState: 'unknown',
3960
5234
  connectionState: 'unknown',
3961
5235
  iceConnectionState: 'unknown',
5236
+ connectionType: 'udp',
3962
5237
  selectedCandidatePairChanges: 2,
3963
5238
  numTransports: 1,
3964
5239
  subnet_reachable: null,
@@ -4019,9 +5294,11 @@ describe('plugin-meetings', () => {
4019
5294
  retriedWithTurnServer: false,
4020
5295
  isMultistream: false,
4021
5296
  isJoinWithMediaRetry: false,
5297
+ iceTransportPolicy: 'all',
4022
5298
  signalingState: 'unknown',
4023
5299
  connectionState: 'unknown',
4024
5300
  iceConnectionState: 'unknown',
5301
+ connectionType: 'udp',
4025
5302
  selectedCandidatePairChanges: 2,
4026
5303
  numTransports: 1,
4027
5304
  '701_error': 2,
@@ -4083,6 +5360,7 @@ describe('plugin-meetings', () => {
4083
5360
  isMultistream: false,
4084
5361
  retriedWithTurnServer: false,
4085
5362
  isJoinWithMediaRetry: false,
5363
+ iceTransportPolicy: 'all',
4086
5364
  iceCandidatesCount: 0,
4087
5365
  reachability_public_udp_success: 5,
4088
5366
  subnet_reachable: false,
@@ -4148,9 +5426,11 @@ describe('plugin-meetings', () => {
4148
5426
  retriedWithTurnServer: false,
4149
5427
  isMultistream: false,
4150
5428
  isJoinWithMediaRetry: false,
5429
+ iceTransportPolicy: 'all',
4151
5430
  signalingState: 'unknown',
4152
5431
  connectionState: 'unknown',
4153
5432
  iceConnectionState: 'unknown',
5433
+ connectionType: 'udp',
4154
5434
  selectedCandidatePairChanges: 2,
4155
5435
  numTransports: 1,
4156
5436
  reachability_public_udp_success: 5,
@@ -4502,36 +5782,327 @@ describe('plugin-meetings', () => {
4502
5782
  {data: fakeData}
4503
5783
  );
4504
5784
 
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)),
4513
- ],
4514
- },
5785
+ assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
5786
+ name: 'client.mediaquality.event',
5787
+ options: {
5788
+ meetingId: meeting.id,
5789
+ },
5790
+ payload: {
5791
+ intervals: [
5792
+ sinon.match.has('intervalMetadata', sinon.match.has('meetingUserCount', 2)),
5793
+ ],
5794
+ },
5795
+ });
5796
+ });
5797
+
5798
+ it('calls submitMQE correctly', async () => {
5799
+ const fakeData = {intervalMetadata: {bla: 'bla'}};
5800
+
5801
+ statsAnalyzerStub.emit(
5802
+ {file: 'test', function: 'test'},
5803
+ StatsAnalyzerEventNames.MEDIA_QUALITY,
5804
+ {data: fakeData}
5805
+ );
5806
+
5807
+ assert.calledWithMatch(webex.internal.newMetrics.submitMQE, {
5808
+ name: 'client.mediaquality.event',
5809
+ options: {
5810
+ meetingId: meeting.id,
5811
+ },
5812
+ payload: {
5813
+ intervals: [fakeData],
5814
+ },
5815
+ });
5816
+ });
5817
+
5818
+ describe('handles STATS_UPDATE event for SRTP cipher detection', () => {
5819
+ it('emits MEETING_SRTP_CIPHER_UPDATED event when srtpCipher is found in transport stats', async () => {
5820
+ const fakeStats = new Map([
5821
+ [
5822
+ 'transport-1',
5823
+ {
5824
+ type: 'transport',
5825
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
5826
+ dtlsCipher: 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256',
5827
+ },
5828
+ ],
5829
+ [
5830
+ 'outbound-rtp-1',
5831
+ {
5832
+ type: 'outbound-rtp',
5833
+ ssrc: 12345,
5834
+ },
5835
+ ],
5836
+ ]);
5837
+
5838
+ statsAnalyzerStub.emit(
5839
+ {file: 'test', function: 'test'},
5840
+ StatsAnalyzerEventNames.STATS_UPDATE,
5841
+ {stats: fakeStats}
5842
+ );
5843
+
5844
+ assert.calledWith(
5845
+ TriggerProxy.trigger,
5846
+ sinon.match.instanceOf(Meeting),
5847
+ {
5848
+ file: 'meeting/index',
5849
+ function: 'setupStatsAnalyzerEventHandlers',
5850
+ },
5851
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5852
+ {srtpCipher: 'AES_CM_128_HMAC_SHA1_80'}
5853
+ );
5854
+
5855
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5856
+ });
5857
+
5858
+ it('updates meeting.mediaProperties.srtpCipher when cipher changes', async () => {
5859
+ const firstStats = new Map([
5860
+ [
5861
+ 'transport-1',
5862
+ {
5863
+ type: 'transport',
5864
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
5865
+ },
5866
+ ],
5867
+ ]);
5868
+
5869
+ statsAnalyzerStub.emit(
5870
+ {file: 'test', function: 'test'},
5871
+ StatsAnalyzerEventNames.STATS_UPDATE,
5872
+ {stats: firstStats}
5873
+ );
5874
+
5875
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5876
+
5877
+ const secondStats = new Map([
5878
+ [
5879
+ 'transport-1',
5880
+ {
5881
+ type: 'transport',
5882
+ srtpCipher: 'AEAD_AES_256_GCM',
5883
+ },
5884
+ ],
5885
+ ]);
5886
+
5887
+ TriggerProxy.trigger.resetHistory();
5888
+
5889
+ statsAnalyzerStub.emit(
5890
+ {file: 'test', function: 'test'},
5891
+ StatsAnalyzerEventNames.STATS_UPDATE,
5892
+ {stats: secondStats}
5893
+ );
5894
+
5895
+ assert.calledWith(
5896
+ TriggerProxy.trigger,
5897
+ sinon.match.instanceOf(Meeting),
5898
+ {
5899
+ file: 'meeting/index',
5900
+ function: 'setupStatsAnalyzerEventHandlers',
5901
+ },
5902
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5903
+ {srtpCipher: 'AEAD_AES_256_GCM'}
5904
+ );
5905
+
5906
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AEAD_AES_256_GCM');
5907
+ });
5908
+
5909
+ it('does not emit event when srtpCipher has not changed', async () => {
5910
+ const firstStats = new Map([
5911
+ [
5912
+ 'transport-1',
5913
+ {
5914
+ type: 'transport',
5915
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
5916
+ },
5917
+ ],
5918
+ ]);
5919
+
5920
+ statsAnalyzerStub.emit(
5921
+ {file: 'test', function: 'test'},
5922
+ StatsAnalyzerEventNames.STATS_UPDATE,
5923
+ {stats: firstStats}
5924
+ );
5925
+
5926
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5927
+
5928
+ TriggerProxy.trigger.resetHistory();
5929
+
5930
+ // Emit same cipher again
5931
+ statsAnalyzerStub.emit(
5932
+ {file: 'test', function: 'test'},
5933
+ StatsAnalyzerEventNames.STATS_UPDATE,
5934
+ {stats: firstStats}
5935
+ );
5936
+
5937
+ // Should not trigger event again
5938
+ assert.neverCalledWith(
5939
+ TriggerProxy.trigger,
5940
+ sinon.match.instanceOf(Meeting),
5941
+ sinon.match.any,
5942
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5943
+ sinon.match.any
5944
+ );
5945
+
5946
+ // Cipher should remain the same
5947
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
5948
+ });
5949
+
5950
+ it('does not emit event when stats contain no transport with srtpCipher', async () => {
5951
+ const fakeStats = new Map([
5952
+ [
5953
+ 'outbound-rtp-1',
5954
+ {
5955
+ type: 'outbound-rtp',
5956
+ ssrc: 12345,
5957
+ },
5958
+ ],
5959
+ [
5960
+ 'inbound-rtp-1',
5961
+ {
5962
+ type: 'inbound-rtp',
5963
+ ssrc: 67890,
5964
+ },
5965
+ ],
5966
+ ]);
5967
+
5968
+ statsAnalyzerStub.emit(
5969
+ {file: 'test', function: 'test'},
5970
+ StatsAnalyzerEventNames.STATS_UPDATE,
5971
+ {stats: fakeStats}
5972
+ );
5973
+
5974
+ assert.neverCalledWith(
5975
+ TriggerProxy.trigger,
5976
+ sinon.match.instanceOf(Meeting),
5977
+ sinon.match.any,
5978
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
5979
+ sinon.match.any
5980
+ );
5981
+
5982
+ assert.isUndefined(meeting.mediaProperties.srtpCipher);
5983
+ });
5984
+
5985
+ it('does not emit event when transport stat has no srtpCipher property', async () => {
5986
+ const fakeStats = new Map([
5987
+ [
5988
+ 'transport-1',
5989
+ {
5990
+ type: 'transport',
5991
+ dtlsCipher: 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256',
5992
+ // no srtpCipher property
5993
+ },
5994
+ ],
5995
+ ]);
5996
+
5997
+ statsAnalyzerStub.emit(
5998
+ {file: 'test', function: 'test'},
5999
+ StatsAnalyzerEventNames.STATS_UPDATE,
6000
+ {stats: fakeStats}
6001
+ );
6002
+
6003
+ assert.neverCalledWith(
6004
+ TriggerProxy.trigger,
6005
+ sinon.match.instanceOf(Meeting),
6006
+ sinon.match.any,
6007
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
6008
+ sinon.match.any
6009
+ );
6010
+
6011
+ assert.isUndefined(meeting.mediaProperties.srtpCipher);
6012
+ });
6013
+
6014
+ it('uses first transport with srtpCipher when multiple transports exist', async () => {
6015
+ const fakeStats = new Map([
6016
+ [
6017
+ 'transport-1',
6018
+ {
6019
+ type: 'transport',
6020
+ srtpCipher: 'AES_CM_128_HMAC_SHA1_80',
6021
+ },
6022
+ ],
6023
+ [
6024
+ 'transport-2',
6025
+ {
6026
+ type: 'transport',
6027
+ srtpCipher: 'AEAD_AES_256_GCM',
6028
+ },
6029
+ ],
6030
+ [
6031
+ 'outbound-rtp-1',
6032
+ {
6033
+ type: 'outbound-rtp',
6034
+ ssrc: 12345,
6035
+ },
6036
+ ],
6037
+ ]);
6038
+
6039
+ statsAnalyzerStub.emit(
6040
+ {file: 'test', function: 'test'},
6041
+ StatsAnalyzerEventNames.STATS_UPDATE,
6042
+ {stats: fakeStats}
6043
+ );
6044
+
6045
+ assert.calledWith(
6046
+ TriggerProxy.trigger,
6047
+ sinon.match.instanceOf(Meeting),
6048
+ {
6049
+ file: 'meeting/index',
6050
+ function: 'setupStatsAnalyzerEventHandlers',
6051
+ },
6052
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
6053
+ {srtpCipher: 'AES_CM_128_HMAC_SHA1_80'}
6054
+ );
6055
+
6056
+ assert.equal(meeting.mediaProperties.srtpCipher, 'AES_CM_128_HMAC_SHA1_80');
6057
+ });
6058
+
6059
+ it('handles empty stats map without errors', async () => {
6060
+ const emptyStats = new Map();
6061
+
6062
+ statsAnalyzerStub.emit(
6063
+ {file: 'test', function: 'test'},
6064
+ StatsAnalyzerEventNames.STATS_UPDATE,
6065
+ {stats: emptyStats}
6066
+ );
6067
+
6068
+ assert.neverCalledWith(
6069
+ TriggerProxy.trigger,
6070
+ sinon.match.instanceOf(Meeting),
6071
+ sinon.match.any,
6072
+ EVENT_TRIGGERS.MEETING_SRTP_CIPHER_UPDATED,
6073
+ sinon.match.any
6074
+ );
6075
+
6076
+ assert.isUndefined(meeting.mediaProperties.srtpCipher);
4515
6077
  });
4516
- });
4517
6078
 
4518
- it('calls submitMQE correctly', async () => {
4519
- const fakeData = {intervalMetadata: {bla: 'bla'}};
6079
+ it('logs cipher change when cipher is updated', async () => {
6080
+ const loggerSpy = sinon.spy(LoggerProxy.logger, 'info');
4520
6081
 
4521
- statsAnalyzerStub.emit(
4522
- {file: 'test', function: 'test'},
4523
- StatsAnalyzerEventNames.MEDIA_QUALITY,
4524
- {data: fakeData}
4525
- );
6082
+ meeting.mediaProperties.srtpCipher = 'AES_CM_128_HMAC_SHA1_80';
4526
6083
 
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
- },
6084
+ const newStats = new Map([
6085
+ [
6086
+ 'transport-1',
6087
+ {
6088
+ type: 'transport',
6089
+ srtpCipher: 'AEAD_AES_256_GCM',
6090
+ },
6091
+ ],
6092
+ ]);
6093
+
6094
+ statsAnalyzerStub.emit(
6095
+ {file: 'test', function: 'test'},
6096
+ StatsAnalyzerEventNames.STATS_UPDATE,
6097
+ {stats: newStats}
6098
+ );
6099
+
6100
+ assert.calledWithMatch(
6101
+ loggerSpy,
6102
+ sinon.match(/SRTP cipher changed from AES_CM_128_HMAC_SHA1_80 to AEAD_AES_256_GCM/)
6103
+ );
6104
+
6105
+ loggerSpy.restore();
4535
6106
  });
4536
6107
  });
4537
6108
  });
@@ -4637,6 +6208,7 @@ describe('plugin-meetings', () => {
4637
6208
  member2: unmutedMember,
4638
6209
  member3: selfMember,
4639
6210
  });
6211
+ meeting.isUserUnadmitted = false;
4640
6212
 
4641
6213
  // Reset the stub to clear any previous calls
4642
6214
  TriggerProxy.trigger.resetHistory();
@@ -4656,8 +6228,46 @@ describe('plugin-meetings', () => {
4656
6228
  meeting.mediaProperties.sendMediaIssueMetric,
4657
6229
  'inbound_audio',
4658
6230
  fakeEventData.issueSubType,
4659
- meeting.correlationId
6231
+ {
6232
+ correlationId: meeting.correlationId,
6233
+ isMultistream: meeting.isMultistream,
6234
+ }
6235
+ );
6236
+ });
6237
+
6238
+ it('should not trigger event or metric when the user is in the lobby', () => {
6239
+ const fakeEventData = {issueSubType: 'DECODE_RESULTS_IN_ZERO_AUDIO_LEVEL'};
6240
+
6241
+ const unmutedMember = {
6242
+ isSelf: false,
6243
+ isPairedWithSelf: false,
6244
+ isAudioMuted: false,
6245
+ };
6246
+ const selfMember = {
6247
+ isSelf: true,
6248
+ isPairedWithSelf: false,
6249
+ isAudioMuted: false,
6250
+ };
6251
+ meeting.members.membersCollection.getAll = sinon.stub().returns({
6252
+ member1: unmutedMember,
6253
+ member2: selfMember,
6254
+ });
6255
+ meeting.isUserUnadmitted = true;
6256
+
6257
+ // Reset the stub to clear any previous calls
6258
+ TriggerProxy.trigger.resetHistory();
6259
+
6260
+ // Emit the event from statsMonitor
6261
+ listeners[StatsMonitorEventNames.INBOUND_AUDIO_ISSUE](fakeEventData);
6262
+
6263
+ assert.neverCalledWith(
6264
+ TriggerProxy.trigger,
6265
+ meeting,
6266
+ sinon.match.object,
6267
+ EVENT_TRIGGERS.MEDIA_INBOUND_AUDIO_ISSUE_DETECTED,
6268
+ fakeEventData
4660
6269
  );
6270
+ assert.notCalled(meeting.mediaProperties.sendMediaIssueMetric);
4661
6271
  });
4662
6272
  });
4663
6273
  });
@@ -6192,13 +7802,14 @@ describe('plugin-meetings', () => {
6192
7802
  sinon.stub(meeting.locusMediaRequest, 'downgradeFromMultistreamToTranscoded');
6193
7803
  });
6194
7804
 
6195
- const runCheck = async (turnServerInfo, forceTurnDiscovery) => {
7805
+ const runCheck = async (turnServerInfo, forceTurnDiscovery, iceTransportPolicy) => {
6196
7806
  // we're calling addMediaInternal() with mic stream,
6197
7807
  // so that we also verify that audioMute, videoMute info is correctly sent to backend
6198
7808
  const addMediaPromise = meeting.addMediaInternal(
6199
7809
  () => '',
6200
- turnServerInfo,
6201
7810
  forceTurnDiscovery,
7811
+ turnServerInfo,
7812
+ iceTransportPolicy,
6202
7813
  {
6203
7814
  localStreams: {microphone: fakeMicrophoneStream},
6204
7815
  }
@@ -6252,6 +7863,10 @@ describe('plugin-meetings', () => {
6252
7863
  // at this point the meeting should have been downgraded to transcoded
6253
7864
  assert.equal(meeting.isMultistream, false);
6254
7865
 
7866
+ // iceTransportPolicy must be reset to undefined on downgrade to transcoded,
7867
+ // otherwise the transcoded retry could gather direct candidates while metrics report relay
7868
+ assert.isUndefined(meeting.addMediaData.iceTransportPolicy);
7869
+
6255
7870
  // old stats analyzer stopped and new one created
6256
7871
  assert.calledOnce(initialStatsAnalyzer.stopAnalyzer);
6257
7872
  assert.calledOnceWithExactly(
@@ -6342,6 +7957,11 @@ describe('plugin-meetings', () => {
6342
7957
  true
6343
7958
  );
6344
7959
  });
7960
+
7961
+ it('resets iceTransportPolicy to undefined when falling back from multistream (relay) to transcoded', async () => {
7962
+ // simulate a relay-only retry falling back to transcoded and verify iceTransportPolicy is reset
7963
+ await runCheck(undefined, false, 'relay');
7964
+ });
6345
7965
  });
6346
7966
  }
6347
7967
  })
@@ -6429,6 +8049,9 @@ describe('plugin-meetings', () => {
6429
8049
 
6430
8050
  meeting.annotation.deregisterEvents = sinon.stub();
6431
8051
  webex.internal.llm.off = sinon.stub();
8052
+ webex.internal.mercury.off = sinon.stub();
8053
+ meeting.mercuryOnlineHandler = sinon.stub();
8054
+ meeting.mercuryOfflineHandler = sinon.stub();
6432
8055
 
6433
8056
  // A meeting needs to be joined to leave
6434
8057
  meeting.meetingState = 'ACTIVE';
@@ -6452,6 +8075,67 @@ describe('plugin-meetings', () => {
6452
8075
  assert.calledOnce(meeting.clearMeetingData);
6453
8076
  });
6454
8077
 
8078
+ it('stops listening for LLM/Mercury and tears down transcription and annotation before calling Locus /leave', async () => {
8079
+ const onlineHandler = meeting.mercuryOnlineHandler;
8080
+ const offlineHandler = meeting.mercuryOfflineHandler;
8081
+
8082
+ await meeting.leave();
8083
+
8084
+ // All llm/mercury consumers (direct listeners, voicea transcription,
8085
+ // annotation) must be detached before the /leave request so that
8086
+ // in-flight events do not trigger unnecessary Locus syncs
8087
+ // (per Locus team recommendation).
8088
+ assert.callOrder(
8089
+ webex.internal.llm.off,
8090
+ webex.internal.mercury.off,
8091
+ meeting.stopTranscription,
8092
+ meeting.annotation.deregisterEvents,
8093
+ meeting.meetingRequest.leaveMeeting
8094
+ );
8095
+ assert.calledWithExactly(
8096
+ webex.internal.llm.off,
8097
+ 'event:relay.event',
8098
+ meeting.processRelayEvent
8099
+ );
8100
+ assert.calledWithExactly(
8101
+ webex.internal.llm.off,
8102
+ LOCUS_LLM_EVENT,
8103
+ meeting.processLocusLLMEvent
8104
+ );
8105
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
8106
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
8107
+ assert.isUndefined(meeting.mercuryOnlineHandler);
8108
+ assert.isUndefined(meeting.mercuryOfflineHandler);
8109
+ assert.calledOnceWithExactly(meeting.stopTranscription);
8110
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
8111
+ assert.isUndefined(meeting.transcription);
8112
+ });
8113
+
8114
+ it('tears down llm/mercury/transcription/annotation even when /leave rejects', async () => {
8115
+ const onlineHandler = meeting.mercuryOnlineHandler;
8116
+ const offlineHandler = meeting.mercuryOfflineHandler;
8117
+ meeting.meetingRequest.leaveMeeting = sinon
8118
+ .stub()
8119
+ .returns(Promise.reject(new Error('leave failed')));
8120
+
8121
+ await meeting.leave().catch(() => {});
8122
+
8123
+ assert.calledWithExactly(
8124
+ webex.internal.llm.off,
8125
+ 'event:relay.event',
8126
+ meeting.processRelayEvent
8127
+ );
8128
+ assert.calledWithExactly(
8129
+ webex.internal.llm.off,
8130
+ LOCUS_LLM_EVENT,
8131
+ meeting.processLocusLLMEvent
8132
+ );
8133
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
8134
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
8135
+ assert.calledOnceWithExactly(meeting.stopTranscription);
8136
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
8137
+ });
8138
+
6455
8139
  it('should reset call diagnostic latencies correctly', async () => {
6456
8140
  const leave = meeting.leave();
6457
8141
 
@@ -8459,6 +10143,9 @@ describe('plugin-meetings', () => {
8459
10143
 
8460
10144
  meeting.annotation.deregisterEvents = sinon.stub();
8461
10145
  webex.internal.llm.off = sinon.stub();
10146
+ webex.internal.mercury.off = sinon.stub();
10147
+ meeting.mercuryOnlineHandler = sinon.stub();
10148
+ meeting.mercuryOfflineHandler = sinon.stub();
8462
10149
 
8463
10150
  // A meeting needs to be joined to end
8464
10151
  meeting.meetingState = 'ACTIVE';
@@ -8481,6 +10168,66 @@ describe('plugin-meetings', () => {
8481
10168
  assert.calledOnce(meeting?.unsetPeerConnections);
8482
10169
  assert.calledOnce(meeting?.clearMeetingData);
8483
10170
  });
10171
+
10172
+ it('stops listening for LLM/Mercury and tears down transcription and annotation before calling Locus /end', async () => {
10173
+ const onlineHandler = meeting.mercuryOnlineHandler;
10174
+ const offlineHandler = meeting.mercuryOfflineHandler;
10175
+
10176
+ await meeting.endMeetingForAll();
10177
+
10178
+ // All llm/mercury consumers (direct listeners, voicea transcription,
10179
+ // annotation) must be detached before the /end request so that
10180
+ // in-flight events do not trigger unnecessary Locus syncs
10181
+ // (per Locus team recommendation).
10182
+ assert.callOrder(
10183
+ webex.internal.llm.off,
10184
+ webex.internal.mercury.off,
10185
+ meeting.stopTranscription,
10186
+ meeting.annotation.deregisterEvents,
10187
+ meeting.meetingRequest.endMeetingForAll
10188
+ );
10189
+ assert.calledWithExactly(
10190
+ webex.internal.llm.off,
10191
+ 'event:relay.event',
10192
+ meeting.processRelayEvent
10193
+ );
10194
+ assert.calledWithExactly(
10195
+ webex.internal.llm.off,
10196
+ LOCUS_LLM_EVENT,
10197
+ meeting.processLocusLLMEvent
10198
+ );
10199
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
10200
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
10201
+ assert.isUndefined(meeting.mercuryOnlineHandler);
10202
+ assert.isUndefined(meeting.mercuryOfflineHandler);
10203
+ assert.calledOnceWithExactly(meeting.stopTranscription);
10204
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
10205
+ });
10206
+
10207
+ it('tears down llm/mercury/transcription/annotation even when /end rejects', async () => {
10208
+ const onlineHandler = meeting.mercuryOnlineHandler;
10209
+ const offlineHandler = meeting.mercuryOfflineHandler;
10210
+ meeting.meetingRequest.endMeetingForAll = sinon
10211
+ .stub()
10212
+ .returns(Promise.reject(new Error('end failed')));
10213
+
10214
+ await meeting.endMeetingForAll().catch(() => {});
10215
+
10216
+ assert.calledWithExactly(
10217
+ webex.internal.llm.off,
10218
+ 'event:relay.event',
10219
+ meeting.processRelayEvent
10220
+ );
10221
+ assert.calledWithExactly(
10222
+ webex.internal.llm.off,
10223
+ LOCUS_LLM_EVENT,
10224
+ meeting.processLocusLLMEvent
10225
+ );
10226
+ assert.calledWithExactly(webex.internal.mercury.off, ONLINE, onlineHandler);
10227
+ assert.calledWithExactly(webex.internal.mercury.off, OFFLINE, offlineHandler);
10228
+ assert.calledOnceWithExactly(meeting.stopTranscription);
10229
+ assert.calledOnceWithExactly(meeting.annotation.deregisterEvents);
10230
+ });
8484
10231
  });
8485
10232
 
8486
10233
  describe('#moveTo', () => {
@@ -9262,7 +11009,9 @@ describe('plugin-meetings', () => {
9262
11009
  MediaCodecMimeType.OPUS,
9263
11010
  ['maxaveragebitrate', 'maxplaybackrate']
9264
11011
  );
9265
- assert.notCalled(meeting.sendSlotManager.getSlot(MediaType.AudioMain).setCustomCodecParameters);
11012
+ assert.notCalled(
11013
+ meeting.sendSlotManager.getSlot(MediaType.AudioMain).setCustomCodecParameters
11014
+ );
9266
11015
  });
9267
11016
  });
9268
11017
 
@@ -9990,6 +11739,8 @@ describe('plugin-meetings', () => {
9990
11739
  });
9991
11740
 
9992
11741
  it('handles REMOTE_SDP_ANSWER_PROCESSED correctly', () => {
11742
+ // capture the start timestamp before any fake timers are installed
11743
+ const localSdpGeneratedTimestamp = Date.now() - 100;
9993
11744
  const clock = sinon.useFakeTimers();
9994
11745
  sinon.spy(clock, 'clearTimeout');
9995
11746
  meeting.deferSDPAnswer = {
@@ -9997,24 +11748,29 @@ describe('plugin-meetings', () => {
9997
11748
  };
9998
11749
  meeting.sdpResponseTimer = '1234';
9999
11750
 
11751
+ // latency is computed as Date.now() - the stored local-sdp-generated timestamp,
11752
+ // so it is unaffected by any earlier remote-sdp-received timestamp saved on timeout
11753
+ webex.internal.newMetrics.callDiagnosticLatencies.latencyTimestamps = new Map([
11754
+ ['client.media-engine.local-sdp-generated', localSdpGeneratedTimestamp],
11755
+ ]);
11756
+
10000
11757
  eventListeners[MediaConnectionEventNames.REMOTE_SDP_ANSWER_PROCESSED]();
10001
11758
 
10002
11759
  assert.calledOnce(webex.internal.newMetrics.submitClientEvent);
10003
11760
  assert.calledWithMatch(webex.internal.newMetrics.submitClientEvent, {
10004
11761
  name: 'client.media-engine.remote-sdp-received',
11762
+ payload: {
11763
+ eventData: {
11764
+ localSDPGenRemoteSDPRecv: sinon.match(
11765
+ (value) => typeof value === 'number' && value >= 100 && value < 5000
11766
+ ),
11767
+ },
11768
+ },
10005
11769
  options: {meetingId: meeting.id},
10006
11770
  });
10007
11771
 
10008
- assert.calledOnce(Metrics.sendBehavioralMetric);
10009
- assert.calledWith(
10010
- Metrics.sendBehavioralMetric,
10011
- BEHAVIORAL_METRICS.ROAP_OFFER_TO_ANSWER_LATENCY,
10012
- {
10013
- correlation_id: meeting.correlationId,
10014
- meetingId: meeting.id,
10015
- latency: undefined,
10016
- }
10017
- );
11772
+ // the high-volume ROAP_OFFER_TO_ANSWER_LATENCY behavioral metric is no longer sent
11773
+ assert.notCalled(Metrics.sendBehavioralMetric);
10018
11774
 
10019
11775
  assert.calledOnce(meeting.deferSDPAnswer.resolve);
10020
11776
  assert.calledOnce(clock.clearTimeout);
@@ -10022,6 +11778,28 @@ describe('plugin-meetings', () => {
10022
11778
  assert.equal(meeting.sdpResponseTimer, undefined);
10023
11779
  });
10024
11780
 
11781
+ it('sends undefined localSDPGenRemoteSDPRecv when the local-sdp-generated timestamp is missing', () => {
11782
+ meeting.deferSDPAnswer = {
11783
+ resolve: sinon.stub(),
11784
+ };
11785
+
11786
+ // no local-sdp-generated timestamp stored -> latency cannot be computed
11787
+ webex.internal.newMetrics.callDiagnosticLatencies.latencyTimestamps = new Map();
11788
+
11789
+ eventListeners[MediaConnectionEventNames.REMOTE_SDP_ANSWER_PROCESSED]();
11790
+
11791
+ assert.calledOnce(webex.internal.newMetrics.submitClientEvent);
11792
+ assert.calledWithMatch(webex.internal.newMetrics.submitClientEvent, {
11793
+ name: 'client.media-engine.remote-sdp-received',
11794
+ payload: {
11795
+ eventData: {
11796
+ localSDPGenRemoteSDPRecv: undefined,
11797
+ },
11798
+ },
11799
+ options: {meetingId: meeting.id},
11800
+ });
11801
+ });
11802
+
10025
11803
  it('handles LOCAL_SDP_OFFER_GENERATED correctly', () => {
10026
11804
  assert.equal(meeting.deferSDPAnswer, undefined);
10027
11805
 
@@ -10417,16 +12195,16 @@ describe('plugin-meetings', () => {
10417
12195
  );
10418
12196
  done();
10419
12197
  });
10420
- it('listens to the self admitted guest event without blocking on token prefetch', async () => {
12198
+ it('listens to the self admitted guest event and waits for token prefetch before reconnecting LLM', async () => {
10421
12199
  meeting.stopKeepAlive = sinon.stub();
10422
12200
  meeting.updateLLMConnection = sinon.stub();
10423
12201
  let resolvePrefetch;
10424
12202
 
10425
- meeting.ensureDefaultDatachannelTokenAfterAdmit = sinon
10426
- .stub()
10427
- .returns(new Promise((resolve) => {
12203
+ meeting.ensureDefaultDatachannelTokenAfterAdmit = sinon.stub().returns(
12204
+ new Promise((resolve) => {
10428
12205
  resolvePrefetch = resolve;
10429
- }));
12206
+ })
12207
+ );
10430
12208
  meeting.rtcMetrics = {
10431
12209
  sendNextMetrics: sinon.stub(),
10432
12210
  };
@@ -10443,7 +12221,7 @@ describe('plugin-meetings', () => {
10443
12221
  'meeting:self:guestAdmitted',
10444
12222
  {payload: test1}
10445
12223
  );
10446
- assert.calledOnce(meeting.updateLLMConnection);
12224
+ assert.notCalled(meeting.updateLLMConnection);
10447
12225
  assert.calledOnceWithExactly(meeting.rtcMetrics.sendNextMetrics);
10448
12226
 
10449
12227
  assert.calledOnceWithExactly(
@@ -10456,6 +12234,7 @@ describe('plugin-meetings', () => {
10456
12234
 
10457
12235
  resolvePrefetch(false);
10458
12236
  await Promise.resolve();
12237
+ await Promise.resolve();
10459
12238
 
10460
12239
  assert.calledOnce(meeting.updateLLMConnection);
10461
12240
  });
@@ -10971,6 +12750,106 @@ describe('plugin-meetings', () => {
10971
12750
  );
10972
12751
  });
10973
12752
 
12753
+ const recordingTestCases = [
12754
+ {
12755
+ description: 'triggers MEETING_STARTED_RECORDING when state is RECORDING',
12756
+ state: RECORDING_STATE.RECORDING,
12757
+ expectedEvent: EVENT_TRIGGERS.MEETING_STARTED_RECORDING,
12758
+ expectedRecordingState: RECORDING_STATE.RECORDING,
12759
+ },
12760
+ {
12761
+ description: 'triggers MEETING_STOPPED_RECORDING when state is IDLE',
12762
+ state: RECORDING_STATE.IDLE,
12763
+ expectedEvent: EVENT_TRIGGERS.MEETING_STOPPED_RECORDING,
12764
+ expectedRecordingState: RECORDING_STATE.IDLE,
12765
+ },
12766
+ {
12767
+ description: 'triggers MEETING_PAUSED_RECORDING when state is PAUSED',
12768
+ state: RECORDING_STATE.PAUSED,
12769
+ expectedEvent: EVENT_TRIGGERS.MEETING_PAUSED_RECORDING,
12770
+ expectedRecordingState: RECORDING_STATE.PAUSED,
12771
+ },
12772
+ {
12773
+ description:
12774
+ 'triggers MEETING_RESUMED_RECORDING and sets state to RECORDING when state is RESUMED',
12775
+ state: RECORDING_STATE.RESUMED,
12776
+ expectedEvent: EVENT_TRIGGERS.MEETING_RESUMED_RECORDING,
12777
+ expectedRecordingState: RECORDING_STATE.RECORDING,
12778
+ },
12779
+ ];
12780
+
12781
+ recordingTestCases.forEach(
12782
+ ({description, state, expectedEvent, expectedRecordingState}) => {
12783
+ it(`listens to CONTROLS_RECORDING_UPDATED - ${description}`, async () => {
12784
+ const modifiedBy = 'user-id-123';
12785
+ const lastModified = '2026-01-01T00:00:00Z';
12786
+
12787
+ await meeting.locusInfo.emitScoped(
12788
+ {function: 'test', file: 'test'},
12789
+ LOCUSINFO.EVENTS.CONTROLS_RECORDING_UPDATED,
12790
+ {
12791
+ state,
12792
+ modifiedBy,
12793
+ lastModified,
12794
+ modifiedByServiceAppName: undefined,
12795
+ modifiedByServiceAppId: undefined,
12796
+ }
12797
+ );
12798
+
12799
+ assert.deepEqual(meeting.recording, {
12800
+ state: expectedRecordingState,
12801
+ modifiedBy,
12802
+ lastModified,
12803
+ modifiedByServiceAppName: undefined,
12804
+ modifiedByServiceAppId: undefined,
12805
+ });
12806
+
12807
+ assert.calledWith(
12808
+ TriggerProxy.trigger,
12809
+ meeting,
12810
+ {file: 'meeting/index', function: 'setupLocusControlsListener'},
12811
+ expectedEvent,
12812
+ meeting.recording
12813
+ );
12814
+ });
12815
+ }
12816
+ );
12817
+
12818
+ it('listens to CONTROLS_RECORDING_UPDATED and includes modifiedByServiceAppName and modifiedByServiceAppId when present', async () => {
12819
+ const modifiedBy = 'user-id-123';
12820
+ const lastModified = '2026-01-01T00:00:00Z';
12821
+ const modifiedByServiceAppName = 'My Bot';
12822
+ const modifiedByServiceAppId = 'app-id-123';
12823
+
12824
+ await meeting.locusInfo.emitScoped(
12825
+ {function: 'test', file: 'test'},
12826
+ LOCUSINFO.EVENTS.CONTROLS_RECORDING_UPDATED,
12827
+ {
12828
+ state: RECORDING_STATE.RECORDING,
12829
+ modifiedBy,
12830
+ lastModified,
12831
+ modifiedByServiceAppName,
12832
+ modifiedByServiceAppId,
12833
+ }
12834
+ );
12835
+
12836
+ assert.deepEqual(meeting.recording, {
12837
+ state: RECORDING_STATE.RECORDING,
12838
+ modifiedBy,
12839
+ lastModified,
12840
+ modifiedByServiceAppName,
12841
+ modifiedByServiceAppId,
12842
+ });
12843
+
12844
+ assert.calledWith(
12845
+ TriggerProxy.trigger,
12846
+ meeting,
12847
+ {file: 'meeting/index', function: 'setupLocusControlsListener'},
12848
+ EVENT_TRIGGERS.MEETING_STARTED_RECORDING,
12849
+ meeting.recording
12850
+ );
12851
+ });
12852
+
10974
12853
  it('listens to the locus interpretation update event', () => {
10975
12854
  const interpretation = {
10976
12855
  siLanguages: [{languageCode: 20, languageName: 'en'}],
@@ -11024,6 +12903,7 @@ describe('plugin-meetings', () => {
11024
12903
  meeting.annotation.locusUrlUpdate = sinon.stub();
11025
12904
  meeting.simultaneousInterpretation.locusUrlUpdate = sinon.stub();
11026
12905
  meeting.webinar.locusUrlUpdate = sinon.stub();
12906
+ meeting.aiEnableRequest.locusUrlUpdate = sinon.stub();
11027
12907
 
11028
12908
  meeting.locusInfo.emit(
11029
12909
  {function: 'test', file: 'test'},
@@ -11038,6 +12918,7 @@ describe('plugin-meetings', () => {
11038
12918
  assert.calledWith(meeting.controlsOptionsManager.setLocusUrl, newLocusUrl, false);
11039
12919
  assert.calledWith(meeting.simultaneousInterpretation.locusUrlUpdate, newLocusUrl);
11040
12920
  assert.calledWith(meeting.webinar.locusUrlUpdate, newLocusUrl);
12921
+ assert.calledWith(meeting.aiEnableRequest.locusUrlUpdate, newLocusUrl);
11041
12922
  assert.equal(meeting.locusUrl, newLocusUrl);
11042
12923
  assert(meeting.locusId, '12345');
11043
12924
 
@@ -11353,6 +13234,109 @@ describe('plugin-meetings', () => {
11353
13234
  });
11354
13235
  });
11355
13236
 
13237
+ describe('#finalizeMeetingAfterInitialLocusSetup', () => {
13238
+ it('refreshes destination from synced locus when destination type is LOCUS_ID', () => {
13239
+ const syncedLocus = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13240
+
13241
+ meeting.destinationType = DESTINATION_TYPE.LOCUS_ID;
13242
+ meeting.destination = {info: {topic: 'old'}};
13243
+
13244
+ meeting.finalizeMeetingAfterInitialLocusSetup(syncedLocus);
13245
+
13246
+ assert.equal(meeting.destination, syncedLocus);
13247
+ });
13248
+
13249
+ it('does not refresh destination when destination type is not LOCUS_ID', () => {
13250
+ const syncedLocus = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13251
+ const originalDestination = {destination: 'original-destination'};
13252
+
13253
+ meeting.destinationType = DESTINATION_TYPE.CONVERSATION_URL;
13254
+ meeting.destination = originalDestination;
13255
+
13256
+ meeting.finalizeMeetingAfterInitialLocusSetup(syncedLocus);
13257
+
13258
+ assert.equal(meeting.destination, originalDestination);
13259
+ });
13260
+
13261
+ it('fetches meeting info when meetingInfo is empty and destination has info', () => {
13262
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13263
+
13264
+ meeting.meetingInfo = {};
13265
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13266
+
13267
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13268
+
13269
+ assert.calledOnceWithExactly(fetchMeetingInfoStub, {});
13270
+ });
13271
+
13272
+ it('does not fetch meeting info when destination has no info', () => {
13273
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13274
+
13275
+ meeting.meetingInfo = {};
13276
+ meeting.destination = {url: 'https://locus.example.com/locus/123'};
13277
+
13278
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13279
+
13280
+ assert.notCalled(fetchMeetingInfoStub);
13281
+ });
13282
+
13283
+ it('does not fetch meeting info when meetingInfo is already populated', () => {
13284
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13285
+
13286
+ meeting.meetingInfo = {meetingJoinUrl: 'https://example.com/join/abc'};
13287
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13288
+
13289
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13290
+
13291
+ assert.notCalled(fetchMeetingInfoStub);
13292
+ });
13293
+
13294
+ it('does not fetch meeting info when delayed fetch timer is already scheduled', () => {
13295
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13296
+
13297
+ meeting.meetingInfo = {};
13298
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13299
+ meeting.fetchMeetingInfoTimeoutId = 42;
13300
+
13301
+ meeting.finalizeMeetingAfterInitialLocusSetup({});
13302
+
13303
+ assert.notCalled(fetchMeetingInfoStub);
13304
+ });
13305
+
13306
+ ['CALL', 'SIP_BRIDGE', 'SPACE_SHARE'].forEach((fullStateType) => {
13307
+ it(`does not fetch meeting info when destination is a 1:1 call (fullState.type ${fullStateType})`, () => {
13308
+ const fetchMeetingInfoStub = sinon.stub(meeting, 'fetchMeetingInfo').resolves();
13309
+
13310
+ meeting.meetingInfo = {};
13311
+ meeting.destination = {
13312
+ url: 'https://locus.example.com/locus/123',
13313
+ info: {topic: 'x'},
13314
+ };
13315
+
13316
+ meeting.finalizeMeetingAfterInitialLocusSetup({fullState: {type: fullStateType}});
13317
+
13318
+ assert.notCalled(fetchMeetingInfoStub);
13319
+ });
13320
+ });
13321
+
13322
+ it('swallows async fetchMeetingInfo errors and logs info', async () => {
13323
+ const error = new Error('fetch failed');
13324
+
13325
+ meeting.meetingInfo = {};
13326
+ meeting.destination = {url: 'https://locus.example.com/locus/123', info: {topic: 'x'}};
13327
+ sinon.stub(meeting, 'fetchMeetingInfo').returns(Promise.reject(error));
13328
+ const loggerInfoStub = sinon.stub(LoggerProxy.logger, 'info');
13329
+
13330
+ await meeting.finalizeMeetingAfterInitialLocusSetup({});
13331
+
13332
+ assert.calledOnce(loggerInfoStub);
13333
+ assert.match(
13334
+ loggerInfoStub.firstCall.args[0],
13335
+ /Meeting:index#finalizeMeetingAfterInitialLocusSetup --> deferred fetchMeetingInfo failed: fetch failed/
13336
+ );
13337
+ });
13338
+ });
13339
+
11356
13340
  describe('#emailInput', () => {
11357
13341
  it('should set the email input', () => {
11358
13342
  assert.notOk(meeting.emailInput);
@@ -11955,6 +13939,7 @@ describe('plugin-meetings', () => {
11955
13939
  let showAutoEndMeetingWarningSpy;
11956
13940
  let canAttendeeRequestAiAssistantEnabledSpy;
11957
13941
  let attendeeRequestAiAssistantDeclinedAllSpy;
13942
+ let isAnonymizeDisplayNamesEnabledSpy;
11958
13943
  // Due to import tree issues, hasHints must be stubed within the scope of the `it`.
11959
13944
 
11960
13945
  beforeEach(() => {
@@ -12003,6 +13988,10 @@ describe('plugin-meetings', () => {
12003
13988
  MeetingUtil,
12004
13989
  'attendeeRequestAiAssistantDeclinedAll'
12005
13990
  );
13991
+ isAnonymizeDisplayNamesEnabledSpy = sinon.spy(
13992
+ MeetingUtil,
13993
+ 'isAnonymizeDisplayNamesEnabled'
13994
+ );
12006
13995
  });
12007
13996
 
12008
13997
  afterEach(() => {
@@ -12011,6 +14000,7 @@ describe('plugin-meetings', () => {
12011
14000
  showAutoEndMeetingWarningSpy.restore();
12012
14001
  canAttendeeRequestAiAssistantEnabledSpy.restore();
12013
14002
  attendeeRequestAiAssistantDeclinedAllSpy.restore();
14003
+ isAnonymizeDisplayNamesEnabledSpy.restore();
12014
14004
  });
12015
14005
 
12016
14006
  forEach(
@@ -12568,6 +14558,7 @@ describe('plugin-meetings', () => {
12568
14558
  meeting.roles
12569
14559
  );
12570
14560
  assert.calledWith(attendeeRequestAiAssistantDeclinedAllSpy, userDisplayHints);
14561
+ assert.calledWith(isAnonymizeDisplayNamesEnabledSpy, userDisplayHints);
12571
14562
 
12572
14563
  assert.calledWith(ControlsOptionsUtil.hasHints, {
12573
14564
  requiredHints: [DISPLAY_HINTS.MUTE_ALL],
@@ -12782,6 +14773,10 @@ describe('plugin-meetings', () => {
12782
14773
  describe('#saveDataChannelToken', () => {
12783
14774
  beforeEach(() => {
12784
14775
  webex.internal.llm.setDatachannelToken = sinon.stub();
14776
+ webex.internal.llm.resolveSessionOwnership = sinon
14777
+ .stub()
14778
+ .returns({currentOwner: undefined, isOwner: true});
14779
+ webex.internal.llm.isConnected = sinon.stub().returns(false);
12785
14780
  });
12786
14781
 
12787
14782
  it('saves datachannelToken into LLM as Default', () => {
@@ -12794,7 +14789,8 @@ describe('plugin-meetings', () => {
12794
14789
  assert.calledWithExactly(
12795
14790
  webex.internal.llm.setDatachannelToken,
12796
14791
  'default-token',
12797
- 'llm-default-session'
14792
+ 'llm-default-session',
14793
+ meeting.id
12798
14794
  );
12799
14795
  });
12800
14796
 
@@ -12808,7 +14804,8 @@ describe('plugin-meetings', () => {
12808
14804
  assert.calledWithExactly(
12809
14805
  webex.internal.llm.setDatachannelToken,
12810
14806
  'ps-token',
12811
- 'llm-practice-session'
14807
+ 'llm-practice-session',
14808
+ meeting.id
12812
14809
  );
12813
14810
  });
12814
14811
 
@@ -12826,12 +14823,14 @@ describe('plugin-meetings', () => {
12826
14823
  assert.calledWithExactly(
12827
14824
  webex.internal.llm.setDatachannelToken,
12828
14825
  'default-token',
12829
- 'llm-default-session'
14826
+ 'llm-default-session',
14827
+ meeting.id
12830
14828
  );
12831
14829
  assert.calledWithExactly(
12832
14830
  webex.internal.llm.setDatachannelToken,
12833
14831
  'ps-token',
12834
- 'llm-practice-session'
14832
+ 'llm-practice-session',
14833
+ meeting.id
12835
14834
  );
12836
14835
  });
12837
14836
 
@@ -12850,19 +14849,44 @@ describe('plugin-meetings', () => {
12850
14849
  it('handles missing locus.self gracefully', () => {
12851
14850
  meeting.saveDataChannelToken({locus: {}});
12852
14851
 
12853
- assert.notCalled(webex.internal.llm.setDatachannelToken);
14852
+ assert.notCalled(webex.internal.llm.setDatachannelToken);
14853
+ });
14854
+
14855
+ it('writes token with meeting id as owner', () => {
14856
+ meeting.saveDataChannelToken({
14857
+ locus: {
14858
+ self: {datachannelToken: 'default-token'},
14859
+ },
14860
+ });
14861
+
14862
+ assert.calledOnceWithExactly(
14863
+ webex.internal.llm.setDatachannelToken,
14864
+ 'default-token',
14865
+ 'llm-default-session',
14866
+ meeting.id
14867
+ );
12854
14868
  });
12855
14869
  });
12856
14870
 
12857
14871
  describe('#clearDataChannelToken', () => {
12858
14872
  beforeEach(() => {
12859
- webex.internal.llm.resetDatachannelTokens = sinon.stub();
14873
+ webex.internal.llm.clearDatachannelToken = sinon.stub();
12860
14874
  });
12861
14875
 
12862
- it('calls resetDatachannelTokens on LLM', () => {
14876
+ it('delegates default and practice token clears to llm with meeting ownership id', () => {
12863
14877
  meeting.clearDataChannelToken();
12864
14878
 
12865
- assert.calledOnce(webex.internal.llm.resetDatachannelTokens);
14879
+ assert.calledWithExactly(
14880
+ webex.internal.llm.clearDatachannelToken,
14881
+ 'llm-default-session',
14882
+ meeting.id
14883
+ );
14884
+ assert.calledWithExactly(
14885
+ webex.internal.llm.clearDatachannelToken,
14886
+ 'llm-practice-session',
14887
+ meeting.id
14888
+ );
14889
+ assert.callCount(webex.internal.llm.clearDatachannelToken, 2);
12866
14890
  });
12867
14891
  });
12868
14892
 
@@ -12872,6 +14896,7 @@ describe('plugin-meetings', () => {
12872
14896
  webex.internal.llm.getLocusUrl = sinon.stub();
12873
14897
  webex.internal.llm.getDatachannelUrl = sinon.stub();
12874
14898
  webex.internal.llm.registerAndConnect = sinon.stub().resolves('something');
14899
+ webex.internal.llm.setRefreshHandler = sinon.stub();
12875
14900
  webex.internal.llm.disconnectLLM = sinon.stub().resolves();
12876
14901
  webex.internal.llm.on = sinon.stub();
12877
14902
  webex.internal.llm.off = sinon.stub();
@@ -12889,7 +14914,11 @@ describe('plugin-meetings', () => {
12889
14914
  meeting.joinedWith = {state: 'any other state'};
12890
14915
  webex.internal.llm.getLocusUrl.returns('a url');
12891
14916
 
12892
- meeting.locusInfo = {url: 'a url', info: {datachannelUrl: 'a datachannel url'}};
14917
+ meeting.locusInfo = {
14918
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
14919
+ url: 'a url',
14920
+ info: {datachannelUrl: 'a datachannel url'},
14921
+ };
12893
14922
 
12894
14923
  const result = await meeting.updateLLMConnection();
12895
14924
 
@@ -12901,6 +14930,7 @@ describe('plugin-meetings', () => {
12901
14930
  it('returns undefined if llm is already connected and the locus url is unchanged', async () => {
12902
14931
  meeting.joinedWith = {state: 'JOINED'};
12903
14932
  meeting.locusInfo = {
14933
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
12904
14934
  url: 'a url',
12905
14935
  info: {datachannelUrl: 'a datachannel url'},
12906
14936
  };
@@ -12937,7 +14967,11 @@ describe('plugin-meetings', () => {
12937
14967
  });
12938
14968
  it('connects if not already connected', async () => {
12939
14969
  meeting.joinedWith = {state: 'JOINED'};
12940
- meeting.locusInfo = {url: 'a url', info: {datachannelUrl: 'a datachannel url'}};
14970
+ meeting.locusInfo = {
14971
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
14972
+ url: 'a url',
14973
+ info: {datachannelUrl: 'a datachannel url'},
14974
+ };
12941
14975
 
12942
14976
  const result = await meeting.updateLLMConnection();
12943
14977
 
@@ -12948,7 +14982,14 @@ describe('plugin-meetings', () => {
12948
14982
  'a datachannel url',
12949
14983
  undefined
12950
14984
  );
14985
+ assert.calledOnceWithExactly(
14986
+ webex.internal.llm.setRefreshHandler,
14987
+ sinon.match.func,
14988
+ 'llm-default-session',
14989
+ meeting.id
14990
+ );
12951
14991
  assert.equal(result, 'something');
14992
+ assert.calledOnceWithExactly(meeting.locusInfo.syncAllHashTreeDatasets, {onlyLLM: true});
12952
14993
  });
12953
14994
  it('disconnects if the locus url has changed', async () => {
12954
14995
  meeting.joinedWith = {state: 'JOINED'};
@@ -12957,6 +14998,7 @@ describe('plugin-meetings', () => {
12957
14998
  webex.internal.llm.getLocusUrl.returns('a url');
12958
14999
 
12959
15000
  meeting.locusInfo = {
15001
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
12960
15002
  url: 'a different url',
12961
15003
  info: {datachannelUrl: 'a datachannel url'},
12962
15004
  self: {},
@@ -12964,10 +15006,15 @@ describe('plugin-meetings', () => {
12964
15006
 
12965
15007
  const result = await meeting.updateLLMConnection();
12966
15008
 
12967
- assert.calledWithExactly(webex.internal.llm.disconnectLLM, {
12968
- code: 3050,
12969
- reason: 'done (permanent)',
12970
- });
15009
+ assert.calledWithExactly(
15010
+ webex.internal.llm.disconnectLLM,
15011
+ {
15012
+ code: 3050,
15013
+ reason: 'done (permanent)',
15014
+ },
15015
+ 'llm-default-session',
15016
+ meeting.id
15017
+ );
12971
15018
 
12972
15019
  assert.calledWithExactly(
12973
15020
  webex.internal.llm.registerAndConnect,
@@ -13010,6 +15057,7 @@ describe('plugin-meetings', () => {
13010
15057
  webex.internal.llm.getLocusUrl.returns('a url');
13011
15058
 
13012
15059
  meeting.locusInfo = {
15060
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13013
15061
  url: 'a url',
13014
15062
  info: {datachannelUrl: 'a different datachannel url'},
13015
15063
  self: {},
@@ -13017,10 +15065,15 @@ describe('plugin-meetings', () => {
13017
15065
 
13018
15066
  const result = await meeting.updateLLMConnection();
13019
15067
 
13020
- assert.calledWithExactly(webex.internal.llm.disconnectLLM, {
13021
- code: 3050,
13022
- reason: 'done (permanent)',
13023
- });
15068
+ assert.calledWithExactly(
15069
+ webex.internal.llm.disconnectLLM,
15070
+ {
15071
+ code: 3050,
15072
+ reason: 'done (permanent)',
15073
+ },
15074
+ 'llm-default-session',
15075
+ meeting.id
15076
+ );
13024
15077
 
13025
15078
  assert.calledWithExactly(
13026
15079
  webex.internal.llm.registerAndConnect,
@@ -13061,14 +15114,23 @@ describe('plugin-meetings', () => {
13061
15114
  webex.internal.llm.isConnected.returns(true);
13062
15115
  webex.internal.llm.getLocusUrl.returns('a url');
13063
15116
 
13064
- meeting.locusInfo = {url: 'a url', info: {datachannelUrl: 'a datachannel url'}};
15117
+ meeting.locusInfo = {
15118
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15119
+ url: 'a url',
15120
+ info: {datachannelUrl: 'a datachannel url'},
15121
+ };
13065
15122
 
13066
15123
  const result = await meeting.updateLLMConnection();
13067
15124
 
13068
- assert.calledWith(webex.internal.llm.disconnectLLM, {
13069
- code: 3050,
13070
- reason: 'done (permanent)',
13071
- });
15125
+ assert.calledWith(
15126
+ webex.internal.llm.disconnectLLM,
15127
+ {
15128
+ code: 3050,
15129
+ reason: 'done (permanent)',
15130
+ },
15131
+ 'llm-default-session',
15132
+ meeting.id
15133
+ );
13072
15134
  assert.notCalled(webex.internal.llm.registerAndConnect);
13073
15135
  assert.equal(result, undefined);
13074
15136
  assert.isFalse(
@@ -13084,6 +15146,7 @@ describe('plugin-meetings', () => {
13084
15146
  webex.internal.llm.disconnectLLM.rejects(disconnectError);
13085
15147
 
13086
15148
  meeting.locusInfo = {
15149
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13087
15150
  url: 'a different url',
13088
15151
  info: {datachannelUrl: 'a datachannel url'},
13089
15152
  self: {},
@@ -13115,6 +15178,7 @@ describe('plugin-meetings', () => {
13115
15178
  it('still need connect main session data channel when PS started', async () => {
13116
15179
  meeting.joinedWith = {state: 'JOINED'};
13117
15180
  meeting.locusInfo = {
15181
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13118
15182
  url: 'a url',
13119
15183
  info: {
13120
15184
  datachannelUrl: 'a datachannel url',
@@ -13135,11 +15199,14 @@ describe('plugin-meetings', () => {
13135
15199
  it('passes dataChannelToken from LLM to registerAndConnect', async () => {
13136
15200
  meeting.joinedWith = {state: 'JOINED'};
13137
15201
  meeting.locusInfo = {
15202
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13138
15203
  url: 'a url',
13139
15204
  info: {datachannelUrl: 'a datachannel url'},
13140
15205
  };
13141
15206
 
13142
- webex.internal.llm.getDatachannelToken.withArgs('llm-default-session').returns('token-123');
15207
+ webex.internal.llm.getDatachannelToken
15208
+ .withArgs('llm-default-session', meeting.id)
15209
+ .returns('token-123');
13143
15210
 
13144
15211
  await meeting.updateLLMConnection();
13145
15212
 
@@ -13154,6 +15221,7 @@ describe('plugin-meetings', () => {
13154
15221
  it('passes undefined token when LLM has no token stored', async () => {
13155
15222
  meeting.joinedWith = {state: 'JOINED'};
13156
15223
  meeting.locusInfo = {
15224
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13157
15225
  url: 'a url',
13158
15226
  info: {datachannelUrl: 'a datachannel url'},
13159
15227
  };
@@ -13175,6 +15243,7 @@ describe('plugin-meetings', () => {
13175
15243
  it('does not pass token when data channel with jwt token is disabled', async () => {
13176
15244
  meeting.joinedWith = {state: 'JOINED'};
13177
15245
  meeting.locusInfo = {
15246
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
13178
15247
  url: 'a url',
13179
15248
  info: {datachannelUrl: 'a datachannel url'},
13180
15249
  };
@@ -13193,6 +15262,209 @@ describe('plugin-meetings', () => {
13193
15262
  assert.notCalled(webex.internal.llm.setDatachannelToken);
13194
15263
  });
13195
15264
 
15265
+ describe('ownership tag', () => {
15266
+ beforeEach(() => {
15267
+ // Make the owner stub dynamic so setOwnerMeetingId() writes
15268
+ // propagate back to getOwnerMeetingId() reads. This mirrors the
15269
+ // real LLM singleton behavior so the finally-block release in
15270
+ // cleanupLLMConneciton is reflected in subsequent reads.
15271
+ webex.internal.llm.getOwnerMeetingId = sinon.stub().returns(undefined);
15272
+ webex.internal.llm.setOwnerMeetingId = sinon.stub().callsFake((id) => {
15273
+ webex.internal.llm.getOwnerMeetingId.returns(id);
15274
+ });
15275
+ });
15276
+
15277
+ it('skips disconnect and reconnect when LLM is connected and owned by another meeting (regardless of URL)', async () => {
15278
+ meeting.joinedWith = {state: 'JOINED'};
15279
+ webex.internal.llm.isConnected.returns(true);
15280
+ webex.internal.llm.getOwnerMeetingId.returns('some-other-meeting-id');
15281
+ // Locus/datachannel URL mismatch is the *normal* case when
15282
+ // another meeting owns the live socket -- each meeting has its
15283
+ // own locus URL. URL mismatch must NOT trigger a reclaim,
15284
+ // because doing so would tear down the owning meeting's healthy
15285
+ // LLM socket and break its data channel.
15286
+ webex.internal.llm.getLocusUrl.returns('owner-locus-url');
15287
+ webex.internal.llm.getDatachannelUrl.returns('owner-dc-url');
15288
+ meeting.locusInfo = {
15289
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15290
+ url: 'a different url',
15291
+ info: {datachannelUrl: 'a different datachannel url'},
15292
+ self: {},
15293
+ };
15294
+
15295
+ const result = await meeting.updateLLMConnection();
15296
+
15297
+ assert.equal(result, undefined);
15298
+ assert.notCalled(webex.internal.llm.disconnectLLM);
15299
+ assert.notCalled(webex.internal.llm.registerAndConnect);
15300
+ assert.notCalled(webex.internal.llm.setOwnerMeetingId);
15301
+ assert.notCalled(meeting.startLLMHealthCheckTimer);
15302
+ });
15303
+
15304
+ it('clears stale owner tag in cleanup finally block even when disconnectLLM rejects', async () => {
15305
+ meeting.joinedWith = {state: 'JOINED'};
15306
+ webex.internal.llm.isConnected.returns(true);
15307
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15308
+ webex.internal.llm.getLocusUrl.returns('a url');
15309
+ webex.internal.llm.getDatachannelUrl.returns('a datachannel url');
15310
+ webex.internal.llm.disconnectLLM.rejects(new Error('disconnect failed'));
15311
+ meeting.locusInfo = {
15312
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15313
+ url: 'a different url',
15314
+ info: {datachannelUrl: 'a datachannel url'},
15315
+ self: {},
15316
+ };
15317
+
15318
+ try {
15319
+ await meeting.updateLLMConnection();
15320
+ } catch (e) {
15321
+ /* updateLLMConnection may reject when cleanup throws */
15322
+ }
15323
+
15324
+ // The owner-eligible finally branch must release the tag so a
15325
+ // subsequent reconnect attempt from any meeting is not blocked.
15326
+ assert.calledWith(webex.internal.llm.setOwnerMeetingId, undefined);
15327
+ });
15328
+
15329
+ it('does not clear owner tag when ownership changes during cleanup disconnect await', async () => {
15330
+ meeting.joinedWith = {state: 'JOINED'};
15331
+ webex.internal.llm.isConnected.returns(true);
15332
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15333
+ webex.internal.llm.getLocusUrl.returns('a url');
15334
+ webex.internal.llm.getDatachannelUrl.returns('a datachannel url');
15335
+ webex.internal.llm.disconnectLLM.callsFake(async () => {
15336
+ webex.internal.llm.getOwnerMeetingId.returns('new-owner-id');
15337
+ throw new Error('disconnect failed');
15338
+ });
15339
+ meeting.locusInfo = {
15340
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15341
+ url: 'a different url',
15342
+ info: {datachannelUrl: 'a datachannel url'},
15343
+ self: {},
15344
+ };
15345
+
15346
+ try {
15347
+ await meeting.updateLLMConnection();
15348
+ } catch (e) {
15349
+ /* updateLLMConnection may reject when cleanup throws */
15350
+ }
15351
+
15352
+ assert.notCalled(webex.internal.llm.setOwnerMeetingId);
15353
+ assert.equal(webex.internal.llm.getOwnerMeetingId(), 'new-owner-id');
15354
+ });
15355
+
15356
+ it('proceeds normally when LLM is connected and owned by this meeting with URL change', async () => {
15357
+ meeting.joinedWith = {state: 'JOINED'};
15358
+ webex.internal.llm.isConnected.returns(true);
15359
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15360
+ webex.internal.llm.getLocusUrl.returns('a url');
15361
+ webex.internal.llm.getDatachannelUrl.returns('a datachannel url');
15362
+ meeting.locusInfo = {
15363
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15364
+ url: 'a different url',
15365
+ info: {datachannelUrl: 'a datachannel url'},
15366
+ self: {},
15367
+ };
15368
+
15369
+ await meeting.updateLLMConnection();
15370
+
15371
+ assert.calledOnceWithExactly(
15372
+ webex.internal.llm.disconnectLLM,
15373
+ {
15374
+ code: 3050,
15375
+ reason: 'done (permanent)',
15376
+ },
15377
+ 'llm-default-session',
15378
+ meeting.id
15379
+ );
15380
+ assert.calledWithExactly(
15381
+ webex.internal.llm.registerAndConnect,
15382
+ 'a different url',
15383
+ 'a datachannel url',
15384
+ undefined
15385
+ );
15386
+ // setOwnerMeetingId is called twice: first with undefined in
15387
+ // cleanupLLMConneciton's finally block (so a failed disconnect
15388
+ // cannot leave a stale owner), then with this meeting's id
15389
+ // after registerAndConnect resolves.
15390
+ assert.calledTwice(webex.internal.llm.setOwnerMeetingId);
15391
+ assert.calledWith(webex.internal.llm.setOwnerMeetingId.firstCall, undefined);
15392
+ assert.calledWith(webex.internal.llm.setOwnerMeetingId.lastCall, meeting.id);
15393
+ });
15394
+
15395
+ it('claims ownership after successful registerAndConnect on initial connect', async () => {
15396
+ meeting.joinedWith = {state: 'JOINED'};
15397
+ webex.internal.llm.isConnected.returns(false);
15398
+ webex.internal.llm.getOwnerMeetingId.returns(undefined);
15399
+ meeting.locusInfo = {
15400
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15401
+ url: 'a url',
15402
+ info: {datachannelUrl: 'a datachannel url'},
15403
+ };
15404
+
15405
+ await meeting.updateLLMConnection();
15406
+
15407
+ assert.calledOnce(webex.internal.llm.registerAndConnect);
15408
+ assert.calledOnceWithExactly(
15409
+ webex.internal.llm.setRefreshHandler,
15410
+ sinon.match.func,
15411
+ 'llm-default-session',
15412
+ meeting.id
15413
+ );
15414
+ assert.calledOnceWithExactly(webex.internal.llm.setOwnerMeetingId, meeting.id);
15415
+ });
15416
+
15417
+ it('proceeds to connect when LLM is not connected even if another ownerId lingers', async () => {
15418
+ // Defensive path: if the LLM reports not-connected but an old
15419
+ // ownerId is still present (e.g. race before a successful
15420
+ // connections.delete), this meeting can still claim a fresh
15421
+ // connection.
15422
+ meeting.joinedWith = {state: 'JOINED'};
15423
+ webex.internal.llm.isConnected.returns(false);
15424
+ webex.internal.llm.getOwnerMeetingId.returns('stale-owner-id');
15425
+ webex.internal.llm.getDatachannelToken.onFirstCall().returns(undefined);
15426
+ webex.internal.llm.getDatachannelToken.onSecondCall().returns('recovered-token');
15427
+ meeting.locusInfo = {
15428
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
15429
+ url: 'a url',
15430
+ info: {datachannelUrl: 'a datachannel url'},
15431
+ };
15432
+
15433
+ await meeting.updateLLMConnection();
15434
+
15435
+ assert.calledTwice(webex.internal.llm.getDatachannelToken);
15436
+ assert.calledWithExactly(
15437
+ webex.internal.llm.getDatachannelToken.firstCall,
15438
+ 'llm-default-session',
15439
+ meeting.id
15440
+ );
15441
+ assert.calledWithExactly(
15442
+ webex.internal.llm.getDatachannelToken.secondCall,
15443
+ 'llm-default-session'
15444
+ );
15445
+ assert.calledOnceWithExactly(
15446
+ webex.internal.llm.registerAndConnect,
15447
+ 'a url',
15448
+ 'a datachannel url',
15449
+ 'recovered-token'
15450
+ );
15451
+ assert.calledWithExactly(
15452
+ webex.internal.llm.setRefreshHandler.firstCall,
15453
+ sinon.match.func,
15454
+ 'llm-default-session',
15455
+ undefined
15456
+ );
15457
+ assert.calledTwice(webex.internal.llm.setRefreshHandler);
15458
+ assert.calledWithExactly(
15459
+ webex.internal.llm.setRefreshHandler.secondCall,
15460
+ sinon.match.func,
15461
+ 'llm-default-session',
15462
+ meeting.id
15463
+ );
15464
+ assert.calledOnceWithExactly(webex.internal.llm.setOwnerMeetingId, meeting.id);
15465
+ });
15466
+ });
15467
+
13196
15468
  describe('#clearMeetingData', () => {
13197
15469
  beforeEach(() => {
13198
15470
  webex.internal.llm.isConnected = sinon.stub().returns(true);
@@ -13208,10 +15480,15 @@ describe('plugin-meetings', () => {
13208
15480
  it('disconnects llm and removes online and relay listeners during meeting data cleanup', async () => {
13209
15481
  await meeting.clearMeetingData();
13210
15482
 
13211
- assert.calledOnceWithExactly(webex.internal.llm.disconnectLLM, {
13212
- code: 3050,
13213
- reason: 'done (permanent)',
13214
- });
15483
+ assert.calledOnceWithExactly(
15484
+ webex.internal.llm.disconnectLLM,
15485
+ {
15486
+ code: 3050,
15487
+ reason: 'done (permanent)',
15488
+ },
15489
+ 'llm-default-session',
15490
+ meeting.id
15491
+ );
13215
15492
  assert.calledWithExactly(webex.internal.llm.off, 'online', meeting.handleLLMOnline);
13216
15493
  assert.calledWithExactly(
13217
15494
  webex.internal.llm.off,
@@ -13224,10 +15501,13 @@ describe('plugin-meetings', () => {
13224
15501
  meeting.processLocusLLMEvent
13225
15502
  );
13226
15503
  assert.calledOnce(meeting.clearLLMHealthCheckTimer);
13227
- assert.calledOnce(meeting.stopTranscription);
13228
- assert.isUndefined(meeting.transcription);
13229
15504
  assert.calledOnce(meeting.clearDataChannelToken);
13230
- assert.calledOnce(meeting.annotation.deregisterEvents);
15505
+ // stopTranscription and annotation.deregisterEvents are not
15506
+ // called here: they run in stopListeningForMeetingEvents()
15507
+ // before /leave to avoid double-emitting
15508
+ // MEETING_STOPPED_RECEIVING_TRANSCRIPTION.
15509
+ assert.notCalled(meeting.stopTranscription);
15510
+ assert.notCalled(meeting.annotation.deregisterEvents);
13231
15511
  });
13232
15512
  it('continues cleanup when disconnectLLM fails during meeting data cleanup', async () => {
13233
15513
  webex.internal.llm.disconnectLLM.rejects(new Error('disconnect failed'));
@@ -13246,19 +15526,234 @@ describe('plugin-meetings', () => {
13246
15526
  meeting.processLocusLLMEvent
13247
15527
  );
13248
15528
  assert.calledOnce(meeting.clearLLMHealthCheckTimer);
13249
- assert.calledOnce(meeting.stopTranscription);
13250
- assert.isUndefined(meeting.transcription);
13251
15529
  assert.calledOnce(meeting.clearDataChannelToken);
13252
- assert.calledOnce(meeting.annotation.deregisterEvents);
15530
+ assert.notCalled(meeting.stopTranscription);
15531
+ assert.notCalled(meeting.annotation.deregisterEvents);
13253
15532
  });
13254
- it('always calls stopTranscription even when transcription is undefined', async () => {
13255
- meeting.transcription = undefined;
13256
15533
 
13257
- await meeting.clearMeetingData();
15534
+ describe('ownership tag', () => {
15535
+ beforeEach(() => {
15536
+ webex.internal.llm.getOwnerMeetingId = sinon.stub();
15537
+ });
13258
15538
 
13259
- assert.calledOnce(meeting.stopTranscription);
13260
- assert.isUndefined(meeting.transcription);
13261
- assert.calledOnce(meeting.clearDataChannelToken);
15539
+ it('skips disconnectLLM but still removes this meeting listeners when another meeting owns the LLM', async () => {
15540
+ webex.internal.llm.getOwnerMeetingId.returns('some-other-meeting-id');
15541
+
15542
+ await meeting.clearMeetingData();
15543
+
15544
+ assert.notCalled(webex.internal.llm.disconnectLLM);
15545
+ // clearDataChannelToken is always delegated; llm enforces
15546
+ // ownership and no-ops for non-owners internally.
15547
+ assert.calledOnce(meeting.clearDataChannelToken);
15548
+ // Listeners owned by *this* Meeting instance must still be
15549
+ // removed so a leaving subordinate meeting stops receiving
15550
+ // relay/locus events from the shared singleton.
15551
+ assert.calledWithExactly(webex.internal.llm.off, 'online', meeting.handleLLMOnline);
15552
+ assert.calledWithExactly(
15553
+ webex.internal.llm.off,
15554
+ 'event:relay.event',
15555
+ meeting.processRelayEvent
15556
+ );
15557
+ assert.calledWithExactly(
15558
+ webex.internal.llm.off,
15559
+ 'event:locus.state_message',
15560
+ meeting.processLocusLLMEvent
15561
+ );
15562
+ assert.calledOnce(meeting.clearLLMHealthCheckTimer);
15563
+ });
15564
+
15565
+ it('calls disconnectLLM and clears data channel token when this meeting is the owner', async () => {
15566
+ webex.internal.llm.getOwnerMeetingId.returns(meeting.id);
15567
+
15568
+ await meeting.clearMeetingData();
15569
+
15570
+ assert.calledOnceWithExactly(
15571
+ webex.internal.llm.disconnectLLM,
15572
+ {
15573
+ code: 3050,
15574
+ reason: 'done (permanent)',
15575
+ },
15576
+ 'llm-default-session',
15577
+ meeting.id
15578
+ );
15579
+ assert.calledOnce(meeting.clearDataChannelToken);
15580
+ });
15581
+
15582
+ it('calls disconnectLLM and clears data channel token when no owner is recorded (first-claim / legacy)', async () => {
15583
+ webex.internal.llm.getOwnerMeetingId.returns(undefined);
15584
+
15585
+ await meeting.clearMeetingData();
15586
+
15587
+ assert.calledOnceWithExactly(
15588
+ webex.internal.llm.disconnectLLM,
15589
+ {
15590
+ code: 3050,
15591
+ reason: 'done (permanent)',
15592
+ },
15593
+ 'llm-default-session',
15594
+ meeting.id
15595
+ );
15596
+ assert.calledOnce(meeting.clearDataChannelToken);
15597
+ });
15598
+ });
15599
+ });
15600
+ });
15601
+
15602
+ describe('#processLocusLLMEvent', () => {
15603
+ it('routes the LLM event through locusInfo.parse and records the LLM message with the top-level tracking id', () => {
15604
+ const event = {
15605
+ data: {
15606
+ eventType: 'locus.state_message',
15607
+ dataSets: [],
15608
+ },
15609
+ trackingId: 'envelope-tracking-id',
15610
+ };
15611
+
15612
+ meeting.locusInfo.parse = sinon.stub();
15613
+ meeting.onLocusSyncLlmMessage = sinon.stub();
15614
+
15615
+ meeting.processLocusLLMEvent(event);
15616
+
15617
+ // The LLM message is parsed without the tracking id - completion is driven from the
15618
+ // meeting's LLM handler, not threaded through locusInfo.
15619
+ assert.calledOnceWithExactly(meeting.locusInfo.parse, meeting, event.data);
15620
+ // Only the client whose /sync request tracking id matches the tracking id echoed back on
15621
+ // the top-level LLM event envelope records the LLM arrival; onLocusSyncLlmMessage is a
15622
+ // no-op otherwise.
15623
+ assert.calledOnceWithExactly(meeting.onLocusSyncLlmMessage, meeting.id, event.trackingId);
15624
+ });
15625
+
15626
+ it('does not attempt sync completion when the tracking id is missing', () => {
15627
+ const event = {
15628
+ data: {
15629
+ eventType: 'locus.state_message',
15630
+ dataSets: [],
15631
+ },
15632
+ };
15633
+
15634
+ meeting.locusInfo.parse = sinon.stub();
15635
+ meeting.onLocusSyncLlmMessage = sinon.stub();
15636
+
15637
+ meeting.processLocusLLMEvent(event);
15638
+
15639
+ assert.calledOnceWithExactly(meeting.locusInfo.parse, meeting, event.data);
15640
+ assert.notCalled(meeting.onLocusSyncLlmMessage);
15641
+ });
15642
+ });
15643
+
15644
+ describe('#onLocusSyncLlmMessage', () => {
15645
+ it('records the LLM arrival time and then tries to complete the metric', () => {
15646
+ webex.internal.newMetrics.callDiagnosticLatencies.recordLocusSyncMessageReceived =
15647
+ sinon.stub();
15648
+ meeting.tryCompleteLocusSyncLatency = sinon.stub();
15649
+
15650
+ meeting.onLocusSyncLlmMessage('meeting-1', 'sync-tracking-id');
15651
+
15652
+ assert.calledOnceWithExactly(
15653
+ webex.internal.newMetrics.callDiagnosticLatencies.recordLocusSyncMessageReceived,
15654
+ 'meeting-1',
15655
+ 'sync-tracking-id'
15656
+ );
15657
+ assert.calledOnceWithExactly(
15658
+ meeting.tryCompleteLocusSyncLatency,
15659
+ 'meeting-1',
15660
+ 'sync-tracking-id'
15661
+ );
15662
+ // the arrival time must be recorded before completion is attempted
15663
+ assert.callOrder(
15664
+ webex.internal.newMetrics.callDiagnosticLatencies.recordLocusSyncMessageReceived,
15665
+ meeting.tryCompleteLocusSyncLatency
15666
+ );
15667
+ });
15668
+ });
15669
+
15670
+ describe('#tryCompleteLocusSyncLatency', () => {
15671
+ beforeEach(() => {
15672
+ meeting.emitLocusSyncCompleteMetric = sinon.stub();
15673
+ });
15674
+
15675
+ it('emits the metric when both milestones are in (completion succeeds)', () => {
15676
+ const completed = {dataSet: 'main', syncLatency: {totalTime: 50}};
15677
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency = sinon
15678
+ .stub()
15679
+ .returns(completed);
15680
+
15681
+ meeting.tryCompleteLocusSyncLatency('meeting-1', 'sync-tracking-id');
15682
+
15683
+ assert.calledOnceWithExactly(
15684
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency,
15685
+ 'meeting-1',
15686
+ 'sync-tracking-id'
15687
+ );
15688
+ assert.calledOnceWithExactly(meeting.emitLocusSyncCompleteMetric, 'meeting-1', completed);
15689
+ });
15690
+
15691
+ it('does not emit when completion returns undefined (only one milestone is in)', () => {
15692
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency = sinon
15693
+ .stub()
15694
+ .returns(undefined);
15695
+
15696
+ meeting.tryCompleteLocusSyncLatency('meeting-1', 'sync-tracking-id');
15697
+
15698
+ assert.calledOnceWithExactly(
15699
+ webex.internal.newMetrics.callDiagnosticLatencies.completeLocusSyncLatency,
15700
+ 'meeting-1',
15701
+ 'sync-tracking-id'
15702
+ );
15703
+ assert.notCalled(meeting.emitLocusSyncCompleteMetric);
15704
+ });
15705
+ });
15706
+
15707
+ describe('#emitLocusSyncCompleteMetric', () => {
15708
+ it('submits client.locus.sync.complete with the llm websocket url and sync latency', () => {
15709
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
15710
+ webex.internal.llm.getWebSocketUrl = sinon.stub().returns('wss://llm-websocket-url');
15711
+
15712
+ meeting.emitLocusSyncCompleteMetric('meeting-1', {
15713
+ dataSet: 'main',
15714
+ syncLatency: {totalTime: 50},
15715
+ });
15716
+
15717
+ assert.calledOnceWithExactly(webex.internal.newMetrics.submitClientEvent, {
15718
+ name: 'client.locus.sync.complete',
15719
+ payload: {
15720
+ identifiers: {
15721
+ llmWebsocketUrl: 'wss://llm-websocket-url',
15722
+ },
15723
+ llmInfo: {
15724
+ dataSet: 'main',
15725
+ },
15726
+ syncLatency: {totalTime: 50},
15727
+ },
15728
+ options: {
15729
+ meetingId: 'meeting-1',
15730
+ },
15731
+ });
15732
+ });
15733
+
15734
+ it('submits with an undefined llm websocket url when it is unavailable', () => {
15735
+ webex.internal.newMetrics.submitClientEvent.resetHistory();
15736
+ webex.internal.llm.getWebSocketUrl = sinon.stub().returns(undefined);
15737
+
15738
+ meeting.emitLocusSyncCompleteMetric('meeting-1', {
15739
+ dataSet: 'main',
15740
+ syncLatency: {totalTime: 50},
15741
+ });
15742
+
15743
+ assert.calledOnceWithExactly(webex.internal.newMetrics.submitClientEvent, {
15744
+ name: 'client.locus.sync.complete',
15745
+ payload: {
15746
+ identifiers: {
15747
+ llmWebsocketUrl: undefined,
15748
+ },
15749
+ llmInfo: {
15750
+ dataSet: 'main',
15751
+ },
15752
+ syncLatency: {totalTime: 50},
15753
+ },
15754
+ options: {
15755
+ meetingId: 'meeting-1',
15756
+ },
13262
15757
  });
13263
15758
  });
13264
15759
  });
@@ -13298,6 +15793,71 @@ describe('plugin-meetings', () => {
13298
15793
  });
13299
15794
  });
13300
15795
 
15796
+ describe('#waitForSelfUrlChange', () => {
15797
+ let waitForSelfUrlChange;
15798
+ let locusMediaRequestStub;
15799
+
15800
+ beforeEach(async () => {
15801
+ locusMediaRequestStub = sinon
15802
+ .stub(LocusMediaRequestModule, 'LocusMediaRequest')
15803
+ .returns({id: 'fake LocusMediaRequest instance'});
15804
+
15805
+ meeting.setLocus = sinon.stub().returns(true);
15806
+ webex.meetings.registered = true;
15807
+ sandbox.stub(MeetingUtil, 'joinMeeting').returns(Promise.resolve('JOIN_RESULT'));
15808
+ sinon.stub(meeting, 'updateLLMConnection').returns(Promise.resolve());
15809
+
15810
+ await meeting.join();
15811
+
15812
+ waitForSelfUrlChange = locusMediaRequestStub.firstCall.args[0].waitForSelfUrlChange;
15813
+ });
15814
+
15815
+ it('should resolve immediately when joinWithMediaRetryInfo.retryCount > 0', async () => {
15816
+ meeting.joinWithMediaRetryInfo = {retryCount: 1, prevJoinResponse: undefined};
15817
+
15818
+ const result = waitForSelfUrlChange();
15819
+
15820
+ assert.instanceOf(result, Promise);
15821
+ await result;
15822
+ });
15823
+
15824
+ it('should not resolve before the timeout when retryCount is 0', async () => {
15825
+ meeting.joinWithMediaRetryInfo = {retryCount: 0, prevJoinResponse: undefined};
15826
+
15827
+ let resolved = false;
15828
+ waitForSelfUrlChange().then(() => {
15829
+ resolved = true;
15830
+ });
15831
+
15832
+ await testUtils.flushPromises();
15833
+ assert.isFalse(resolved);
15834
+ });
15835
+
15836
+ it('should resolve after the 5s timeout when retryCount is 0', async () => {
15837
+ meeting.joinWithMediaRetryInfo = {retryCount: 0, prevJoinResponse: undefined};
15838
+
15839
+ let resolved = false;
15840
+ const promise = waitForSelfUrlChange();
15841
+ promise.then(() => {
15842
+ resolved = true;
15843
+ });
15844
+
15845
+ fakeClock.tick(5000);
15846
+ await promise;
15847
+
15848
+ assert.isTrue(resolved);
15849
+ });
15850
+
15851
+ it('should return the same promise when called multiple times', () => {
15852
+ meeting.joinWithMediaRetryInfo = {retryCount: 0, prevJoinResponse: undefined};
15853
+
15854
+ const firstPromise = waitForSelfUrlChange();
15855
+ const secondPromise = waitForSelfUrlChange();
15856
+
15857
+ assert.equal(firstPromise, secondPromise);
15858
+ });
15859
+ });
15860
+
13301
15861
  describe('preferred video device', () => {
13302
15862
  describe('#getVideoDeviceId', () => {
13303
15863
  it('returns the preferred video device', () => {
@@ -15012,16 +17572,25 @@ describe('plugin-meetings', () => {
15012
17572
  assert.notCalled(meeting.meetingRequest.sendReaction);
15013
17573
  });
15014
17574
 
15015
- it('should fail sending a reaction if reactionType is invalid ', async () => {
17575
+ it('should send a custom reaction type not in the known list', async () => {
15016
17576
  meeting.locusInfo.controls = {reactions: {reactionChannelUrl: 'Fake URL'}};
15017
17577
 
15018
- await assert.isRejected(
15019
- meeting.sendReaction('invalid_reaction', 'light'),
15020
- Error,
15021
- 'invalid_reaction is not a valid reaction.'
15022
- );
17578
+ const reactionPromise = meeting.sendReaction('custom_reaction', 'light');
15023
17579
 
15024
- assert.notCalled(meeting.meetingRequest.sendReaction);
17580
+ assert.exists(reactionPromise.then);
17581
+ await reactionPromise;
17582
+ assert.calledOnceWithExactly(meeting.meetingRequest.sendReaction, {
17583
+ reactionChannelUrl: 'Fake URL',
17584
+ reaction: {
17585
+ type: 'custom_reaction',
17586
+ tone: {
17587
+ type: 'light_skin_tone',
17588
+ codepoints: '1F3FB',
17589
+ shortcodes: ':skin-tone-2:',
17590
+ },
17591
+ },
17592
+ participantId: meeting.members.selfId,
17593
+ });
15025
17594
  });
15026
17595
 
15027
17596
  it('should send a reaction with default skin tone if provided skinToneType is invalid ', async () => {