@webex/plugin-meetings 3.12.0-webex-services-ready.4 → 3.13.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/.sdd/manifest.json +1312 -0
  2. package/.sdd/templates/.source.json +30 -0
  3. package/.sdd/templates/component-repo/module-docs/module-spec-quality.md +111 -0
  4. package/.sdd/templates/component-repo/module-docs/module-spec.template.md +321 -0
  5. package/.sdd/templates/component-repo/reference-docs/adr/_adr-example.md +59 -0
  6. package/.sdd/templates/component-repo/reference-docs/patterns/_pattern-example.md +49 -0
  7. package/.sdd/templates/component-repo/reference-docs/rules/_rule-example.md +42 -0
  8. package/.sdd/templates/component-repo/standing-docs/AGENTS.template.md +120 -0
  9. package/.sdd/templates/component-repo/standing-docs/ARCHITECTURE.template.md +206 -0
  10. package/.sdd/templates/component-repo/standing-docs/CONTRACTS.template.md +90 -0
  11. package/.sdd/templates/component-repo/standing-docs/DATA_MODEL.template.md +68 -0
  12. package/.sdd/templates/component-repo/standing-docs/GETTING_STARTED.template.md +111 -0
  13. package/.sdd/templates/component-repo/standing-docs/GLOSSARY.template.md +57 -0
  14. package/.sdd/templates/component-repo/standing-docs/REVIEW_CHECKLIST.template.md +69 -0
  15. package/.sdd/templates/component-repo/standing-docs/RULES.template.md +96 -0
  16. package/.sdd/templates/component-repo/standing-docs/SECURITY.template.md +84 -0
  17. package/.sdd/templates/component-repo/standing-docs/SERVICE_STATE.template.md +82 -0
  18. package/.sdd/templates/component-repo/standing-docs/SPEC_INDEX.template.md +94 -0
  19. package/.sdd/templates/component-repo/standing-docs/TEST_INDEX.template.md +64 -0
  20. package/.sdd/templates/component-repo/template-map.json +112 -0
  21. package/AGENTS.md +130 -4
  22. package/ai-docs/ARCHITECTURE.md +208 -0
  23. package/ai-docs/CONTRACTS.md +267 -0
  24. package/ai-docs/DATA_MODEL.md +64 -0
  25. package/ai-docs/GETTING_STARTED.md +73 -0
  26. package/ai-docs/GLOSSARY.md +56 -0
  27. package/ai-docs/REVIEW_CHECKLIST.md +45 -0
  28. package/ai-docs/RULES.md +79 -0
  29. package/ai-docs/SECURITY.md +74 -0
  30. package/ai-docs/SERVICE_STATE.md +59 -0
  31. package/ai-docs/SPEC_INDEX.md +85 -0
  32. package/ai-docs/TEST_INDEX.md +45 -0
  33. package/ai-docs/adr/0001-migrate-existing-docs-into-sdd.md +61 -0
  34. package/ai-docs/patterns/defensive-error-propagation.md +55 -0
  35. package/ai-docs/patterns/event-scope-emission.md +46 -0
  36. package/ai-docs/patterns/source-to-test-path-mirroring.md +45 -0
  37. package/ai-docs/patterns/stateless-plugin-request-classes.md +53 -0
  38. package/ai-docs/patterns/typed-constants-and-enum-values.md +47 -0
  39. package/assets/README.md +28 -0
  40. package/assets/e2ee-0.0.1.js +2 -0
  41. package/assets/e2ee-0.0.1.wasm +0 -0
  42. package/dist/aiEnableRequest/index.js +1 -1
  43. package/dist/annotation/index.js +55 -19
  44. package/dist/annotation/index.js.map +1 -1
  45. package/dist/assets/e2ee-0.0.1.js +2 -0
  46. package/dist/assets/e2ee-0.0.1.wasm +0 -0
  47. package/dist/breakouts/breakout.js +1 -1
  48. package/dist/breakouts/index.js +39 -5
  49. package/dist/breakouts/index.js.map +1 -1
  50. package/dist/common/errors/webex-errors.js +7 -2
  51. package/dist/common/errors/webex-errors.js.map +1 -1
  52. package/dist/config.js +1 -0
  53. package/dist/config.js.map +1 -1
  54. package/dist/constants.js +6 -5
  55. package/dist/constants.js.map +1 -1
  56. package/dist/hashTree/hashTreeParser.js +101 -48
  57. package/dist/hashTree/hashTreeParser.js.map +1 -1
  58. package/dist/index.js +1 -0
  59. package/dist/index.js.map +1 -1
  60. package/dist/interceptors/dataChannelAuthToken.js +41 -59
  61. package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
  62. package/dist/interceptors/locusRetry.js +1 -1
  63. package/dist/interceptors/locusRetry.js.map +1 -1
  64. package/dist/interpretation/index.js +46 -12
  65. package/dist/interpretation/index.js.map +1 -1
  66. package/dist/interpretation/siLanguage.js +1 -1
  67. package/dist/locus-info/index.js +236 -80
  68. package/dist/locus-info/index.js.map +1 -1
  69. package/dist/locus-info/types.js +2 -1
  70. package/dist/locus-info/types.js.map +1 -1
  71. package/dist/media/MediaConnectionAwaiter.js +225 -175
  72. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  73. package/dist/meeting/index.js +355 -299
  74. package/dist/meeting/index.js.map +1 -1
  75. package/dist/meeting/util.js +8 -2
  76. package/dist/meeting/util.js.map +1 -1
  77. package/dist/meeting/voicea-meeting.js +2 -1
  78. package/dist/meeting/voicea-meeting.js.map +1 -1
  79. package/dist/meeting-info/meeting-info-v2.js +10 -3
  80. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  81. package/dist/meetings/index.js +72 -31
  82. package/dist/meetings/index.js.map +1 -1
  83. package/dist/multistream/remoteMediaManager.js +32 -4
  84. package/dist/multistream/remoteMediaManager.js.map +1 -1
  85. package/dist/multistream/sendSlotManager.js +11 -1
  86. package/dist/multistream/sendSlotManager.js.map +1 -1
  87. package/dist/types/annotation/index.d.ts +19 -0
  88. package/dist/types/common/errors/webex-errors.d.ts +6 -2
  89. package/dist/types/config.d.ts +1 -0
  90. package/dist/types/constants.d.ts +2 -1
  91. package/dist/types/hashTree/hashTreeParser.d.ts +12 -0
  92. package/dist/types/index.d.ts +1 -0
  93. package/dist/types/locus-info/index.d.ts +45 -1
  94. package/dist/types/locus-info/types.d.ts +1 -0
  95. package/dist/types/media/MediaConnectionAwaiter.d.ts +61 -53
  96. package/dist/types/meeting/index.d.ts +49 -12
  97. package/dist/types/meeting/util.d.ts +3 -1
  98. package/dist/types/meeting-info/meeting-info-v2.d.ts +1 -0
  99. package/dist/types/meetings/index.d.ts +2 -1
  100. package/dist/types/multistream/remoteMediaManager.d.ts +18 -0
  101. package/dist/types/multistream/sendSlotManager.d.ts +5 -1
  102. package/dist/webinar/index.js +298 -255
  103. package/dist/webinar/index.js.map +1 -1
  104. package/package.json +25 -23
  105. package/src/aiEnableRequest/ai-docs/ai-enable-request-spec.md +223 -0
  106. package/src/annotation/ai-docs/annotation-spec.md +236 -0
  107. package/src/annotation/index.ts +61 -29
  108. package/src/breakouts/ai-docs/breakouts-spec.md +324 -0
  109. package/src/breakouts/index.ts +35 -2
  110. package/src/common/errors/webex-errors.ts +8 -2
  111. package/src/config.ts +5 -1
  112. package/src/constants.ts +2 -1
  113. package/src/controls-options-manager/ai-docs/controls-options-manager-spec.md +243 -0
  114. package/src/hashTree/ai-docs/hash-tree-spec.md +267 -0
  115. package/src/hashTree/hashTreeParser.ts +67 -3
  116. package/src/index.ts +1 -0
  117. package/src/interceptors/ai-docs/interceptors-spec.md +247 -0
  118. package/src/interceptors/dataChannelAuthToken.ts +48 -77
  119. package/src/interceptors/locusRetry.ts +1 -1
  120. package/src/interpretation/ai-docs/interpretation-spec.md +256 -0
  121. package/src/interpretation/index.ts +38 -1
  122. package/src/locus-info/ai-docs/locus-info-spec.md +293 -0
  123. package/src/locus-info/index.ts +156 -35
  124. package/src/locus-info/types.ts +1 -0
  125. package/src/media/MediaConnectionAwaiter.ts +223 -207
  126. package/src/media/ai-docs/media-spec.md +267 -0
  127. package/src/meeting/ai-docs/meeting-spec.md +404 -0
  128. package/src/meeting/index.ts +332 -296
  129. package/src/meeting/util.ts +7 -4
  130. package/src/meeting/voicea-meeting.ts +1 -1
  131. package/src/meeting-info/ai-docs/meeting-info-spec.md +261 -0
  132. package/src/meeting-info/meeting-info-v2.ts +7 -2
  133. package/src/meetings/ai-docs/meetings-spec.md +296 -0
  134. package/src/meetings/index.ts +59 -23
  135. package/src/member/ai-docs/member-spec.md +196 -0
  136. package/src/members/ai-docs/members-spec.md +256 -0
  137. package/src/metrics/ai-docs/metrics-spec.md +185 -0
  138. package/src/multistream/ai-docs/multistream-spec.md +295 -0
  139. package/src/multistream/remoteMediaManager.ts +23 -1
  140. package/src/multistream/sendSlotManager.ts +15 -1
  141. package/src/personal-meeting-room/ai-docs/personal-meeting-room-spec.md +234 -0
  142. package/src/reachability/ai-docs/reachability-spec.md +261 -0
  143. package/src/reactions/ai-docs/reactions-spec.md +198 -0
  144. package/src/reconnection-manager/ai-docs/reconnection-manager-spec.md +272 -0
  145. package/src/recording-controller/ai-docs/recording-controller-spec.md +223 -0
  146. package/src/roap/ai-docs/roap-spec.md +241 -0
  147. package/src/webinar/ai-docs/webinar-spec.md +243 -0
  148. package/src/webinar/index.ts +168 -188
  149. package/test/unit/spec/annotation/index.ts +214 -182
  150. package/test/unit/spec/breakouts/index.ts +145 -13
  151. package/test/unit/spec/hashTree/hashTreeParser.ts +212 -1
  152. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +81 -99
  153. package/test/unit/spec/interceptors/locusRetry.ts +29 -1
  154. package/test/unit/spec/interpretation/index.ts +93 -0
  155. package/test/unit/spec/locus-info/index.js +397 -0
  156. package/test/unit/spec/media/MediaConnectionAwaiter.ts +426 -19
  157. package/test/unit/spec/media/properties.ts +3 -3
  158. package/test/unit/spec/meeting/index.js +1219 -723
  159. package/test/unit/spec/meeting/utils.js +52 -18
  160. package/test/unit/spec/meeting/voicea-meeting.ts +85 -1
  161. package/test/unit/spec/meeting-info/meetinginfov2.js +69 -1
  162. package/test/unit/spec/meetings/index.js +145 -43
  163. package/test/unit/spec/multistream/remoteMediaManager.ts +46 -0
  164. package/test/unit/spec/multistream/sendSlotManager.ts +30 -2
  165. package/test/unit/spec/webinar/index.ts +886 -718
