@webex/internal-plugin-voicea 3.12.0-next.72 → 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/dist/voicea.js CHANGED
@@ -12,6 +12,7 @@ _Object$defineProperty(exports, "__esModule", {
12
12
  value: true
13
13
  });
14
14
  exports.default = exports.VoiceaChannel = void 0;
15
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
15
16
  var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
16
17
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
17
18
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
@@ -20,6 +21,7 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
20
21
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
21
22
  var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
22
23
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
24
+ var _events = _interopRequireDefault(require("events"));
23
25
  var _uuid = _interopRequireDefault(require("uuid"));
24
26
  var _webexCore = require("@webex/webex-core");
25
27
  var _constants = require("./constants");
@@ -27,25 +29,28 @@ var _utils = require("./utils");
27
29
  function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
28
30
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
29
31
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
30
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } // eslint-disable-next-line no-unused-vars
32
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } // @ts-ignore - webex-core types
33
+ // @ts-ignore - internal-plugin-llm types
31
34
  /**
32
- * @description VoiceaChannel to hold single instance of LLM
35
+ * @description VoiceaChannel — handles voicea/transcription functionality for a single LLM connection.
36
+ * Created via `webex.internal.voicea.createChannel(llmChannel)`. The caller owns the
37
+ * channel and is responsible for its lifecycle.
33
38
  * @export
34
39
  * @class VoiceaChannel
35
40
  */
