@webex/internal-plugin-voicea 3.12.0-next.73 → 3.12.0-next.74

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.
package/src/voicea.ts CHANGED
@@ -1,19 +1,19 @@
1
+ import EventEmitter from 'events';
1
2
  import uuid from 'uuid';
2
- import {WebexPlugin, config} from '@webex/webex-core';
3
+ // @ts-ignore - webex-core types
4
+ import {config} from '@webex/webex-core';
3
5
 
6
+ // @ts-ignore - internal-plugin-llm types
7
+ import type LLMChannel from '@webex/internal-plugin-llm';
4
8
  import {
5
9
  EVENT_TRIGGERS,
6
10
  AIBRIDGE_RELAY_TYPES,
7
11
  TRANSCRIPTION_TYPE,
8
- VOICEA,
9
- LLM_PRACTICE_SESSION,
10
12
  ANNOUNCE_STATUS,
11
13
  TURN_ON_CAPTION_STATUS,
12
14
  TOGGLE_MANUAL_CAPTION_STATUS,
13
15
  DEFAULT_SPOKEN_LANGUAGE,
14
- LANGUAGE_ASSIGNMENT,
15
16
  } from './constants';
16
- // eslint-disable-next-line no-unused-vars
17
17
  import {
18
18
  AnnouncementPayload,
19
19
  CaptionLanguageResponse,
@@ -24,41 +24,88 @@ import {
24
24
  import {millisToMinutesAndSeconds} from './utils';
25
25
 
26
26
  /**
27
- * @description VoiceaChannel to hold single instance of LLM
27
+ * @description VoiceaChannel — handles voicea/transcription functionality for a single LLM connection.
28
+ * Created via `webex.internal.voicea.createChannel(llmChannel)`. The caller owns the
29
+ * channel and is responsible for its lifecycle.
28
30
  * @export
29
31
  * @class VoiceaChannel
30
32
  */
31
- export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
32
- namespace = VOICEA;
33
+ export class VoiceaChannel extends EventEmitter implements IVoiceaChannel {
34
+ private request: (options: {method: string; url: string; body?: object}) => Promise<any>;
35
+ private llmChannel?: LLMChannel;
33
36
 
34
37
  private seqNum: number;
35
-
36
38
  private areCaptionsEnabled: boolean;
37
-
38
39
  private hasSubscribedToEvents = false;
39
-
40
40
  private captionServiceId?: string;
41
-
42
41
  private announceStatus: string;
43
-
44
42
  private captionStatus: string;
45
43
 
46
44
  private keepTranscriptionSubscribed: boolean;
47
45
 
48
46
  private toggleManualCaptionStatus: string;
49
-
50
47
  private currentSpokenLanguage?: string;
51
-
52
48
  private spokenLanguages: string[] = [];
53
-
54
49
  private currentCaptionLanguage?: string;
55
50
 
51
+ // Target channel for reconciler pattern - the channel voicea WANTS to be bound to
52
+ private targetLLMChannel?: LLMChannel;
53
+ // Single pending 'online' listener for deferred reconciliation
54
+ private _pendingOnlineListener?: () => void;
55
+ // Tracks whether caption restoration is pending (set on switch, cleared on restore)
56
+ private _pendingCaptionRestore = false;
57
+
56
58
  /**
57
- * @param {Object} e
58
- * @returns {undefined}
59
+ * Creates a VoiceaChannel, optionally bound to an LLMChannel.
60
+ * If no llmChannel is provided, call switchLLMChannel() later to attach one.
61
+ * @param {LLMChannel} [llmChannel] - The LLM channel to use (optional)
62
+ * @param {Function} request - The request function for making API calls (typically webex.request bound to webex)
59
63
  */
64
+ constructor(
65
+ llmChannel: LLMChannel | undefined,
66
+ request: (options: {method: string; url: string; body?: object}) => Promise<any>
67
+ ) {
68
+ super();
69
+ this.llmChannel = llmChannel;
70
+ this.request = request;
71
+
72
+ this.seqNum = 1;
73
+ this.areCaptionsEnabled = false;
74
+ this.captionServiceId = undefined;
75
+ this.announceStatus = ANNOUNCE_STATUS.IDLE;
76
+ this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
77
+ this.toggleManualCaptionStatus = TOGGLE_MANUAL_CAPTION_STATUS.IDLE;
78
+ this.currentSpokenLanguage = DEFAULT_SPOKEN_LANGUAGE;
79
+ this.currentCaptionLanguage = undefined;
80
+ this.keepTranscriptionSubscribed = false;
81
+
82
+ // Subscribe to relay events from the LLM channel if provided
83
+ if (this.llmChannel) {
84
+ this.llmChannel.on('event:relay.event', this.eventProcessor);
85
+ this.hasSubscribedToEvents = true;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Returns the LLM channel, throwing if not available.
91
+ * @private
92
+ * @returns {LLMChannel}
93
+ * @throws {Error} If LLM channel is not available
94
+ */
95
+ private requireLLMChannel(): LLMChannel {
96
+ if (!this.llmChannel) {
97
+ throw new Error('VoiceaChannel: LLM channel not available');
98
+ }
99
+
100
+ return this.llmChannel;
101
+ }
60
102
 
61
- private eventProcessor = (e) => {
103
+ /**
104
+ * Process events from LLM channel
105
+ * @param {Object} e - Event data
106
+ * @returns {void}
107
+ */
108
+ private eventProcessor = (e: any): void => {
62
109
  this.seqNum = e.sequenceNumber + 1;
63
110
  switch (e.data.relayType) {
64
111
  case AIBRIDGE_RELAY_TYPES.VOICEA.ANNOUNCEMENT:
@@ -89,32 +136,24 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
89
136
  };
90
137
 
91
138
  /**
92
- * Listen to websocket messages
93
- * @returns {undefined}
94
- */
95
- private listenToEvents() {
96
- if (!this.hasSubscribedToEvents) {
97
- // @ts-ignore
98
- this.webex.internal.llm.on('event:relay.event', this.eventProcessor);
99
- // @ts-ignore
100
- this.webex.internal.llm.on(`event:relay.event:${LLM_PRACTICE_SESSION}`, this.eventProcessor);
101
- this.hasSubscribedToEvents = true;
102
- }
103
- }
104
-
105
- /**
106
- * Listen to websocket messages
139
+ * Deregister events and clean up
107
140
  * @returns {void}
108
141
  */
109
- public deregisterEvents() {
142
+ public deregisterEvents(): void {
110
143
  this.areCaptionsEnabled = false;
111
144
  this.keepTranscriptionSubscribed = false;
112
145
  this.captionServiceId = undefined;
113
- // @ts-ignore
114
- this.webex.internal.llm.off('event:relay.event', this.eventProcessor);
115
- // @ts-ignore
116
- this.webex.internal.llm.off(`event:relay.event:${LLM_PRACTICE_SESSION}`, this.eventProcessor);
117
- this.hasSubscribedToEvents = false;
146
+ this.targetLLMChannel = undefined;
147
+ this._pendingCaptionRestore = false;
148
+
149
+ // Remove any pending online listener
150
+ this.detachPendingOnline();
151
+
152
+ if (this.hasSubscribedToEvents) {
153
+ this.llmChannel?.off('event:relay.event', this.eventProcessor);
154
+ this.hasSubscribedToEvents = false;
155
+ }
156
+
118
157
  this.announceStatus = ANNOUNCE_STATUS.IDLE;
119
158
  this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
120
159
  this.toggleManualCaptionStatus = TOGGLE_MANUAL_CAPTION_STATUS.IDLE;
@@ -123,20 +162,101 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
123
162
  }
124
163
 
125
164
  /**
126
- * Initializes Voicea plugin
127
- * @param {any} args
165
+ * Attach a pending 'online' listener to a channel for deferred reconciliation.
166
+ * Detaches any existing listener first.
167
+ * @param {LLMChannel} channel - The channel to attach to
168
+ * @param {Function} callback - The callback to run when 'online' fires
169
+ * @private
170
+ * @returns {void}
128
171
  */
129
- constructor(...args) {
130
- super(...args);
131
- this.seqNum = 1;
132
- this.areCaptionsEnabled = false;
133
- this.keepTranscriptionSubscribed = false;
134
- this.captionServiceId = undefined;
172
+ private attachPendingOnline(channel: LLMChannel, callback: () => void): void {
173
+ this.detachPendingOnline();
174
+ this._pendingOnlineListener = callback;
175
+ channel.once('online', this._pendingOnlineListener);
176
+ }
177
+
178
+ /**
179
+ * Detach any pending 'online' listener.
180
+ * @private
181
+ * @returns {void}
182
+ */
183
+ private detachPendingOnline(): void {
184
+ if (this._pendingOnlineListener && this.llmChannel) {
185
+ this.llmChannel.off('online', this._pendingOnlineListener);
186
+ }
187
+ this._pendingOnlineListener = undefined;
188
+ }
189
+
190
+ /**
191
+ * Reset announcement state for a new connection.
192
+ * @private
193
+ * @returns {void}
194
+ */
195
+ private resetAnnounceState(): void {
135
196
  this.announceStatus = ANNOUNCE_STATUS.IDLE;
136
197
  this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
137
- this.toggleManualCaptionStatus = TOGGLE_MANUAL_CAPTION_STATUS.IDLE;
138
- this.currentSpokenLanguage = DEFAULT_SPOKEN_LANGUAGE;
139
- this.currentCaptionLanguage = undefined;
198
+ this.captionServiceId = undefined;
199
+ this.areCaptionsEnabled = false;
200
+ }
201
+
202
+ /**
203
+ * Reconcile voicea binding and caption state to match the desired target.
204
+ * This is idempotent - always re-reads targetLLMChannel and current state.
205
+ * A deferred 'online' callback that fires late self-corrects automatically.
206
+ * @private
207
+ * @returns {Promise<void>}
208
+ */
209
+ private reconcile(): Promise<void> {
210
+ const target = this.targetLLMChannel;
211
+ if (!target) return Promise.resolve();
212
+
213
+ // 1. Rebind relay-event subscription if actual != desired
214
+ if (this.llmChannel !== target) {
215
+ if (this.hasSubscribedToEvents && this.llmChannel) {
216
+ this.llmChannel.off('event:relay.event', this.eventProcessor);
217
+ }
218
+ this.detachPendingOnline();
219
+ this.llmChannel = target;
220
+ this.llmChannel.on('event:relay.event', this.eventProcessor);
221
+ this.hasSubscribedToEvents = true;
222
+ this.resetAnnounceState();
223
+ // Mark caption restoration as pending if captions were subscribed
224
+ this._pendingCaptionRestore = this.keepTranscriptionSubscribed;
225
+ }
226
+
227
+ // 2. Restore captions if pending
228
+ if (!this._pendingCaptionRestore) return Promise.resolve();
229
+
230
+ if (this.isLLMConnected()) {
231
+ // Channel is connected, restore captions immediately
232
+ this._pendingCaptionRestore = false;
233
+
234
+ return this.turnOnCaptions(this.currentSpokenLanguage)
235
+ .then(() => undefined)
236
+ .catch(() => {
237
+ // Best-effort restoration
238
+ });
239
+ }
240
+ // Channel not yet connected - defer until 'online' then re-reconcile.
241
+ // If target changes meanwhile, reconcile() self-corrects.
242
+ this.attachPendingOnline(target, () => {
243
+ this.reconcile();
244
+ });
245
+
246
+ return Promise.resolve();
247
+ }
248
+
249
+ /**
250
+ * Switch to a different LLM channel while preserving caption state.
251
+ * Used when transitioning between main meeting and practice session.
252
+ * This is a thin intent-setter - actual binding happens in reconcile().
253
+ * @param {LLMChannel} newLLMChannel - The new LLM channel to switch to
254
+ * @returns {Promise<void>}
255
+ */
256
+ public switchLLMChannel(newLLMChannel: LLMChannel): Promise<void> {
257
+ this.targetLLMChannel = newLLMChannel;
258
+
259
+ return this.reconcile();
140
260
  }
141
261
 
142
262
  /**
@@ -149,8 +269,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
149
269
  transcriptPayload.type === TRANSCRIPTION_TYPE.MANUAL_CAPTION_FINAL_RESULT ||
150
270
  transcriptPayload.type === TRANSCRIPTION_TYPE.MANUAL_CAPTION_INTERIM_RESULT
151
271
  ) {
152
- // @ts-ignore
153
- this.trigger(EVENT_TRIGGERS.NEW_MANUAL_CAPTION, {
272
+ this.emit(EVENT_TRIGGERS.NEW_MANUAL_CAPTION, {
154
273
  isFinal: transcriptPayload.type === TRANSCRIPTION_TYPE.MANUAL_CAPTION_FINAL_RESULT,
155
274
  transcriptId: transcriptPayload.id,
156
275
  transcripts: transcriptPayload.transcripts,
@@ -167,7 +286,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
167
286
  */
168
287
  private processSpeakerNameUpdate = (voiceaPayload: SpeakerNameUpdatePayload): void => {
169
288
  // @ts-ignore
170
- this.trigger(EVENT_TRIGGERS.SPEAKER_NAME_UPDATED, voiceaPayload);
289
+ this.emit(EVENT_TRIGGERS.SPEAKER_NAME_UPDATED, voiceaPayload);
171
290
  };
172
291
 
173
292
  /**
@@ -178,8 +297,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
178
297
  private processTranscription = (voiceaPayload: TranscriptionResponse): void => {
179
298
  switch (voiceaPayload.type) {
180
299
  case TRANSCRIPTION_TYPE.TRANSCRIPT_INTERIM_RESULTS:
181
- // @ts-ignore
182
- this.trigger(EVENT_TRIGGERS.NEW_CAPTION, {
300
+ this.emit(EVENT_TRIGGERS.NEW_CAPTION, {
183
301
  isFinal: false,
184
302
  transcriptId: voiceaPayload.transcript_id,
185
303
  transcripts: voiceaPayload.transcripts,
@@ -187,11 +305,10 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
187
305
  break;
188
306
 
189
307
  case TRANSCRIPTION_TYPE.TRANSCRIPT_FINAL_RESULT:
190
- // @ts-ignore
191
- this.trigger(EVENT_TRIGGERS.NEW_CAPTION, {
308
+ this.emit(EVENT_TRIGGERS.NEW_CAPTION, {
192
309
  isFinal: true,
193
310
  transcriptId: voiceaPayload.transcript_id,
194
- transcripts: voiceaPayload.transcripts.map((transcript) => {
311
+ transcripts: voiceaPayload.transcripts?.map((transcript) => {
195
312
  transcript.timestamp = millisToMinutesAndSeconds(transcript.end_millis);
196
313
 
197
314
  return transcript;
@@ -200,20 +317,18 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
200
317
  break;
201
318
 
202
319
  case TRANSCRIPTION_TYPE.HIGHLIGHT_CREATED:
203
- // @ts-ignore
204
- this.trigger(EVENT_TRIGGERS.HIGHLIGHT_CREATED, {
205
- csis: voiceaPayload.highlight.csis,
206
- highlightId: voiceaPayload.highlight.highlight_id,
207
- text: voiceaPayload.highlight.transcript,
208
- highlightLabel: voiceaPayload.highlight.highlight_label,
209
- highlightSource: voiceaPayload.highlight.highlight_source,
210
- timestamp: millisToMinutesAndSeconds(voiceaPayload.highlight.end_millis),
320
+ this.emit(EVENT_TRIGGERS.HIGHLIGHT_CREATED, {
321
+ csis: voiceaPayload.highlight?.csis,
322
+ highlightId: voiceaPayload.highlight?.highlight_id,
323
+ text: voiceaPayload.highlight?.transcript,
324
+ highlightLabel: voiceaPayload.highlight?.highlight_label,
325
+ highlightSource: voiceaPayload.highlight?.highlight_source,
326
+ timestamp: millisToMinutesAndSeconds(voiceaPayload.highlight?.end_millis ?? 0),
211
327
  });
212
328
  break;
213
329
 
214
330
  case TRANSCRIPTION_TYPE.EVA_THANKS:
215
- // @ts-ignore
216
- this.trigger(EVENT_TRIGGERS.EVA_COMMAND, {
331
+ this.emit(EVENT_TRIGGERS.EVA_COMMAND, {
217
332
  isListening: false,
218
333
  text: voiceaPayload.command_response,
219
334
  });
@@ -221,22 +336,18 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
221
336
 
222
337
  case TRANSCRIPTION_TYPE.EVA_WAKE:
223
338
  case TRANSCRIPTION_TYPE.EVA_CANCEL:
224
- // @ts-ignore
225
- this.trigger(EVENT_TRIGGERS.EVA_COMMAND, {
339
+ this.emit(EVENT_TRIGGERS.EVA_COMMAND, {
226
340
  isListening: voiceaPayload.type === TRANSCRIPTION_TYPE.EVA_WAKE,
227
341
  });
228
342
  break;
229
343
 
230
344
  case TRANSCRIPTION_TYPE.LANGUAGE_DETECTED: {
231
345
  const isInSpokenLanguages = this.spokenLanguages.includes(voiceaPayload.language);
232
-
233
346
  if (isInSpokenLanguages) {
234
- // @ts-ignore
235
- this.trigger(EVENT_TRIGGERS.LANGUAGE_DETECTED, {
347
+ this.emit(EVENT_TRIGGERS.LANGUAGE_DETECTED, {
236
348
  languageCode: voiceaPayload.language,
237
349
  });
238
350
  }
239
-
240
351
  break;
241
352
  }
242
353
  default:
@@ -251,11 +362,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
251
362
  */
252
363
  private processCaptionLanguageResponse = (voiceaPayload: CaptionLanguageResponse): void => {
253
364
  if (voiceaPayload.statusCode === 200) {
254
- // @ts-ignore
255
- this.trigger(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {statusCode: 200});
365
+ this.emit(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {statusCode: 200});
256
366
  } else {
257
- // @ts-ignore
258
- this.trigger(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
367
+ this.emit(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
259
368
  statusCode: voiceaPayload.errorCode,
260
369
  errorMessage: voiceaPayload.message,
261
370
  });
@@ -276,51 +385,28 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
276
385
  };
277
386
 
278
387
  this.spokenLanguages = voiceaPayload?.ASR?.spoken_languages ?? [];
279
- // @ts-ignore
280
- this.trigger(EVENT_TRIGGERS.VOICEA_ANNOUNCEMENT, voiceaLanguageOptions);
388
+ this.emit(EVENT_TRIGGERS.VOICEA_ANNOUNCEMENT, voiceaLanguageOptions);
281
389
  };
282
390
 
283
391
  /**
284
- * Indicates whether the default or practice-session LLM connection is active.
392
+ * Indicates whether the LLM channel is connected.
285
393
  * @returns {boolean}
286
394
  */
287
- private isLLMConnected = (): boolean =>
288
- // @ts-ignore
289
- this.webex.internal.llm.isConnected() ||
290
- // @ts-ignore
291
- this.webex.internal.llm.isConnected(LLM_PRACTICE_SESSION);
395
+ public isLLMConnected = (): boolean => this.llmChannel?.isConnected() ?? false;
292
396
 
293
397
  public getKeepTranscriptionSubscribed = (): boolean => this.keepTranscriptionSubscribed;
294
398
 
295
- /**
296
- * Resolves the active LLM publish transport, preferring the practice-session
297
- * connection only when that session is fully connected.
298
- * @returns {Object}
299
- */
300
- private getPublishTransport = () => {
301
- // @ts-ignore
302
- const {llm} = this.webex.internal;
303
- const isPracticeSessionConnected = llm.isConnected(LLM_PRACTICE_SESSION);
304
-
305
- return {
306
- socket: (isPracticeSessionConnected && llm.getSocket(LLM_PRACTICE_SESSION)) || llm.socket,
307
- binding:
308
- (isPracticeSessionConnected && llm.getBinding(LLM_PRACTICE_SESSION)) || llm.getBinding(),
309
- datachannelUrl:
310
- (isPracticeSessionConnected && llm.getDatachannelUrl(LLM_PRACTICE_SESSION)) ||
311
- llm.getDatachannelUrl(),
312
- };
313
- };
314
-
315
399
  /**
316
400
  * Sends Announcement to add voicea to the meeting
317
401
  * @returns {void}
318
402
  */
319
- private sendAnnouncement = (): void => {
403
+ public sendAnnouncement = (): void => {
404
+ const llm = this.requireLLMChannel();
320
405
  this.announceStatus = ANNOUNCE_STATUS.JOINING;
321
- this.listenToEvents();
322
- const {socket, binding} = this.getPublishTransport();
323
- socket.send({
406
+ const socket = llm.getSocket();
407
+ const binding = llm.getBinding();
408
+
409
+ const payload = {
324
410
  id: `${this.seqNum}`,
325
411
  type: 'publishRequest',
326
412
  recipients: [
@@ -338,7 +424,8 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
338
424
  relayType: AIBRIDGE_RELAY_TYPES.VOICEA.CLIENT_ANNOUNCEMENT,
339
425
  },
340
426
  trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
341
- });
427
+ };
428
+ socket.send(payload);
342
429
  this.seqNum += 1;
343
430
  };
344
431
 
@@ -352,11 +439,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
352
439
  languageCode: string,
353
440
  languageAssignment?: 'DEFAULT' | 'AUTO' | 'MANUAL'
354
441
  ): Promise<void> =>
355
- // @ts-ignore
356
442
  this.request({
357
443
  method: 'PUT',
358
- // @ts-ignore
359
- url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
444
+ url: `${this.requireLLMChannel().getLocusUrl()}/controls/`,
360
445
  body: {
361
446
  transcribe: {
362
447
  spokenLanguage: languageCode,
@@ -364,8 +449,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
364
449
  },
365
450
  },
366
451
  }).then(() => {
367
- // @ts-ignore
368
- this.trigger(EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {languageCode});
452
+ this.emit(EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {languageCode});
369
453
  });
370
454
 
371
455
  /**
@@ -378,7 +462,10 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
378
462
  return;
379
463
  }
380
464
 
381
- const {socket, binding} = this.getPublishTransport();
465
+ const llm = this.requireLLMChannel();
466
+ const socket = llm.getSocket();
467
+ const binding = llm.getBinding();
468
+
382
469
  socket.send({
383
470
  id: `${this.seqNum}`,
384
471
  type: 'publishRequest',
@@ -401,7 +488,6 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
401
488
  trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
402
489
  });
403
490
  this.currentCaptionLanguage = languageCode;
404
-
405
491
  this.seqNum += 1;
406
492
  };
407
493
 
@@ -423,7 +509,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
423
509
  return;
424
510
  }
425
511
 
426
- const {socket, binding} = this.getPublishTransport();
512
+ const llm = this.requireLLMChannel();
513
+ const socket = llm.getSocket();
514
+ const binding = llm.getBinding();
427
515
 
428
516
  socket?.send({
429
517
  id: `${this.seqNum}`,
@@ -460,38 +548,35 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
460
548
 
461
549
  /**
462
550
  * request turn on Captions
463
- * @param {string} [languageCode] - Optional Parameter for spoken language code. Defaults to English
551
+ * @param {string} [languageCode] - Optional Parameter for spoken language code
464
552
  * @returns {Promise}
465
553
  */
466
- private requestTurnOnCaptions = (languageCode?): undefined | Promise<void> => {
554
+ private requestTurnOnCaptions = (languageCode?: string): undefined | Promise<void> => {
467
555
  this.captionStatus = TURN_ON_CAPTION_STATUS.SENDING;
468
556
 
469
- // only set the spoken language if it is provided
557
+ const locusUrl = this.requireLLMChannel().getLocusUrl();
558
+
470
559
  const body = {
471
560
  transcribe: {caption: true},
472
561
  languageCode,
473
562
  };
474
563
 
475
- // @ts-ignore
476
- // eslint-disable-next-line newline-before-return
477
564
  return this.request({
478
565
  method: 'PUT',
479
- // @ts-ignore
480
- url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
566
+ url: `${locusUrl}/controls/`,
481
567
  body,
482
568
  })
483
569
  .then(() => {
484
- // @ts-ignore
485
- this.trigger(EVENT_TRIGGERS.CAPTIONS_TURNED_ON);
570
+ this.emit(EVENT_TRIGGERS.CAPTIONS_TURNED_ON);
486
571
 
487
572
  this.areCaptionsEnabled = true;
488
573
  this.captionStatus = TURN_ON_CAPTION_STATUS.ENABLED;
489
574
  this.announce();
490
575
  this.updateSubchannelSubscriptionsAndSyncCaptionState({subscribe: ['transcription']}, true);
491
576
  })
492
- .catch(() => {
577
+ .catch((error) => {
493
578
  this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
494
- throw new Error('turn on captions fail');
579
+ throw new Error('turn on captions fail', {cause: error});
495
580
  });
496
581
  };
497
582
 
@@ -499,20 +584,20 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
499
584
  * is announce processing
500
585
  * @returns {boolean}
501
586
  */
502
- private isAnnounceProcessing = () =>
587
+ private isAnnounceProcessing = (): boolean =>
503
588
  [ANNOUNCE_STATUS.JOINING, ANNOUNCE_STATUS.JOINED].includes(this.announceStatus);
504
589
 
505
590
  /**
506
591
  * is announce processed
507
592
  * @returns {boolean}
508
593
  */
509
- private isAnnounceProcessed = () => this.announceStatus === ANNOUNCE_STATUS.JOINED;
594
+ private isAnnounceProcessed = (): boolean => this.announceStatus === ANNOUNCE_STATUS.JOINED;
510
595
 
511
596
  /**
512
- * announce to voicea data chanel
597
+ * announce to voicea data channel
513
598
  * @returns {void}
514
599
  */
515
- public announce = () => {
600
+ public announce = (): void => {
516
601
  if (this.isAnnounceProcessed()) {
517
602
  return;
518
603
  }
@@ -526,7 +611,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
526
611
  * is turn on caption processing
527
612
  * @returns {boolean}
528
613
  */
529
- private isCaptionProcessing = () =>
614
+ private isCaptionProcessing = (): boolean =>
530
615
  [TURN_ON_CAPTION_STATUS.SENDING, TURN_ON_CAPTION_STATUS.ENABLED].includes(this.captionStatus);
531
616
 
532
617
  /**
@@ -534,8 +619,8 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
534
619
  * @param {string} [spokenLanguage] - Optional Spoken language code
535
620
  * @returns {Promise}
536
621
  */
537
- public turnOnCaptions = async (spokenLanguage?): undefined | Promise<void> => {
538
- if (this.captionStatus === TURN_ON_CAPTION_STATUS.SENDING) return undefined;
622
+ public turnOnCaptions = async (spokenLanguage?: string): Promise<void | undefined> => {
623
+ if (this.isCaptionProcessing()) return undefined;
539
624
 
540
625
  if (!this.isLLMConnected()) {
541
626
  throw new Error('can not turn on captions before llm connected');
@@ -554,11 +639,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
554
639
  activate: boolean,
555
640
  spokenLanguage?: string
556
641
  ): undefined | Promise<void> => {
557
- // @ts-ignore
558
642
  return this.request({
559
643
  method: 'PUT',
560
- // @ts-ignore
561
- url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
644
+ url: `${this.requireLLMChannel().getLocusUrl()}/controls/`,
562
645
  body: {
563
646
  transcribe: {
564
647
  transcribing: activate,
@@ -584,11 +667,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
584
667
 
585
668
  this.toggleManualCaptionStatus = TOGGLE_MANUAL_CAPTION_STATUS.SENDING;
586
669
 
587
- // @ts-ignore
588
670
  return this.request({
589
671
  method: 'PUT',
590
- // @ts-ignore
591
- url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
672
+ url: `${this.requireLLMChannel().getLocusUrl()}/controls/`,
592
673
  body: {
593
674
  manualCaption: {
594
675
  enable,
@@ -612,9 +693,8 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
612
693
  * @param {string} meetingId
613
694
  * @returns {void}
614
695
  */
615
- public onSpokenLanguageUpdate = (languageCode: string, meetingId): void => {
616
- // @ts-ignore
617
- this.trigger(EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {languageCode, meetingId});
696
+ public onSpokenLanguageUpdate = (languageCode: string, meetingId: string): void => {
697
+ this.emit(EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {languageCode, meetingId});
618
698
  this.currentSpokenLanguage = languageCode;
619
699
  };
620
700
 
@@ -629,7 +709,6 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
629
709
  }
630
710
  if (this.captionServiceId !== serviceId) {
631
711
  this.captionServiceId = serviceId;
632
- // if service id value has changed and the translation language has been set, client needs to resend the translator language message to the LLM.
633
712
  if (this.currentCaptionLanguage) {
634
713
  this.requestLanguage(this.currentCaptionLanguage);
635
714
  }
@@ -640,19 +719,17 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
640
719
  * get caption status
641
720
  * @returns {string}
642
721
  */
643
- public getCaptionStatus = () => this.captionStatus;
722
+ public getCaptionStatus = (): string => this.captionStatus;
644
723
 
645
724
  /**
646
725
  * get announce status
647
726
  * @returns {string}
648
727
  */
649
- public getAnnounceStatus = () => this.announceStatus;
728
+ public getAnnounceStatus = (): string => this.announceStatus;
729
+
650
730
  /**
651
731
  * update LLM sub‑channel subscriptions.
652
732
  *
653
- * sends a single `subchannelSubscriptionRequest` to LLM,
654
- * allowing subscribe and unsubscribe subchannel.
655
- *
656
733
  * @param {string[]} options.subscribe Sub‑channels to subscribe to.
657
734
  * @param {string[]} options.unsubscribe Sub‑channels to unsubscribe from.
658
735
  * @returns {Promise}
@@ -664,19 +741,19 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
664
741
  subscribe?: string[];
665
742
  unsubscribe?: string[];
666
743
  } = {}): Promise<void> => {
667
- // @ts-ignore
668
- const isDataChannelTokenEnabled = await this.webex.internal.llm.isDataChannelTokenEnabled();
669
- // @ts-ignore
670
- if (!this.isLLMConnected() || !isDataChannelTokenEnabled) return;
744
+ if (!this.isLLMConnected()) return;
671
745
 
672
- const {socket, datachannelUrl} = this.getPublishTransport();
746
+ const llm = this.requireLLMChannel();
747
+ const isDataChannelTokenEnabled = await llm.isDataChannelTokenEnabled();
748
+ if (!isDataChannelTokenEnabled) return;
749
+
750
+ const socket = llm.getSocket();
751
+ const datachannelUrl = llm.getDatachannelUrl();
673
752
 
674
- // @ts-ignore
675
753
  socket.send({
676
754
  id: `${this.seqNum}`,
677
755
  type: 'subchannelSubscriptionRequest',
678
756
  data: {
679
- // @ts-ignore
680
757
  datachannelUri: datachannelUrl,
681
758
  subscribe,
682
759
  unsubscribe,