@@ -4,36 +4,25 @@
4
4
  import {WebexPlugin, config} from '@webex/webex-core';
5
5
  import uuid from 'uuid';
6
6
  import {get} from 'lodash';
7
+ import type LLMChannel from '@webex/internal-plugin-llm';
7
8
  import {
8
9
  _ID_,
10
+ EVENT_TRIGGERS,
9
11
  HEADERS,
10
12
  HTTP_VERBS,
11
13
  MEETINGS,
12
14
  SELF_ROLES,
13
15
  SHARE_STATUS,
14
16
  DEFAULT_LARGE_SCALE_WEBINAR_ATTENDEE_SEARCH_LIMIT,
15
- LLM_PRACTICE_SESSION,
16
17
  LOCUS_LLM_EVENT,
17
18
  } from '../constants';
19
+ import Trigger from '../common/events/trigger-proxy';
18
20
 
19
21
  import WebinarCollection from './collection';
20
22
  import LoggerProxy from '../common/logs/logger-proxy';
21
23
  import MeetingUtil from '../meeting/util';
22
24
  import {sanitizeParams} from './utils';
23
25
 
24
- const PS_LLM_EVENTS = [
25
- {
26
- event: `event:relay.event:${LLM_PRACTICE_SESSION}`,
27
- listenerKey: 'relay',
28
- handlerKey: 'processRelayEvent',
29
- },
30
- {
31
- event: `${LOCUS_LLM_EVENT}:${LLM_PRACTICE_SESSION}`,
32
- listenerKey: 'locusLLM',
33
- handlerKey: 'processLocusLLMEvent',
34
- },
35
- ];
36
-
37
26
  /**
38
27
  * @class Webinar
39
28
  */