36
- var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin) {
41
+ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_EventEmitter) {
37
42
  /**
38
- * Initializes Voicea plugin
39
- * @param {any} args
43
+ * Creates a VoiceaChannel, optionally bound to an LLMChannel.
44
+ * If no llmChannel is provided, call switchLLMChannel() later to attach one.
45
+ * @param {LLMChannel} [llmChannel] - The LLM channel to use (optional)
46
+ * @param {Function} request - The request function for making API calls (typically webex.request bound to webex)
40
47
  */
41
- function VoiceaChannel() {
48
+ function VoiceaChannel(llmChannel, request) {
42
49
  var _this;
43
50
  (0, _classCallCheck2.default)(this, VoiceaChannel);
44
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
- args[_key] = arguments[_key];
46
- }
47
- _this = _callSuper(this, VoiceaChannel, [].concat(args));
48
- (0, _defineProperty2.default)(_this, "namespace", _constants.VOICEA);
51
+ _this = _callSuper(this, VoiceaChannel);
52
+ (0, _defineProperty2.default)(_this, "request", void 0);
53
+ (0, _defineProperty2.default)(_this, "llmChannel", void 0);
49
54
  (0, _defineProperty2.default)(_this, "seqNum", void 0);
50
55
  (0, _defineProperty2.default)(_this, "areCaptionsEnabled", void 0);
51
56
  (0, _defineProperty2.default)(_this, "hasSubscribedToEvents", false);
@@ -57,9 +62,16 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
57
62
  (0, _defineProperty2.default)(_this, "currentSpokenLanguage", void 0);
58
63
  (0, _defineProperty2.default)(_this, "spokenLanguages", []);
59
64
  (0, _defineProperty2.default)(_this, "currentCaptionLanguage", void 0);
65
+ // Target channel for reconciler pattern - the channel voicea WANTS to be bound to
66
+ (0, _defineProperty2.default)(_this, "targetLLMChannel", void 0);
67
+ // Single pending 'online' listener for deferred reconciliation
68
+ (0, _defineProperty2.default)(_this, "_pendingOnlineListener", void 0);
69
+ // Tracks whether caption restoration is pending (set on switch, cleared on restore)
70
+ (0, _defineProperty2.default)(_this, "_pendingCaptionRestore", false);
60
71
  /**
61
- * @param {Object} e
62
- * @returns {undefined}
72
+ * Process events from LLM channel
73
+ * @param {Object} e - Event data
74
+ * @returns {void}
63
75
  */
64
76
  (0, _defineProperty2.default)(_this, "eventProcessor", function (e) {
65
77
  var _e$headers;
@@ -97,8 +109,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
97
109
  */
98
110
  (0, _defineProperty2.default)(_this, "processManualTranscription", function (transcriptPayload) {
99
111
  if (transcriptPayload.type === _constants.TRANSCRIPTION_TYPE.MANUAL_CAPTION_FINAL_RESULT || transcriptPayload.type === _constants.TRANSCRIPTION_TYPE.MANUAL_CAPTION_INTERIM_RESULT) {
100
- // @ts-ignore
101
- _this.trigger(_constants.EVENT_TRIGGERS.NEW_MANUAL_CAPTION, {
112
+ _this.emit(_constants.EVENT_TRIGGERS.NEW_MANUAL_CAPTION, {
102
113
  isFinal: transcriptPayload.type === _constants.TRANSCRIPTION_TYPE.MANUAL_CAPTION_FINAL_RESULT,
103
114
  transcriptId: transcriptPayload.id,
104
115
  transcripts: transcriptPayload.transcripts,
@@ -114,7 +125,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
114
125
  */
115
126
  (0, _defineProperty2.default)(_this, "processSpeakerNameUpdate", function (voiceaPayload) {
116
127
  // @ts-ignore
117
- _this.trigger(_constants.EVENT_TRIGGERS.SPEAKER_NAME_UPDATED, voiceaPayload);
128
+ _this.emit(_constants.EVENT_TRIGGERS.SPEAKER_NAME_UPDATED, voiceaPayload);
118
129
  });
119
130
  /**
120
131
  * Process Transcript and send alert
@@ -122,48 +133,44 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
122
133
  * @returns {void}
123
134
  */
124
135
  (0, _defineProperty2.default)(_this, "processTranscription", function (voiceaPayload) {
136
+ var _voiceaPayload$transc, _voiceaPayload$highli, _voiceaPayload$highli2, _voiceaPayload$highli3, _voiceaPayload$highli4, _voiceaPayload$highli5, _voiceaPayload$highli6, _voiceaPayload$highli7;
125
137
  switch (voiceaPayload.type) {
126
138
  case _constants.TRANSCRIPTION_TYPE.TRANSCRIPT_INTERIM_RESULTS:
127
- // @ts-ignore
128
- _this.trigger(_constants.EVENT_TRIGGERS.NEW_CAPTION, {
139
+ _this.emit(_constants.EVENT_TRIGGERS.NEW_CAPTION, {
129
140
  isFinal: false,
130
141
  transcriptId: voiceaPayload.transcript_id,
131
142
  transcripts: voiceaPayload.transcripts
132
143
  });
133
144
  break;
134
145
  case _constants.TRANSCRIPTION_TYPE.TRANSCRIPT_FINAL_RESULT:
135
- // @ts-ignore
136
- _this.trigger(_constants.EVENT_TRIGGERS.NEW_CAPTION, {
146
+ _this.emit(_constants.EVENT_TRIGGERS.NEW_CAPTION, {
137
147
  isFinal: true,
138
148
  transcriptId: voiceaPayload.transcript_id,
139
- transcripts: voiceaPayload.transcripts.map(function (transcript) {
149
+ transcripts: (_voiceaPayload$transc = voiceaPayload.transcripts) === null || _voiceaPayload$transc === void 0 ? void 0 : _voiceaPayload$transc.map(function (transcript) {
140
150
  transcript.timestamp = (0, _utils.millisToMinutesAndSeconds)(transcript.end_millis);
141
151
  return transcript;
142
152
  })
143
153
  });
144
154
  break;
145
155
  case _constants.TRANSCRIPTION_TYPE.HIGHLIGHT_CREATED:
146
- // @ts-ignore
147
- _this.trigger(_constants.EVENT_TRIGGERS.HIGHLIGHT_CREATED, {
148
- csis: voiceaPayload.highlight.csis,
149
- highlightId: voiceaPayload.highlight.highlight_id,
150
- text: voiceaPayload.highlight.transcript,
151
- highlightLabel: voiceaPayload.highlight.highlight_label,
152
- highlightSource: voiceaPayload.highlight.highlight_source,
153
- timestamp: (0, _utils.millisToMinutesAndSeconds)(voiceaPayload.highlight.end_millis)
156
+ _this.emit(_constants.EVENT_TRIGGERS.HIGHLIGHT_CREATED, {
157
+ csis: (_voiceaPayload$highli = voiceaPayload.highlight) === null || _voiceaPayload$highli === void 0 ? void 0 : _voiceaPayload$highli.csis,
158
+ highlightId: (_voiceaPayload$highli2 = voiceaPayload.highlight) === null || _voiceaPayload$highli2 === void 0 ? void 0 : _voiceaPayload$highli2.highlight_id,
159
+ text: (_voiceaPayload$highli3 = voiceaPayload.highlight) === null || _voiceaPayload$highli3 === void 0 ? void 0 : _voiceaPayload$highli3.transcript,
160
+ highlightLabel: (_voiceaPayload$highli4 = voiceaPayload.highlight) === null || _voiceaPayload$highli4 === void 0 ? void 0 : _voiceaPayload$highli4.highlight_label,
161
+ highlightSource: (_voiceaPayload$highli5 = voiceaPayload.highlight) === null || _voiceaPayload$highli5 === void 0 ? void 0 : _voiceaPayload$highli5.highlight_source,
162
+ timestamp: (0, _utils.millisToMinutesAndSeconds)((_voiceaPayload$highli6 = (_voiceaPayload$highli7 = voiceaPayload.highlight) === null || _voiceaPayload$highli7 === void 0 ? void 0 : _voiceaPayload$highli7.end_millis) !== null && _voiceaPayload$highli6 !== void 0 ? _voiceaPayload$highli6 : 0)
154
163
  });
155
164
  break;
156
165
  case _constants.TRANSCRIPTION_TYPE.EVA_THANKS:
157
- // @ts-ignore
158
- _this.trigger(_constants.EVENT_TRIGGERS.EVA_COMMAND, {
166
+ _this.emit(_constants.EVENT_TRIGGERS.EVA_COMMAND, {
159
167
  isListening: false,
160
168
  text: voiceaPayload.command_response
161
169
  });
162
170
  break;
163
171
  case _constants.TRANSCRIPTION_TYPE.EVA_WAKE:
164
172
  case _constants.TRANSCRIPTION_TYPE.EVA_CANCEL:
165
- // @ts-ignore
166
- _this.trigger(_constants.EVENT_TRIGGERS.EVA_COMMAND, {
173
+ _this.emit(_constants.EVENT_TRIGGERS.EVA_COMMAND, {
167
174
  isListening: voiceaPayload.type === _constants.TRANSCRIPTION_TYPE.EVA_WAKE
168
175
  });
169
176
  break;
@@ -171,8 +178,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
171
178
  {
172
179
  var isInSpokenLanguages = _this.spokenLanguages.includes(voiceaPayload.language);
173
180
  if (isInSpokenLanguages) {
174
- // @ts-ignore
175
- _this.trigger(_constants.EVENT_TRIGGERS.LANGUAGE_DETECTED, {
181
+ _this.emit(_constants.EVENT_TRIGGERS.LANGUAGE_DETECTED, {
176
182
  languageCode: voiceaPayload.language
177
183
  });
178
184
  }
@@ -189,13 +195,11 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
189
195
  */
190
196
  (0, _defineProperty2.default)(_this, "processCaptionLanguageResponse", function (voiceaPayload) {
191
197
  if (voiceaPayload.statusCode === 200) {
192
- // @ts-ignore
193
- _this.trigger(_constants.EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
198
+ _this.emit(_constants.EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
194
199
  statusCode: 200
195
200
  });
196
201
  } else {
197
- // @ts-ignore
198
- _this.trigger(_constants.EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
202
+ _this.emit(_constants.EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
199
203
  statusCode: voiceaPayload.errorCode,
200
204
  errorMessage: voiceaPayload.message
201
205
  });
@@ -215,50 +219,29 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
215
219
  currentSpokenLanguage: _this.currentSpokenLanguage
216
220
  };
217
221
  _this.spokenLanguages = (_voiceaPayload$ASR$sp2 = voiceaPayload === null || voiceaPayload === void 0 ? void 0 : (_voiceaPayload$ASR2 = voiceaPayload.ASR) === null || _voiceaPayload$ASR2 === void 0 ? void 0 : _voiceaPayload$ASR2.spoken_languages) !== null && _voiceaPayload$ASR$sp2 !== void 0 ? _voiceaPayload$ASR$sp2 : [];
218
- // @ts-ignore
219
- _this.trigger(_constants.EVENT_TRIGGERS.VOICEA_ANNOUNCEMENT, voiceaLanguageOptions);
222
+ _this.emit(_constants.EVENT_TRIGGERS.VOICEA_ANNOUNCEMENT, voiceaLanguageOptions);
220
223
  });
221
224
  /**
222
- * Indicates whether the default or practice-session LLM connection is active.
225
+ * Indicates whether the LLM channel is connected.
223
226
  * @returns {boolean}
224
227
  */
225
228
  (0, _defineProperty2.default)(_this, "isLLMConnected", function () {
226
- return (
227
- // @ts-ignore
228
- _this.webex.internal.llm.isConnected() ||
229
- // @ts-ignore
230
- _this.webex.internal.llm.isConnected(_constants.LLM_PRACTICE_SESSION)
231
- );
229
+ var _this$llmChannel$isCo, _this$llmChannel;
230
+ return (_this$llmChannel$isCo = (_this$llmChannel = _this.llmChannel) === null || _this$llmChannel === void 0 ? void 0 : _this$llmChannel.isConnected()) !== null && _this$llmChannel$isCo !== void 0 ? _this$llmChannel$isCo : false;
232
231
  });
233
232
  (0, _defineProperty2.default)(_this, "getKeepTranscriptionSubscribed", function () {
234
233
  return _this.keepTranscriptionSubscribed;
235
234
  });
236
- /**
237
- * Resolves the active LLM publish transport, preferring the practice-session
238
- * connection only when that session is fully connected.
239
- * @returns {Object}
240
- */
241
- (0, _defineProperty2.default)(_this, "getPublishTransport", function () {
242
- // @ts-ignore
243
- var llm = _this.webex.internal.llm;
244
- var isPracticeSessionConnected = llm.isConnected(_constants.LLM_PRACTICE_SESSION);
245
- return {
246
- socket: isPracticeSessionConnected && llm.getSocket(_constants.LLM_PRACTICE_SESSION) || llm.socket,
247
- binding: isPracticeSessionConnected && llm.getBinding(_constants.LLM_PRACTICE_SESSION) || llm.getBinding(),
248
- datachannelUrl: isPracticeSessionConnected && llm.getDatachannelUrl(_constants.LLM_PRACTICE_SESSION) || llm.getDatachannelUrl()
249
- };
250
- });
251
235
  /**
252
236
  * Sends Announcement to add voicea to the meeting
253
237
  * @returns {void}
254
238
  */
255
239
  (0, _defineProperty2.default)(_this, "sendAnnouncement", function () {
240
+ var llm = _this.requireLLMChannel();
256
241
  _this.announceStatus = _constants.ANNOUNCE_STATUS.JOINING;
257
- _this.listenToEvents();
258
- var _this$getPublishTrans = _this.getPublishTransport(),
259
- socket = _this$getPublishTrans.socket,
260
- binding = _this$getPublishTrans.binding;
261
- socket.send({
242
+ var socket = llm.getSocket();
243
+ var binding = llm.getBinding();
244
+ var payload = {
262
245
  id: "".concat(_this.seqNum),
263
246
  type: 'publishRequest',
264
247
  recipients: [{
@@ -276,7 +259,8 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
276
259
  relayType: _constants.AIBRIDGE_RELAY_TYPES.VOICEA.CLIENT_ANNOUNCEMENT
277
260
  },
278
261
  trackingId: "".concat(_webexCore.config.trackingIdPrefix, "_").concat(_uuid.default.v4().toString())
279
- });
262
+ };
263
+ socket.send(payload);
280
264
  _this.seqNum += 1;
281
265
  });
282
266
  /**
@@ -286,26 +270,21 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
286
270
  * @returns {Promise}
287
271
  */
288
272
  (0, _defineProperty2.default)(_this, "setSpokenLanguage", function (languageCode, languageAssignment) {
289
- return (
290
- // @ts-ignore
291
- _this.request({
292
- method: 'PUT',
293
- // @ts-ignore
294
- url: "".concat(_this.webex.internal.llm.getLocusUrl(), "/controls/"),
295
- body: {
296
- transcribe: _objectSpread({
297
- spokenLanguage: languageCode
298
- }, languageAssignment && {
299
- languageAssignment: languageAssignment
300
- })
301
- }
302
- }).then(function () {
303
- // @ts-ignore
304
- _this.trigger(_constants.EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {
305
- languageCode: languageCode
306
- });
307
- })
308
- );
273
+ return _this.request({
274
+ method: 'PUT',
275
+ url: "".concat(_this.requireLLMChannel().getLocusUrl(), "/controls/"),
276
+ body: {
277
+ transcribe: _objectSpread({
278
+ spokenLanguage: languageCode
279
+ }, languageAssignment && {
280
+ languageAssignment: languageAssignment
281
+ })
282
+ }
283
+ }).then(function () {
284
+ _this.emit(_constants.EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {
285
+ languageCode: languageCode
286
+ });
287
+ });
309
288
  });
310
289
  /**
311
290
  * Request Language translation
@@ -316,9 +295,9 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
316
295
  if (!_this.isLLMConnected()) {
317
296
  return;
318
297
  }
319
- var _this$getPublishTrans2 = _this.getPublishTransport(),
320
- socket = _this$getPublishTrans2.socket,
321
- binding = _this$getPublishTrans2.binding;
298
+ var llm = _this.requireLLMChannel();
299
+ var socket = llm.getSocket();
300
+ var binding = llm.getBinding();
322
301
  socket.send({
323
302
  id: "".concat(_this.seqNum),
324
303
  type: 'publishRequest',
@@ -353,9 +332,9 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
353
332
  if (!_this.isLLMConnected()) {
354
333
  return;
355
334
  }
356
- var _this$getPublishTrans3 = _this.getPublishTransport(),
357
- socket = _this$getPublishTrans3.socket,
358
- binding = _this$getPublishTrans3.binding;
335
+ var llm = _this.requireLLMChannel();
336
+ var socket = llm.getSocket();
337
+ var binding = llm.getBinding();
359
338
  socket === null || socket === void 0 ? void 0 : socket.send({
360
339
  id: "".concat(_this.seqNum),
361
340
  type: 'publishRequest',
@@ -384,39 +363,35 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
384
363
  });
385
364
  /**
386
365
  * request turn on Captions
387
- * @param {string} [languageCode] - Optional Parameter for spoken language code. Defaults to English
366
+ * @param {string} [languageCode] - Optional Parameter for spoken language code
388
367
  * @returns {Promise}
389
368
  */
390
369
  (0, _defineProperty2.default)(_this, "requestTurnOnCaptions", function (languageCode) {
391
370
  _this.captionStatus = _constants.TURN_ON_CAPTION_STATUS.SENDING;
392
-
393
- // only set the spoken language if it is provided
371
+ var locusUrl = _this.requireLLMChannel().getLocusUrl();
394
372
  var body = {
395
373
  transcribe: {
396
374
  caption: true
397
375
  },
398
376
  languageCode: languageCode
399
377
  };
400
-
401
- // @ts-ignore
402
- // eslint-disable-next-line newline-before-return
403
378
  return _this.request({
404
379
  method: 'PUT',
405
- // @ts-ignore
406
- url: "".concat(_this.webex.internal.llm.getLocusUrl(), "/controls/"),
380
+ url: "".concat(locusUrl, "/controls/"),
407
381
  body: body
408
382
  }).then(function () {
409
- // @ts-ignore
410
- _this.trigger(_constants.EVENT_TRIGGERS.CAPTIONS_TURNED_ON);
383
+ _this.emit(_constants.EVENT_TRIGGERS.CAPTIONS_TURNED_ON);
411
384
  _this.areCaptionsEnabled = true;
412
385
  _this.captionStatus = _constants.TURN_ON_CAPTION_STATUS.ENABLED;
413
386
  _this.announce();
414
387
  _this.updateSubchannelSubscriptionsAndSyncCaptionState({
415
388
  subscribe: ['transcription']
416
389
  }, true);
417
- }).catch(function () {
390
+ }).catch(function (error) {
418
391
  _this.captionStatus = _constants.TURN_ON_CAPTION_STATUS.IDLE;
419
- throw new Error('turn on captions fail');
392
+ throw new Error('turn on captions fail', {
393
+ cause: error
394
+ });
420
395
  });
421
396
  });
422
397
  /**
@@ -434,7 +409,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
434
409
  return _this.announceStatus === _constants.ANNOUNCE_STATUS.JOINED;
435
410
  });
436
411
  /**
437
- * announce to voicea data chanel
412
+ * announce to voicea data channel
438
413
  * @returns {void}
439
414
  */
440
415
  (0, _defineProperty2.default)(_this, "announce", function () {
@@ -463,7 +438,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
463
438
  return _regenerator.default.wrap(function (_context) {
464
439
  while (1) switch (_context.prev = _context.next) {
465
440
  case 0:
466
- if (!(_this.captionStatus === _constants.TURN_ON_CAPTION_STATUS.SENDING)) {
441
+ if (!_this.isCaptionProcessing()) {
467
442
  _context.next = 1;
468
443
  break;
469
444
  }
@@ -493,11 +468,9 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
493
468
  * @returns {Promise}
494
469
  */
495
470
  (0, _defineProperty2.default)(_this, "toggleTranscribing", function (activate, spokenLanguage) {
496
- // @ts-ignore
497
471
  return _this.request({
498
472
  method: 'PUT',
499
- // @ts-ignore
500
- url: "".concat(_this.webex.internal.llm.getLocusUrl(), "/controls/"),
473
+ url: "".concat(_this.requireLLMChannel().getLocusUrl(), "/controls/"),
501
474
  body: {
502
475
  transcribe: {
503
476
  transcribing: activate
@@ -519,12 +492,9 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
519
492
  (0, _defineProperty2.default)(_this, "toggleManualCaption", function (enable) {
520
493
  if (_this.toggleManualCaptionStatus === _constants.TOGGLE_MANUAL_CAPTION_STATUS.SENDING) return undefined;
521
494
  _this.toggleManualCaptionStatus = _constants.TOGGLE_MANUAL_CAPTION_STATUS.SENDING;
522
-
523
- // @ts-ignore
524
495
  return _this.request({
525
496
  method: 'PUT',
526
- // @ts-ignore
527
- url: "".concat(_this.webex.internal.llm.getLocusUrl(), "/controls/"),
497
+ url: "".concat(_this.requireLLMChannel().getLocusUrl(), "/controls/"),
528
498
  body: {
529
499
  manualCaption: {
530
500
  enable: enable
@@ -545,8 +515,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
545
515
  * @returns {void}
546
516
  */
547
517
  (0, _defineProperty2.default)(_this, "onSpokenLanguageUpdate", function (languageCode, meetingId) {
548
- // @ts-ignore
549
- _this.trigger(_constants.EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {
518
+ _this.emit(_constants.EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {
550
519
  languageCode: languageCode,
551
520
  meetingId: meetingId
552
521
  });
@@ -563,7 +532,6 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
563
532
  }
564
533
  if (_this.captionServiceId !== serviceId) {
565
534
  _this.captionServiceId = serviceId;
566
- // if service id value has changed and the translation language has been set, client needs to resend the translator language message to the LLM.
567
535
  if (_this.currentCaptionLanguage) {
568
536
  _this.requestLanguage(_this.currentCaptionLanguage);
569
537
  }
@@ -586,9 +554,6 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
586
554
  /**
587
555
  * update LLM sub‑channel subscriptions.
588
556
  *
589
- * sends a single `subchannelSubscriptionRequest` to LLM,
590
- * allowing subscribe and unsubscribe subchannel.
591
- *
592
557
  * @param {string[]} options.subscribe Sub‑channels to subscribe to.
593
558
  * @param {string[]} options.unsubscribe Sub‑channels to unsubscribe from.
594
559
  * @returns {Promise}
@@ -599,8 +564,8 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
599
564
  subscribe,
600
565
  _ref3$unsubscribe,
601
566
  unsubscribe,
567
+ llm,
602
568
  isDataChannelTokenEnabled,
603
- _this$getPublishTrans4,
604
569
  socket,
605
570
  datachannelUrl,
606
571
  _args2 = arguments;
@@ -608,22 +573,29 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
608
573
  while (1) switch (_context2.prev = _context2.next) {
609
574
  case 0:
610
575
  _ref3 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref3$subscribe = _ref3.subscribe, subscribe = _ref3$subscribe === void 0 ? [] : _ref3$subscribe, _ref3$unsubscribe = _ref3.unsubscribe, unsubscribe = _ref3$unsubscribe === void 0 ? [] : _ref3$unsubscribe;
611
- _context2.next = 1;
612
- return _this.webex.internal.llm.isDataChannelTokenEnabled();
576
+ if (_this.isLLMConnected()) {
577
+ _context2.next = 1;
578
+ break;
579
+ }
580
+ return _context2.abrupt("return");
613
581
  case 1:
582
+ llm = _this.requireLLMChannel();
583
+ _context2.next = 2;
584
+ return llm.isDataChannelTokenEnabled();
585
+ case 2:
614
586
  isDataChannelTokenEnabled = _context2.sent;
615
- if (!(!_this.isLLMConnected() || !isDataChannelTokenEnabled)) {
616
- _context2.next = 2;
587
+ if (isDataChannelTokenEnabled) {
588
+ _context2.next = 3;
617
589
  break;
618
590
  }
619
591
  return _context2.abrupt("return");
620
- case 2:
621
- _this$getPublishTrans4 = _this.getPublishTransport(), socket = _this$getPublishTrans4.socket, datachannelUrl = _this$getPublishTrans4.datachannelUrl; // @ts-ignore
592
+ case 3:
593
+ socket = llm.getSocket();
594
+ datachannelUrl = llm.getDatachannelUrl();
622
595
  socket.send({
623
596
  id: "".concat(_this.seqNum),
624
597
  type: 'subchannelSubscriptionRequest',
625
598
  data: {
626
- // @ts-ignore
627
599
  datachannelUri: datachannelUrl,
628
600
  subscribe: subscribe,
629
601
  unsubscribe: unsubscribe
@@ -631,7 +603,7 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
631
603
  trackingId: "".concat(_webexCore.config.trackingIdPrefix, "_").concat(_uuid.default.v4().toString())
632
604
  });
633
605
  _this.seqNum += 1;
634
- case 3:
606
+ case 4:
635
607
  case "end":
636
608
  return _context2.stop();
637
609
  }
@@ -655,57 +627,174 @@ var VoiceaChannel = exports.VoiceaChannel = /*#__PURE__*/function (_WebexPlugin)
655
627
  _this.keepTranscriptionSubscribed = keepSubscribed;
656
628
  return _this.updateSubchannelSubscriptions(options);
657
629
  });
630
+ _this.llmChannel = llmChannel;
631
+ _this.request = request;
658
632
  _this.seqNum = 1;
659
633
  _this.areCaptionsEnabled = false;
660
- _this.keepTranscriptionSubscribed = false;
661
634
  _this.captionServiceId = undefined;
662
635
  _this.announceStatus = _constants.ANNOUNCE_STATUS.IDLE;
663
636
  _this.captionStatus = _constants.TURN_ON_CAPTION_STATUS.IDLE;
664
637
  _this.toggleManualCaptionStatus = _constants.TOGGLE_MANUAL_CAPTION_STATUS.IDLE;
665
638
  _this.currentSpokenLanguage = _constants.DEFAULT_SPOKEN_LANGUAGE;
666
639
  _this.currentCaptionLanguage = undefined;
640
+ _this.keepTranscriptionSubscribed = false;
641
+
642
+ // Subscribe to relay events from the LLM channel if provided
643
+ if (_this.llmChannel) {
644
+ _this.llmChannel.on('event:relay.event', _this.eventProcessor);
645
+ _this.hasSubscribedToEvents = true;
646
+ }
667
647
  return _this;
668
648
  }
669
- (0, _inherits2.default)(VoiceaChannel, _WebexPlugin);
649
+
650
+ /**
651
+ * Returns the LLM channel, throwing if not available.
652
+ * @private
653
+ * @returns {LLMChannel}
654
+ * @throws {Error} If LLM channel is not available
655
+ */
656
+ (0, _inherits2.default)(VoiceaChannel, _EventEmitter);
670
657
  return (0, _createClass2.default)(VoiceaChannel, [{
671
- key: "listenToEvents",
672
- value:
673
- /**
674
- * Listen to websocket messages
675
- * @returns {undefined}
676
- */
677
- function listenToEvents() {
678
- if (!this.hasSubscribedToEvents) {
679
- // @ts-ignore
680
- this.webex.internal.llm.on('event:relay.event', this.eventProcessor);
681
- // @ts-ignore
682
- this.webex.internal.llm.on("event:relay.event:".concat(_constants.LLM_PRACTICE_SESSION), this.eventProcessor);
683
- this.hasSubscribedToEvents = true;
658
+ key: "requireLLMChannel",
659
+ value: function requireLLMChannel() {
660
+ if (!this.llmChannel) {
661
+ throw new Error('VoiceaChannel: LLM channel not available');
684
662
  }
663
+ return this.llmChannel;
685
664
  }
686
-
665
+ }, {
666
+ key: "deregisterEvents",
667
+ value:
687
668
  /**
688
- * Listen to websocket messages
669
+ * Deregister events and clean up
689
670
  * @returns {void}
690
671
  */
691
- }, {
692
- key: "deregisterEvents",
693
- value: function deregisterEvents() {
672
+ function deregisterEvents() {
694
673
  this.areCaptionsEnabled = false;
695
674
  this.keepTranscriptionSubscribed = false;
696
675
  this.captionServiceId = undefined;
697
- // @ts-ignore
698
- this.webex.internal.llm.off('event:relay.event', this.eventProcessor);
699
- // @ts-ignore
700
- this.webex.internal.llm.off("event:relay.event:".concat(_constants.LLM_PRACTICE_SESSION), this.eventProcessor);
701
- this.hasSubscribedToEvents = false;
676
+ this.targetLLMChannel = undefined;
677
+ this._pendingCaptionRestore = false;
678
+
679
+ // Remove any pending online listener
680
+ this.detachPendingOnline();
681
+ if (this.hasSubscribedToEvents) {
682
+ var _this$llmChannel2;
683
+ (_this$llmChannel2 = this.llmChannel) === null || _this$llmChannel2 === void 0 ? void 0 : _this$llmChannel2.off('event:relay.event', this.eventProcessor);
684
+ this.hasSubscribedToEvents = false;
685
+ }
702
686
  this.announceStatus = _constants.ANNOUNCE_STATUS.IDLE;
703
687
  this.captionStatus = _constants.TURN_ON_CAPTION_STATUS.IDLE;
704
688
  this.toggleManualCaptionStatus = _constants.TOGGLE_MANUAL_CAPTION_STATUS.IDLE;
705
689
  this.currentSpokenLanguage = undefined;
706
690
  this.currentCaptionLanguage = undefined;
707
691
  }
692
+
693
+ /**
694
+ * Attach a pending 'online' listener to a channel for deferred reconciliation.
695
+ * Detaches any existing listener first.
696
+ * @param {LLMChannel} channel - The channel to attach to
697
+ * @param {Function} callback - The callback to run when 'online' fires
698
+ * @private
699
+ * @returns {void}
700
+ */
701
+ }, {
702
+ key: "attachPendingOnline",
703
+ value: function attachPendingOnline(channel, callback) {
704
+ this.detachPendingOnline();
705
+ this._pendingOnlineListener = callback;
706
+ channel.once('online', this._pendingOnlineListener);
707
+ }
708
+
709
+ /**
710
+ * Detach any pending 'online' listener.
711
+ * @private
712
+ * @returns {void}
713
+ */
714
+ }, {
715
+ key: "detachPendingOnline",
716
+ value: function detachPendingOnline() {
717
+ if (this._pendingOnlineListener && this.llmChannel) {
718
+ this.llmChannel.off('online', this._pendingOnlineListener);
719
+ }
720
+ this._pendingOnlineListener = undefined;
721
+ }
722
+
723
+ /**
724
+ * Reset announcement state for a new connection.
725
+ * @private
726
+ * @returns {void}
727
+ */
728
+ }, {
729
+ key: "resetAnnounceState",
730
+ value: function resetAnnounceState() {
731
+ this.announceStatus = _constants.ANNOUNCE_STATUS.IDLE;
732
+ this.captionStatus = _constants.TURN_ON_CAPTION_STATUS.IDLE;
733
+ this.captionServiceId = undefined;
734
+ this.areCaptionsEnabled = false;
735
+ }
736
+
737
+ /**
738
+ * Reconcile voicea binding and caption state to match the desired target.
739
+ * This is idempotent - always re-reads targetLLMChannel and current state.
740
+ * A deferred 'online' callback that fires late self-corrects automatically.
741
+ * @private
742
+ * @returns {Promise<void>}
743
+ */
744
+ }, {
745
+ key: "reconcile",
746
+ value: function reconcile() {
747
+ var _this2 = this;
748
+ var target = this.targetLLMChannel;
749
+ if (!target) return _promise.default.resolve();
750
+
751
+ // 1. Rebind relay-event subscription if actual != desired
752
+ if (this.llmChannel !== target) {
753
+ if (this.hasSubscribedToEvents && this.llmChannel) {
754
+ this.llmChannel.off('event:relay.event', this.eventProcessor);
755
+ }
756
+ this.detachPendingOnline();
757
+ this.llmChannel = target;
758
+ this.llmChannel.on('event:relay.event', this.eventProcessor);
759
+ this.hasSubscribedToEvents = true;
760
+ this.resetAnnounceState();
761
+ // Mark caption restoration as pending if captions were subscribed
762
+ this._pendingCaptionRestore = this.keepTranscriptionSubscribed;
763
+ }
764
+
765
+ // 2. Restore captions if pending
766
+ if (!this._pendingCaptionRestore) return _promise.default.resolve();
767
+ if (this.isLLMConnected()) {
768
+ // Channel is connected, restore captions immediately
769
+ this._pendingCaptionRestore = false;
770
+ return this.turnOnCaptions(this.currentSpokenLanguage).then(function () {
771
+ return undefined;
772
+ }).catch(function () {
773
+ // Best-effort restoration
774
+ });
775
+ }
776
+ // Channel not yet connected - defer until 'online' then re-reconcile.
777
+ // If target changes meanwhile, reconcile() self-corrects.
778
+ this.attachPendingOnline(target, function () {
779
+ _this2.reconcile();
780
+ });
781
+ return _promise.default.resolve();
782
+ }
783
+
784
+ /**
785
+ * Switch to a different LLM channel while preserving caption state.
786
+ * Used when transitioning between main meeting and practice session.
787
+ * This is a thin intent-setter - actual binding happens in reconcile().
788
+ * @param {LLMChannel} newLLMChannel - The new LLM channel to switch to
789
+ * @returns {Promise<void>}
790
+ */
791
+ }, {
792
+ key: "switchLLMChannel",
793
+ value: function switchLLMChannel(newLLMChannel) {
794
+ this.targetLLMChannel = newLLMChannel;
795
+ return this.reconcile();
796
+ }
708
797
  }]);
709
- }(_webexCore.WebexPlugin);
798
+ }(_events.default);
710
799
  var _default = exports.default = VoiceaChannel;
711
800
  //# sourceMappingURL=voicea.js.map