@@ -53,6 +42,21 @@ const Webinar = WebexPlugin.extend({
53
42
  meetingId: 'string',
54
43
  },
55
44
 
45
+ /**
46
+ * LLM channel for practice session, owned by this webinar instance.
47
+ * @private
48
+ * @type {LLMChannel|undefined}
49
+ */
50
+ _practiceSessionLLMChannel: undefined as LLMChannel | undefined,
51
+
52
+ /**
53
+ * Pending practice session datachannel token, saved from join response.
54
+ * Used when creating the practice session LLM channel.
55
+ * @private
56
+ * @type {string|undefined}
57
+ */
58
+ _pendingPracticeSessionDatachannelToken: undefined as string | undefined,
59
+
56
60
  /**
57
61
  * Calls this to clean up listeners
58
62
  * @returns {void}
@@ -177,67 +181,96 @@ const Webinar = WebexPlugin.extend({
177
181
  },
178
182
 
179
183
  /**
180
- * Disconnects the practice session data channel and removes its relay listener.
181
- * The listener reference removed here is the exact callback captured at subscribe
182
- * time (see updatePSDataChannel) so that cleanup is correct even if the underlying
183
- * meeting can no longer be resolved (e.g. locusUrl mismatch).
184
+ * Returns the practice session LLM channel binding, if connected.
185
+ * @returns {string|undefined}
186
+ */
187
+ getPracticeSessionBinding() {
188
+ return this._practiceSessionLLMChannel?.getBinding();
189
+ },
190
+
191
+ /**
192
+ * Returns whether the practice session LLM channel is connected.
193
+ * @returns {boolean}
194
+ */
195
+ isPracticeSessionLLMChannelConnected() {
196
+ return this._practiceSessionLLMChannel?.isConnected() ?? false;
197
+ },
198
+
199
+ /**
200
+ * Returns the practice session LLM channel's locus URL, if available.
201
+ * @returns {string|undefined}
202
+ */
203
+ getPracticeSessionLocusUrl() {
204
+ return this._practiceSessionLLMChannel?.getLocusUrl();
205
+ },
206
+
207
+ /**
208
+ * Stores the practice session datachannel token for later use when
209
+ * creating the practice session LLM channel.
210
+ * @param {string} token - The datachannel token to store
211
+ * @returns {void}
212
+ */
213
+ setPracticeSessionDatachannelToken(token: string) {
214
+ this._pendingPracticeSessionDatachannelToken = token;
215
+ },
216
+
217
+ /**
218
+ * Disconnects the practice session LLM channel and cleans up listeners.
184
219
  * @returns {Promise<void>}
185
220
  */
186
221
  async cleanupPSDataChannel() {
187
- const {isOwner} = this.webex.internal.llm.resolveSessionOwnership(
188
- this.meetingId,
189
- LLM_PRACTICE_SESSION
190
- );
191
- this.llmListeners = this.llmListeners || {};
192
-
222
+ // Remove pending online listener if any
193
223
  if (this._pendingOnlineListener) {
194
- // @ts-ignore - Fix type
195
- this.webex.internal.llm.off('online', this._pendingOnlineListener);
224
+ const meeting = this.getValidatedWebinarMeeting();
225
+ meeting?.llmChannel?.off('online', this._pendingOnlineListener);
196
226
  this._pendingOnlineListener = null;
197
227
  }
198
228
 
199
- try {
200
- // @ts-ignore - Fix type
201
- const disconnected = await this.webex.internal.llm.disconnectLLM(
202
- {
203
- code: 3050,
204
- reason: 'done (permanent)',
205
- },
206
- LLM_PRACTICE_SESSION,
207
- this.meetingId
208
- );
229
+ const meeting = this.getValidatedWebinarMeeting();
209
230
 
210
- if (!disconnected) {
211
- LoggerProxy.logger.info(
212
- `Webinar:index#cleanupPSDataChannel --> skipping disconnect; practice-session LLM is not owned by meeting ${this.meetingId}`
213
- );
214
- }
215
- } catch (error) {
216
- // disconnectLLM clears ownership only on success; release a stale owner
217
- // tag here so other meeting instances can reclaim practice-session LLM.
218
- if (isOwner) {
219
- // @ts-ignore - Fix type
220
- this.webex.internal.llm.setOwnerMeetingId?.(undefined, LLM_PRACTICE_SESSION);
231
+ if (!this._practiceSessionLLMChannel) {
232
+ // Even without PS channel, ensure voicea is bound to main channel
233
+ if (meeting?.voiceaChannel && meeting?.llmChannel) {
234
+ await meeting.voiceaChannel.switchLLMChannel(meeting.llmChannel);
235
+ meeting.startTranscriptionIfNeeded();
221
236
  }
222
237
 
238
+ return;
239
+ }
240
+
241
+ try {
242
+ await this._practiceSessionLLMChannel.disconnect({
243
+ code: 3050,
244
+ reason: 'done (permanent)',
245
+ });
246
+ } catch (error) {
247
+ LoggerProxy.logger.error(
248
+ 'Webinar:index#cleanupPSDataChannel --> Failed to disconnect practice session LLM channel',
249
+ error
250
+ );
223
251
  throw error;
224
252
  } finally {
225
- if (this._practiceSessionRelayListener) {
226
- // @ts-ignore - Fix type
227
- this.webex.internal.llm.off(
228
- `event:relay.event:${LLM_PRACTICE_SESSION}`,
229
- this._practiceSessionRelayListener
230
- );
231
- }
232
- this._practiceSessionRelayListener = null;
233
-
234
- for (const {event, listenerKey} of PS_LLM_EVENTS) {
235
- if (this.llmListeners[listenerKey]) {
236
- // @ts-ignore - Fix type
237
- this.webex.internal.llm.off(event, this.llmListeners[listenerKey]);
238
- this.llmListeners[listenerKey] = null;
253
+ // Remove listeners from the channel
254
+ if (meeting) {
255
+ this._practiceSessionLLMChannel?.off('event:relay.event', meeting.processRelayEvent);
256
+ this._practiceSessionLLMChannel?.off(LOCUS_LLM_EVENT, meeting.processLocusLLMEvent);
257
+ this._practiceSessionLLMChannel?.off('online', meeting.handleLLMOnline);
258
+
259
+ // Switch annotation back to the meeting's default channel
260
+ if (meeting.llmChannel) {
261
+ meeting.annotation.registerChannel(meeting.llmChannel);
239
262
  }
240
263
  }
264
+ this._practiceSessionLLMChannel = undefined;
265
+
266
+ // Switch voicea to current main channel. Switching after disconnect ensures:
267
+ // - If main channel was replaced during disconnect (concurrent updateLLMConnection),
268
+ // meeting.llmChannel will be the new channel
269
+ // - If the channel is still connecting, switchLLMChannel waits for it to come online
270
+ if (meeting?.voiceaChannel && meeting?.llmChannel) {
271
+ await meeting.voiceaChannel.switchLLMChannel(meeting.llmChannel);
272
+ meeting.startTranscriptionIfNeeded();
273
+ }
241
274
  }
242
275
  },
243
276
 
@@ -256,11 +289,10 @@ const Webinar = WebexPlugin.extend({
256
289
  return undefined;
257
290
  }
258
291
 
259
- // @ts-ignore
260
- const cachedToken = this.webex.internal.llm.getDatachannelToken(
261
- LLM_PRACTICE_SESSION,
262
- this.meetingId
263
- );
292
+ // Check for cached token on the channel or pending token
293
+ const cachedToken =
294
+ this._practiceSessionLLMChannel?.getDatachannelToken() ??
295
+ this._pendingPracticeSessionDatachannelToken;
264
296
 
265
297
  if (cachedToken) {
266
298
  return cachedToken;
@@ -268,18 +300,18 @@ const Webinar = WebexPlugin.extend({
268
300
 
269
301
  try {
270
302
  const refreshResponse = await meeting.refreshDataChannelToken();
271
- const {datachannelToken, dataChannelTokenType} = refreshResponse?.body ?? {};
303
+ const {datachannelToken} = refreshResponse?.body ?? {};
272
304
 
273
305
  if (!datachannelToken) {
274
306
  return undefined;
275
307
  }
276
308
 
277
- // @ts-ignore
278
- this.webex.internal.llm.setDatachannelToken(
279
- datachannelToken,
280
- dataChannelTokenType || LLM_PRACTICE_SESSION,
281
- this.meetingId
282
- );
309
+ // Store token on the channel if it exists, otherwise save for later
310
+ if (this._practiceSessionLLMChannel) {
311
+ this._practiceSessionLLMChannel.setDatachannelToken(datachannelToken);
312
+ } else {
313
+ this._pendingPracticeSessionDatachannelToken = datachannelToken;
314
+ }
283
315
 
284
316
  return datachannelToken;
285
317
  } catch (error) {
@@ -294,22 +326,17 @@ const Webinar = WebexPlugin.extend({
294
326
  },
295
327
 
296
328
  /**
297
- * Connects to low latency mercury and reconnects if the address has changed
298
- * It will also disconnect if called when the meeting has ended
329
+ * Connects practice session LLM channel. Creates a new channel if needed.
330
+ * Will disconnect if the meeting has ended or is no longer in practice session mode.
331
+ * Waits for the main LLM channel to be connected before connecting practice session.
299
332
  * @returns {Promise}
300
333
  */
301
334
  async updatePSDataChannel() {
302
- this.llmListeners = this.llmListeners || {};
303
-
304
335
  this._updatePSDataChannelSequence = (this._updatePSDataChannelSequence || 0) + 1;
305
336
  const invocationSequence = this._updatePSDataChannelSequence;
306
337
 
307
338
  const meeting = this.getValidatedWebinarMeeting();
308
339
  const isPracticeSession = meeting?.isJoined() && this.isJoinPracticeSessionDataChannel();
309
- const {currentOwner, isOwner} = this.webex.internal.llm.resolveSessionOwnership(
310
- this.meetingId,
311
- LLM_PRACTICE_SESSION
312
- );
313
340
 
314
341
  if (!isPracticeSession) {
315
342
  await this.cleanupPSDataChannel();
@@ -317,61 +344,40 @@ const Webinar = WebexPlugin.extend({
317
344
  return undefined;
318
345
  }
319
346
 
320
- if (!isOwner) {
321
- LoggerProxy.logger.info(
322
- `Webinar:index#updatePSDataChannel --> skipping; practice-session LLM owned by meeting ${currentOwner}, not ${this.meetingId}`
323
- );
324
-
325
- return undefined;
326
- }
327
-
328
347
  // @ts-ignore - Fix type
329
348
  const {url = undefined, info: {practiceSessionDatachannelUrl = undefined} = {}} =
330
349
  meeting?.locusInfo || {};
331
350
 
332
- // @ts-ignore
333
- let practiceSessionDatachannelToken = this.webex.internal.llm.getDatachannelToken(
334
- LLM_PRACTICE_SESSION,
335
- this.meetingId
336
- );
337
-
338
- const keepTranscriptionSubscribed = this.webex.internal.voicea.getKeepTranscriptionSubscribed();
339
-
340
351
  if (!practiceSessionDatachannelUrl) {
341
352
  return undefined;
342
353
  }
343
- // @ts-ignore - Fix type
344
- if (this.webex.internal.llm.isConnected(LLM_PRACTICE_SESSION)) {
354
+
355
+ // If already connected to same URLs, skip reconnect
356
+ if (this._practiceSessionLLMChannel?.isConnected()) {
345
357
  if (
346
- // @ts-ignore - Fix type
347
- url === this.webex.internal.llm.getLocusUrl(LLM_PRACTICE_SESSION) &&
348
- // @ts-ignore - Fix type
349
- practiceSessionDatachannelUrl ===
350
- this.webex.internal.llm.getDatachannelUrl(LLM_PRACTICE_SESSION)
358
+ url === this._practiceSessionLLMChannel.getLocusUrl() &&
359
+ practiceSessionDatachannelUrl === this._practiceSessionLLMChannel.getDatachannelUrl()
351
360
  ) {
352
361
  return undefined;
353
362
  }
354
-
363
+ // URLs changed, disconnect existing channel
355
364
  await this.cleanupPSDataChannel();
356
365
  }
357
366
 
358
- // Ensure the default session data channel is connected before connecting the practice session.
367
+ // Ensure the default session LLM channel is connected before connecting the practice session.
359
368
  // Subscribe before checking isConnected() to avoid a race where the 'online' event fires
360
- // between the check and the subscription — Mercury does not replay missed events.
361
- if (!this._pendingOnlineListener) {
369
+ // between the check and the subscription — the channel does not replay missed events.
370
+ if (!this._pendingOnlineListener && meeting?.llmChannel) {
362
371
  const onDefaultSessionConnected = () => {
363
372
  this._pendingOnlineListener = null;
364
- // @ts-ignore - Fix type
365
- this.webex.internal.llm.off('online', onDefaultSessionConnected);
373
+ meeting.llmChannel?.off('online', onDefaultSessionConnected);
366
374
  this.updatePSDataChannel();
367
375
  };
368
376
  this._pendingOnlineListener = onDefaultSessionConnected;
369
- // @ts-ignore - Fix type
370
- this.webex.internal.llm.on('online', onDefaultSessionConnected);
377
+ meeting.llmChannel.on('online', onDefaultSessionConnected);
371
378
  }
372
379
 
373
- // @ts-ignore - Fix type
374
- if (!this.webex.internal.llm.isConnected()) {
380
+ if (!meeting?.llmChannel?.isConnected()) {
375
381
  LoggerProxy.logger.info(
376
382
  'Webinar:index#updatePSDataChannel --> default session not yet connected, deferring practice session connect.'
377
383
  );
@@ -381,12 +387,16 @@ const Webinar = WebexPlugin.extend({
381
387
 
382
388
  // Default session is already connected — cancel the pending listener and proceed
383
389
  if (this._pendingOnlineListener) {
384
- // @ts-ignore - Fix type
385
- this.webex.internal.llm.off('online', this._pendingOnlineListener);
390
+ meeting.llmChannel.off('online', this._pendingOnlineListener);
386
391
  this._pendingOnlineListener = null;
387
392
  }
388
393
 
389
- const refreshedPracticeSessionToken = await this.ensurePracticeSessionDatachannelToken(meeting);
394
+ // Get token from pending or refresh if needed
395
+ let practiceSessionDatachannelToken =
396
+ this._pendingPracticeSessionDatachannelToken ??
397
+ this._practiceSessionLLMChannel?.getDatachannelToken();
398
+
399
+ const refreshedToken = await this.ensurePracticeSessionDatachannelToken(meeting);
390
400
 
391
401
  const latestPracticeSessionDatachannelUrl = get(
392
402
  meeting,
@@ -405,93 +415,63 @@ const Webinar = WebexPlugin.extend({
405
415
  return undefined;
406
416
  }
407
417
 
408
- if (refreshedPracticeSessionToken) {
409
- practiceSessionDatachannelToken = refreshedPracticeSessionToken;
418
+ if (refreshedToken) {
419
+ practiceSessionDatachannelToken = refreshedToken;
410
420
  }
411
421
 
412
- const {currentOwner: currentOwnerBeforeConnect, isOwner: isOwnerBeforeConnect} =
413
- this.webex.internal.llm.resolveSessionOwnership(this.meetingId, LLM_PRACTICE_SESSION);
422
+ // Create a new practice session LLM channel
423
+ // @ts-ignore - Fix type
424
+ const psChannel = this.webex.internal.llm.createChannel();
425
+ this._practiceSessionLLMChannel = psChannel;
414
426
 
415
- if (!isOwnerBeforeConnect) {
416
- LoggerProxy.logger.info(
417
- `Webinar:index#updatePSDataChannel --> skipping pre-connect owner write; practice-session LLM owned by meeting ${currentOwnerBeforeConnect}, not ${this.meetingId}`
418
- );
427
+ // Set up refresh handler before registration
428
+ psChannel.setRefreshHandler(() => meeting.refreshDataChannelToken());
419
429
 
420
- return undefined;
430
+ // If we have a pending token, store it on the channel
431
+ if (this._pendingPracticeSessionDatachannelToken) {
432
+ psChannel.setDatachannelToken(this._pendingPracticeSessionDatachannelToken);
433
+ this._pendingPracticeSessionDatachannelToken = undefined;
421
434
  }
422
435
 
423
- // Ensure refresh for practice datachannel requests is routed to this
424
- // meeting only when we are actually about to connect the practice session.
425
- // This avoids claiming ownership in flows that return early (e.g. missing
426
- // practiceSessionDatachannelUrl or waiting for default session online).
427
- // @ts-ignore - Fix type
428
- this.webex.internal.llm.setRefreshHandler(
429
- () => meeting.refreshDataChannelToken(),
430
- LLM_PRACTICE_SESSION,
431
- this.meetingId
432
- );
433
- // @ts-ignore - Fix type
434
- this.webex.internal.llm.setOwnerMeetingId?.(this.meetingId, LLM_PRACTICE_SESSION);
435
-
436
- // @ts-ignore - Fix type
437
- return this.webex.internal.llm
438
- .registerAndConnect(
439
- url,
440
- practiceSessionDatachannelUrl,
441
- practiceSessionDatachannelToken,
442
- LLM_PRACTICE_SESSION
443
- )
444
- .then((registerAndConnectResult) => {
445
- const {currentOwner: currentOwnerAfterConnect, isOwner: isOwnerAfterConnect} =
446
- this.webex.internal.llm.resolveSessionOwnership(this.meetingId, LLM_PRACTICE_SESSION);
447
-
448
- if (this.meetingId && isOwnerAfterConnect) {
449
- // @ts-ignore - Fix type
450
- this.webex.internal.llm.setOwnerMeetingId?.(this.meetingId, LLM_PRACTICE_SESSION);
451
- } else {
452
- LoggerProxy.logger.info(
453
- `Webinar:index#updatePSDataChannel --> skipping post-connect owner write; practice-session LLM owned by meeting ${currentOwnerAfterConnect}, not ${this.meetingId}`
454
- );
455
- }
436
+ return psChannel
437
+ .registerAndConnect(url, practiceSessionDatachannelUrl, practiceSessionDatachannelToken)
438
+ .then(async (registerAndConnectResult) => {
439
+ // Check if this channel is still the current one (race condition guard)
440
+ if (this._practiceSessionLLMChannel !== psChannel) {
441
+ psChannel.disconnect({code: 3050, reason: 'replaced'}).catch(() => {});
456
442
 
457
- // Track the exact listener references so cleanupPSDataChannel can
458
- // unsubscribe deterministically, even if the meeting can no longer
459
- // be resolved at cleanup time.
460
- for (const {event, listenerKey, handlerKey} of PS_LLM_EVENTS) {
461
- if (this.llmListeners[listenerKey]) {
462
- // @ts-ignore - Fix type
463
- this.webex.internal.llm.off(event, this.llmListeners[listenerKey]);
464
- }
465
- this.llmListeners[listenerKey] = meeting?.[handlerKey];
466
- // @ts-ignore - Fix type
467
- this.webex.internal.llm.on(event, this.llmListeners[listenerKey]);
443
+ return undefined;
468
444
  }
469
- // @ts-ignore - Fix type
470
- this.webex.internal.voicea?.announce?.();
471
- if (keepTranscriptionSubscribed) {
472
- this.webex.internal.voicea.updateSubchannelSubscriptions({subscribe: ['transcription']});
445
+ // Register event listeners on the practice session channel
446
+ psChannel.off('event:relay.event', meeting.processRelayEvent);
447
+ psChannel.on('event:relay.event', meeting.processRelayEvent);
448
+ psChannel.off(LOCUS_LLM_EVENT, meeting.processLocusLLMEvent);
449
+ psChannel.on(LOCUS_LLM_EVENT, meeting.processLocusLLMEvent);
450
+ psChannel.off('online', meeting.handleLLMOnline);
451
+ psChannel.on('online', meeting.handleLLMOnline);
452
+
453
+ // Switch annotation to practice session channel
454
+ meeting.annotation.registerChannel(psChannel);
455
+
456
+ // Switch meeting's voicea channel to use the PS LLM connection.
457
+ // The reconciler pattern preserves caption state and handles all timing.
458
+ // transcription is always initialized (reset to initial shape, never null).
459
+ if (meeting.voiceaChannel) {
460
+ await meeting.voiceaChannel.switchLLMChannel(psChannel);
461
+ meeting.startTranscriptionIfNeeded();
473
462
  }
463
+
474
464
  LoggerProxy.logger.info(
475
- `Webinar:index#updatePSDataChannel --> enabled to receive relay events for default session for ${LLM_PRACTICE_SESSION}!`
465
+ 'Webinar:index#updatePSDataChannel --> enabled to receive relay events for practice session!'
476
466
  );
477
467
 
478
468
  return Promise.resolve(registerAndConnectResult);
479
469
  })
480
470
  .catch((error) => {
481
- const {
482
- currentOwner: currentOwnerAfterRegisterFailure,
483
- isOwner: isOwnerAfterRegisterFailure,
484
- } = this.webex.internal.llm.resolveSessionOwnership(this.meetingId, LLM_PRACTICE_SESSION);
485
-
486
- if (isOwnerAfterRegisterFailure) {
487
- // @ts-ignore - Fix type
488
- this.webex.internal.llm.setOwnerMeetingId?.(undefined, LLM_PRACTICE_SESSION);
489
- } else {
490
- LoggerProxy.logger.info(
491
- `Webinar:index#updatePSDataChannel --> skipping failure owner release; practice-session LLM owned by meeting ${currentOwnerAfterRegisterFailure}, not ${this.meetingId}`
492
- );
471
+ // Clean up the channel on failure, but only if it's still the current one
472
+ if (this._practiceSessionLLMChannel === psChannel) {
473
+ this._practiceSessionLLMChannel = undefined;
493
474
  }
494
-
495
475
  throw error;
496
476
  });
497
477
  },