@webex/internal-plugin-voicea 3.12.0-next.8 → 3.12.0-next.80
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/constants.js +4 -3
- package/dist/constants.js.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/index.d.ts +6 -3
- package/dist/types/voicea-plugin.d.ts +23 -0
- package/dist/types/voicea.d.ts +89 -37
- package/dist/types/voicea.types.d.ts +19 -1
- package/dist/voicea-plugin.js +59 -0
- package/dist/voicea-plugin.js.map +1 -0
- package/dist/voicea.js +273 -173
- package/dist/voicea.js.map +1 -1
- package/dist/voicea.types.js.map +1 -1
- package/package.json +9 -9
- package/src/constants.ts +2 -1
- package/src/index.ts +7 -5
- package/src/voicea-plugin.ts +33 -0
- package/src/voicea.ts +274 -178
- package/src/voicea.types.ts +22 -0
- package/test/unit/spec/voicea-plugin.js +83 -0
- package/test/unit/spec/voicea.js +836 -1125
package/src/voicea.ts
CHANGED
|
@@ -1,63 +1,111 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
1
2
|
import uuid from 'uuid';
|
|
2
|
-
|
|
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,
|
|
20
|
+
SpeakerNameUpdatePayload,
|
|
20
21
|
TranscriptionResponse,
|
|
21
22
|
IVoiceaChannel,
|
|
22
23
|
} from './voicea.types';
|
|
23
24
|
import {millisToMinutesAndSeconds} from './utils';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
|
-
* @description VoiceaChannel
|
|
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.
|
|
27
30
|
* @export
|
|
28
31
|
* @class VoiceaChannel
|
|
29
32
|
*/
|
|
30
|
-
export class VoiceaChannel extends
|
|
31
|
-
|
|
33
|
+
export class VoiceaChannel extends EventEmitter implements IVoiceaChannel {
|
|
34
|
+
private request: (options: {method: string; url: string; body?: object}) => Promise<any>;
|
|
35
|
+
private llmChannel?: LLMChannel;
|
|
32
36
|
|
|
33
37
|
private seqNum: number;
|
|
34
|
-
|
|
35
38
|
private areCaptionsEnabled: boolean;
|
|
36
|
-
|
|
37
39
|
private hasSubscribedToEvents = false;
|
|
38
|
-
|
|
39
40
|
private captionServiceId?: string;
|
|
40
|
-
|
|
41
41
|
private announceStatus: string;
|
|
42
|
-
|
|
43
42
|
private captionStatus: string;
|
|
44
43
|
|
|
45
|
-
private
|
|
44
|
+
private keepTranscriptionSubscribed: boolean;
|
|
46
45
|
|
|
47
46
|
private toggleManualCaptionStatus: string;
|
|
48
|
-
|
|
49
47
|
private currentSpokenLanguage?: string;
|
|
50
|
-
|
|
51
48
|
private spokenLanguages: string[] = [];
|
|
52
|
-
|
|
53
49
|
private currentCaptionLanguage?: string;
|
|
54
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
|
+
|
|
58
|
+
/**
|
|
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)
|
|
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
|
+
|
|
55
89
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
90
|
+
* Returns the LLM channel, throwing if not available.
|
|
91
|
+
* @private
|
|
92
|
+
* @returns {LLMChannel}
|
|
93
|
+
* @throws {Error} If LLM channel is not available
|
|
58
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
|
+
}
|
|
59
102
|
|
|
60
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Process events from LLM channel
|
|
105
|
+
* @param {Object} e - Event data
|
|
106
|
+
* @returns {void}
|
|
107
|
+
*/
|
|
108
|
+
private eventProcessor = (e: any): void => {
|
|
61
109
|
this.seqNum = e.sequenceNumber + 1;
|
|
62
110
|
switch (e.data.relayType) {
|
|
63
111
|
case AIBRIDGE_RELAY_TYPES.VOICEA.ANNOUNCEMENT:
|
|
@@ -71,6 +119,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
71
119
|
case AIBRIDGE_RELAY_TYPES.VOICEA.TRANSCRIPTION:
|
|
72
120
|
this.processTranscription(e.data.voiceaPayload);
|
|
73
121
|
break;
|
|
122
|
+
case AIBRIDGE_RELAY_TYPES.VOICEA.SPEAKER_NAME_UPDATE:
|
|
123
|
+
this.processSpeakerNameUpdate(e.data.voiceaPayload);
|
|
124
|
+
break;
|
|
74
125
|
case AIBRIDGE_RELAY_TYPES.MANUAL.TRANSCRIPTION:
|
|
75
126
|
case AIBRIDGE_RELAY_TYPES.MANUAL.CAPTIONER:
|
|
76
127
|
this.processManualTranscription({
|
|
@@ -85,32 +136,24 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
85
136
|
};
|
|
86
137
|
|
|
87
138
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @returns {undefined}
|
|
90
|
-
*/
|
|
91
|
-
private listenToEvents() {
|
|
92
|
-
if (!this.hasSubscribedToEvents) {
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
this.webex.internal.llm.on('event:relay.event', this.eventProcessor);
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
this.webex.internal.llm.on(`event:relay.event:${LLM_PRACTICE_SESSION}`, this.eventProcessor);
|
|
97
|
-
this.hasSubscribedToEvents = true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Listen to websocket messages
|
|
139
|
+
* Deregister events and clean up
|
|
103
140
|
* @returns {void}
|
|
104
141
|
*/
|
|
105
|
-
public deregisterEvents() {
|
|
142
|
+
public deregisterEvents(): void {
|
|
106
143
|
this.areCaptionsEnabled = false;
|
|
107
|
-
this.
|
|
144
|
+
this.keepTranscriptionSubscribed = false;
|
|
108
145
|
this.captionServiceId = undefined;
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.
|
|
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
|
+
|
|
114
157
|
this.announceStatus = ANNOUNCE_STATUS.IDLE;
|
|
115
158
|
this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
|
|
116
159
|
this.toggleManualCaptionStatus = TOGGLE_MANUAL_CAPTION_STATUS.IDLE;
|
|
@@ -119,19 +162,101 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
119
162
|
}
|
|
120
163
|
|
|
121
164
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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}
|
|
124
171
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
129
|
-
|
|
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 {
|
|
130
196
|
this.announceStatus = ANNOUNCE_STATUS.IDLE;
|
|
131
197
|
this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
134
|
-
|
|
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();
|
|
135
260
|
}
|
|
136
261
|
|
|
137
262
|
/**
|
|
@@ -144,8 +269,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
144
269
|
transcriptPayload.type === TRANSCRIPTION_TYPE.MANUAL_CAPTION_FINAL_RESULT ||
|
|
145
270
|
transcriptPayload.type === TRANSCRIPTION_TYPE.MANUAL_CAPTION_INTERIM_RESULT
|
|
146
271
|
) {
|
|
147
|
-
|
|
148
|
-
this.trigger(EVENT_TRIGGERS.NEW_MANUAL_CAPTION, {
|
|
272
|
+
this.emit(EVENT_TRIGGERS.NEW_MANUAL_CAPTION, {
|
|
149
273
|
isFinal: transcriptPayload.type === TRANSCRIPTION_TYPE.MANUAL_CAPTION_FINAL_RESULT,
|
|
150
274
|
transcriptId: transcriptPayload.id,
|
|
151
275
|
transcripts: transcriptPayload.transcripts,
|
|
@@ -155,6 +279,16 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
155
279
|
}
|
|
156
280
|
};
|
|
157
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Process speaker name update and send alert
|
|
284
|
+
* @param {SpeakerNameUpdatePayload} voiceaPayload
|
|
285
|
+
* @returns {void}
|
|
286
|
+
*/
|
|
287
|
+
private processSpeakerNameUpdate = (voiceaPayload: SpeakerNameUpdatePayload): void => {
|
|
288
|
+
// @ts-ignore
|
|
289
|
+
this.emit(EVENT_TRIGGERS.SPEAKER_NAME_UPDATED, voiceaPayload);
|
|
290
|
+
};
|
|
291
|
+
|
|
158
292
|
/**
|
|
159
293
|
* Process Transcript and send alert
|
|
160
294
|
* @param {TranscriptionResponse} voiceaPayload
|
|
@@ -163,8 +297,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
163
297
|
private processTranscription = (voiceaPayload: TranscriptionResponse): void => {
|
|
164
298
|
switch (voiceaPayload.type) {
|
|
165
299
|
case TRANSCRIPTION_TYPE.TRANSCRIPT_INTERIM_RESULTS:
|
|
166
|
-
|
|
167
|
-
this.trigger(EVENT_TRIGGERS.NEW_CAPTION, {
|
|
300
|
+
this.emit(EVENT_TRIGGERS.NEW_CAPTION, {
|
|
168
301
|
isFinal: false,
|
|
169
302
|
transcriptId: voiceaPayload.transcript_id,
|
|
170
303
|
transcripts: voiceaPayload.transcripts,
|
|
@@ -172,11 +305,10 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
172
305
|
break;
|
|
173
306
|
|
|
174
307
|
case TRANSCRIPTION_TYPE.TRANSCRIPT_FINAL_RESULT:
|
|
175
|
-
|
|
176
|
-
this.trigger(EVENT_TRIGGERS.NEW_CAPTION, {
|
|
308
|
+
this.emit(EVENT_TRIGGERS.NEW_CAPTION, {
|
|
177
309
|
isFinal: true,
|
|
178
310
|
transcriptId: voiceaPayload.transcript_id,
|
|
179
|
-
transcripts: voiceaPayload.transcripts
|
|
311
|
+
transcripts: voiceaPayload.transcripts?.map((transcript) => {
|
|
180
312
|
transcript.timestamp = millisToMinutesAndSeconds(transcript.end_millis);
|
|
181
313
|
|
|
182
314
|
return transcript;
|
|
@@ -185,20 +317,18 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
185
317
|
break;
|
|
186
318
|
|
|
187
319
|
case TRANSCRIPTION_TYPE.HIGHLIGHT_CREATED:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
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),
|
|
196
327
|
});
|
|
197
328
|
break;
|
|
198
329
|
|
|
199
330
|
case TRANSCRIPTION_TYPE.EVA_THANKS:
|
|
200
|
-
|
|
201
|
-
this.trigger(EVENT_TRIGGERS.EVA_COMMAND, {
|
|
331
|
+
this.emit(EVENT_TRIGGERS.EVA_COMMAND, {
|
|
202
332
|
isListening: false,
|
|
203
333
|
text: voiceaPayload.command_response,
|
|
204
334
|
});
|
|
@@ -206,22 +336,18 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
206
336
|
|
|
207
337
|
case TRANSCRIPTION_TYPE.EVA_WAKE:
|
|
208
338
|
case TRANSCRIPTION_TYPE.EVA_CANCEL:
|
|
209
|
-
|
|
210
|
-
this.trigger(EVENT_TRIGGERS.EVA_COMMAND, {
|
|
339
|
+
this.emit(EVENT_TRIGGERS.EVA_COMMAND, {
|
|
211
340
|
isListening: voiceaPayload.type === TRANSCRIPTION_TYPE.EVA_WAKE,
|
|
212
341
|
});
|
|
213
342
|
break;
|
|
214
343
|
|
|
215
344
|
case TRANSCRIPTION_TYPE.LANGUAGE_DETECTED: {
|
|
216
345
|
const isInSpokenLanguages = this.spokenLanguages.includes(voiceaPayload.language);
|
|
217
|
-
|
|
218
346
|
if (isInSpokenLanguages) {
|
|
219
|
-
|
|
220
|
-
this.trigger(EVENT_TRIGGERS.LANGUAGE_DETECTED, {
|
|
347
|
+
this.emit(EVENT_TRIGGERS.LANGUAGE_DETECTED, {
|
|
221
348
|
languageCode: voiceaPayload.language,
|
|
222
349
|
});
|
|
223
350
|
}
|
|
224
|
-
|
|
225
351
|
break;
|
|
226
352
|
}
|
|
227
353
|
default:
|
|
@@ -236,11 +362,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
236
362
|
*/
|
|
237
363
|
private processCaptionLanguageResponse = (voiceaPayload: CaptionLanguageResponse): void => {
|
|
238
364
|
if (voiceaPayload.statusCode === 200) {
|
|
239
|
-
|
|
240
|
-
this.trigger(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {statusCode: 200});
|
|
365
|
+
this.emit(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {statusCode: 200});
|
|
241
366
|
} else {
|
|
242
|
-
|
|
243
|
-
this.trigger(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
|
|
367
|
+
this.emit(EVENT_TRIGGERS.CAPTION_LANGUAGE_UPDATE, {
|
|
244
368
|
statusCode: voiceaPayload.errorCode,
|
|
245
369
|
errorMessage: voiceaPayload.message,
|
|
246
370
|
});
|
|
@@ -261,57 +385,35 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
261
385
|
};
|
|
262
386
|
|
|
263
387
|
this.spokenLanguages = voiceaPayload?.ASR?.spoken_languages ?? [];
|
|
264
|
-
|
|
265
|
-
this.trigger(EVENT_TRIGGERS.VOICEA_ANNOUNCEMENT, voiceaLanguageOptions);
|
|
388
|
+
this.emit(EVENT_TRIGGERS.VOICEA_ANNOUNCEMENT, voiceaLanguageOptions);
|
|
266
389
|
};
|
|
267
390
|
|
|
268
391
|
/**
|
|
269
|
-
* Indicates whether the
|
|
392
|
+
* Indicates whether the LLM channel is connected.
|
|
270
393
|
* @returns {boolean}
|
|
271
394
|
*/
|
|
272
|
-
|
|
273
|
-
// @ts-ignore
|
|
274
|
-
this.webex.internal.llm.isConnected() ||
|
|
275
|
-
// @ts-ignore
|
|
276
|
-
this.webex.internal.llm.isConnected(LLM_PRACTICE_SESSION);
|
|
395
|
+
public isLLMConnected = (): boolean => this.llmChannel?.isConnected() ?? false;
|
|
277
396
|
|
|
278
|
-
public
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Resolves the active LLM publish transport, preferring the practice-session
|
|
282
|
-
* connection only when that session is fully connected.
|
|
283
|
-
* @returns {Object}
|
|
284
|
-
*/
|
|
285
|
-
private getPublishTransport = () => {
|
|
286
|
-
// @ts-ignore
|
|
287
|
-
const {llm} = this.webex.internal;
|
|
288
|
-
const isPracticeSessionConnected = llm.isConnected(LLM_PRACTICE_SESSION);
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
socket: (isPracticeSessionConnected && llm.getSocket(LLM_PRACTICE_SESSION)) || llm.socket,
|
|
292
|
-
binding:
|
|
293
|
-
(isPracticeSessionConnected && llm.getBinding(LLM_PRACTICE_SESSION)) || llm.getBinding(),
|
|
294
|
-
datachannelUrl:
|
|
295
|
-
(isPracticeSessionConnected && llm.getDatachannelUrl(LLM_PRACTICE_SESSION)) ||
|
|
296
|
-
llm.getDatachannelUrl(),
|
|
297
|
-
};
|
|
298
|
-
};
|
|
397
|
+
public getKeepTranscriptionSubscribed = (): boolean => this.keepTranscriptionSubscribed;
|
|
299
398
|
|
|
300
399
|
/**
|
|
301
400
|
* Sends Announcement to add voicea to the meeting
|
|
302
401
|
* @returns {void}
|
|
303
402
|
*/
|
|
304
|
-
|
|
403
|
+
public sendAnnouncement = (): void => {
|
|
404
|
+
const llm = this.requireLLMChannel();
|
|
305
405
|
this.announceStatus = ANNOUNCE_STATUS.JOINING;
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
406
|
+
const socket = llm.getSocket();
|
|
407
|
+
const binding = llm.getBinding();
|
|
408
|
+
|
|
409
|
+
const payload = {
|
|
309
410
|
id: `${this.seqNum}`,
|
|
310
411
|
type: 'publishRequest',
|
|
311
|
-
recipients:
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
412
|
+
recipients: [
|
|
413
|
+
{
|
|
414
|
+
route: binding,
|
|
415
|
+
},
|
|
416
|
+
],
|
|
315
417
|
// If captionServiceId exists, send it as the 'to' header; otherwise keep headers empty.
|
|
316
418
|
headers: this.captionServiceId ? {to: this.captionServiceId} : {},
|
|
317
419
|
data: {
|
|
@@ -322,7 +424,8 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
322
424
|
relayType: AIBRIDGE_RELAY_TYPES.VOICEA.CLIENT_ANNOUNCEMENT,
|
|
323
425
|
},
|
|
324
426
|
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
|
|
325
|
-
}
|
|
427
|
+
};
|
|
428
|
+
socket.send(payload);
|
|
326
429
|
this.seqNum += 1;
|
|
327
430
|
};
|
|
328
431
|
|
|
@@ -336,11 +439,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
336
439
|
languageCode: string,
|
|
337
440
|
languageAssignment?: 'DEFAULT' | 'AUTO' | 'MANUAL'
|
|
338
441
|
): Promise<void> =>
|
|
339
|
-
// @ts-ignore
|
|
340
442
|
this.request({
|
|
341
443
|
method: 'PUT',
|
|
342
|
-
|
|
343
|
-
url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
|
|
444
|
+
url: `${this.requireLLMChannel().getLocusUrl()}/controls/`,
|
|
344
445
|
body: {
|
|
345
446
|
transcribe: {
|
|
346
447
|
spokenLanguage: languageCode,
|
|
@@ -348,8 +449,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
348
449
|
},
|
|
349
450
|
},
|
|
350
451
|
}).then(() => {
|
|
351
|
-
|
|
352
|
-
this.trigger(EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {languageCode});
|
|
452
|
+
this.emit(EVENT_TRIGGERS.SPOKEN_LANGUAGE_UPDATE, {languageCode});
|
|
353
453
|
});
|
|
354
454
|
|
|
355
455
|
/**
|
|
@@ -362,14 +462,18 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
362
462
|
return;
|
|
363
463
|
}
|
|
364
464
|
|
|
365
|
-
const
|
|
465
|
+
const llm = this.requireLLMChannel();
|
|
466
|
+
const socket = llm.getSocket();
|
|
467
|
+
const binding = llm.getBinding();
|
|
468
|
+
|
|
366
469
|
socket.send({
|
|
367
470
|
id: `${this.seqNum}`,
|
|
368
471
|
type: 'publishRequest',
|
|
369
|
-
recipients:
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
472
|
+
recipients: [
|
|
473
|
+
{
|
|
474
|
+
route: binding,
|
|
475
|
+
},
|
|
476
|
+
],
|
|
373
477
|
headers: {
|
|
374
478
|
to: this.captionServiceId,
|
|
375
479
|
},
|
|
@@ -384,7 +488,6 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
384
488
|
trackingId: `${config.trackingIdPrefix}_${uuid.v4().toString()}`,
|
|
385
489
|
});
|
|
386
490
|
this.currentCaptionLanguage = languageCode;
|
|
387
|
-
|
|
388
491
|
this.seqNum += 1;
|
|
389
492
|
};
|
|
390
493
|
|
|
@@ -406,15 +509,18 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
406
509
|
return;
|
|
407
510
|
}
|
|
408
511
|
|
|
409
|
-
const
|
|
512
|
+
const llm = this.requireLLMChannel();
|
|
513
|
+
const socket = llm.getSocket();
|
|
514
|
+
const binding = llm.getBinding();
|
|
410
515
|
|
|
411
516
|
socket?.send({
|
|
412
517
|
id: `${this.seqNum}`,
|
|
413
518
|
type: 'publishRequest',
|
|
414
|
-
recipients:
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
519
|
+
recipients: [
|
|
520
|
+
{
|
|
521
|
+
route: binding,
|
|
522
|
+
},
|
|
523
|
+
],
|
|
418
524
|
headers: {},
|
|
419
525
|
data: {
|
|
420
526
|
eventType: 'relay.event',
|
|
@@ -442,38 +548,35 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
442
548
|
|
|
443
549
|
/**
|
|
444
550
|
* request turn on Captions
|
|
445
|
-
* @param {string} [languageCode] - Optional Parameter for spoken language code
|
|
551
|
+
* @param {string} [languageCode] - Optional Parameter for spoken language code
|
|
446
552
|
* @returns {Promise}
|
|
447
553
|
*/
|
|
448
|
-
private requestTurnOnCaptions = (languageCode
|
|
554
|
+
private requestTurnOnCaptions = (languageCode?: string): undefined | Promise<void> => {
|
|
449
555
|
this.captionStatus = TURN_ON_CAPTION_STATUS.SENDING;
|
|
450
556
|
|
|
451
|
-
|
|
557
|
+
const locusUrl = this.requireLLMChannel().getLocusUrl();
|
|
558
|
+
|
|
452
559
|
const body = {
|
|
453
560
|
transcribe: {caption: true},
|
|
454
561
|
languageCode,
|
|
455
562
|
};
|
|
456
563
|
|
|
457
|
-
// @ts-ignore
|
|
458
|
-
// eslint-disable-next-line newline-before-return
|
|
459
564
|
return this.request({
|
|
460
565
|
method: 'PUT',
|
|
461
|
-
|
|
462
|
-
url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
|
|
566
|
+
url: `${locusUrl}/controls/`,
|
|
463
567
|
body,
|
|
464
568
|
})
|
|
465
569
|
.then(() => {
|
|
466
|
-
|
|
467
|
-
this.trigger(EVENT_TRIGGERS.CAPTIONS_TURNED_ON);
|
|
570
|
+
this.emit(EVENT_TRIGGERS.CAPTIONS_TURNED_ON);
|
|
468
571
|
|
|
469
572
|
this.areCaptionsEnabled = true;
|
|
470
573
|
this.captionStatus = TURN_ON_CAPTION_STATUS.ENABLED;
|
|
471
574
|
this.announce();
|
|
472
575
|
this.updateSubchannelSubscriptionsAndSyncCaptionState({subscribe: ['transcription']}, true);
|
|
473
576
|
})
|
|
474
|
-
.catch(() => {
|
|
577
|
+
.catch((error) => {
|
|
475
578
|
this.captionStatus = TURN_ON_CAPTION_STATUS.IDLE;
|
|
476
|
-
throw new Error('turn on captions fail');
|
|
579
|
+
throw new Error('turn on captions fail', {cause: error});
|
|
477
580
|
});
|
|
478
581
|
};
|
|
479
582
|
|
|
@@ -481,20 +584,20 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
481
584
|
* is announce processing
|
|
482
585
|
* @returns {boolean}
|
|
483
586
|
*/
|
|
484
|
-
private isAnnounceProcessing = () =>
|
|
587
|
+
private isAnnounceProcessing = (): boolean =>
|
|
485
588
|
[ANNOUNCE_STATUS.JOINING, ANNOUNCE_STATUS.JOINED].includes(this.announceStatus);
|
|
486
589
|
|
|
487
590
|
/**
|
|
488
591
|
* is announce processed
|
|
489
592
|
* @returns {boolean}
|
|
490
593
|
*/
|
|
491
|
-
private isAnnounceProcessed = () => this.announceStatus === ANNOUNCE_STATUS.JOINED;
|
|
594
|
+
private isAnnounceProcessed = (): boolean => this.announceStatus === ANNOUNCE_STATUS.JOINED;
|
|
492
595
|
|
|
493
596
|
/**
|
|
494
|
-
* announce to voicea data
|
|
597
|
+
* announce to voicea data channel
|
|
495
598
|
* @returns {void}
|
|
496
599
|
*/
|
|
497
|
-
public announce = () => {
|
|
600
|
+
public announce = (): void => {
|
|
498
601
|
if (this.isAnnounceProcessed()) {
|
|
499
602
|
return;
|
|
500
603
|
}
|
|
@@ -508,7 +611,7 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
508
611
|
* is turn on caption processing
|
|
509
612
|
* @returns {boolean}
|
|
510
613
|
*/
|
|
511
|
-
private isCaptionProcessing = () =>
|
|
614
|
+
private isCaptionProcessing = (): boolean =>
|
|
512
615
|
[TURN_ON_CAPTION_STATUS.SENDING, TURN_ON_CAPTION_STATUS.ENABLED].includes(this.captionStatus);
|
|
513
616
|
|
|
514
617
|
/**
|
|
@@ -516,8 +619,8 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
516
619
|
* @param {string} [spokenLanguage] - Optional Spoken language code
|
|
517
620
|
* @returns {Promise}
|
|
518
621
|
*/
|
|
519
|
-
public turnOnCaptions = async (spokenLanguage
|
|
520
|
-
if (this.
|
|
622
|
+
public turnOnCaptions = async (spokenLanguage?: string): Promise<void | undefined> => {
|
|
623
|
+
if (this.isCaptionProcessing()) return undefined;
|
|
521
624
|
|
|
522
625
|
if (!this.isLLMConnected()) {
|
|
523
626
|
throw new Error('can not turn on captions before llm connected');
|
|
@@ -536,11 +639,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
536
639
|
activate: boolean,
|
|
537
640
|
spokenLanguage?: string
|
|
538
641
|
): undefined | Promise<void> => {
|
|
539
|
-
// @ts-ignore
|
|
540
642
|
return this.request({
|
|
541
643
|
method: 'PUT',
|
|
542
|
-
|
|
543
|
-
url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
|
|
644
|
+
url: `${this.requireLLMChannel().getLocusUrl()}/controls/`,
|
|
544
645
|
body: {
|
|
545
646
|
transcribe: {
|
|
546
647
|
transcribing: activate,
|
|
@@ -566,11 +667,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
566
667
|
|
|
567
668
|
this.toggleManualCaptionStatus = TOGGLE_MANUAL_CAPTION_STATUS.SENDING;
|
|
568
669
|
|
|
569
|
-
// @ts-ignore
|
|
570
670
|
return this.request({
|
|
571
671
|
method: 'PUT',
|
|
572
|
-
|
|
573
|
-
url: `${this.webex.internal.llm.getLocusUrl()}/controls/`,
|
|
672
|
+
url: `${this.requireLLMChannel().getLocusUrl()}/controls/`,
|
|
574
673
|
body: {
|
|
575
674
|
manualCaption: {
|
|
576
675
|
enable,
|
|
@@ -594,9 +693,8 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
594
693
|
* @param {string} meetingId
|
|
595
694
|
* @returns {void}
|
|
596
695
|
*/
|
|
597
|
-
public onSpokenLanguageUpdate = (languageCode: string, meetingId): void => {
|
|
598
|
-
|
|
599
|
-
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});
|
|
600
698
|
this.currentSpokenLanguage = languageCode;
|
|
601
699
|
};
|
|
602
700
|
|
|
@@ -611,7 +709,6 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
611
709
|
}
|
|
612
710
|
if (this.captionServiceId !== serviceId) {
|
|
613
711
|
this.captionServiceId = serviceId;
|
|
614
|
-
// if service id value has changed and the translation language has been set, client needs to resend the translator language message to the LLM.
|
|
615
712
|
if (this.currentCaptionLanguage) {
|
|
616
713
|
this.requestLanguage(this.currentCaptionLanguage);
|
|
617
714
|
}
|
|
@@ -622,19 +719,17 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
622
719
|
* get caption status
|
|
623
720
|
* @returns {string}
|
|
624
721
|
*/
|
|
625
|
-
public getCaptionStatus = () => this.captionStatus;
|
|
722
|
+
public getCaptionStatus = (): string => this.captionStatus;
|
|
626
723
|
|
|
627
724
|
/**
|
|
628
725
|
* get announce status
|
|
629
726
|
* @returns {string}
|
|
630
727
|
*/
|
|
631
|
-
public getAnnounceStatus = () => this.announceStatus;
|
|
728
|
+
public getAnnounceStatus = (): string => this.announceStatus;
|
|
729
|
+
|
|
632
730
|
/**
|
|
633
731
|
* update LLM sub‑channel subscriptions.
|
|
634
732
|
*
|
|
635
|
-
* sends a single `subchannelSubscriptionRequest` to LLM,
|
|
636
|
-
* allowing subscribe and unsubscribe subchannel.
|
|
637
|
-
*
|
|
638
733
|
* @param {string[]} options.subscribe Sub‑channels to subscribe to.
|
|
639
734
|
* @param {string[]} options.unsubscribe Sub‑channels to unsubscribe from.
|
|
640
735
|
* @returns {Promise}
|
|
@@ -646,19 +741,19 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
646
741
|
subscribe?: string[];
|
|
647
742
|
unsubscribe?: string[];
|
|
648
743
|
} = {}): Promise<void> => {
|
|
649
|
-
|
|
650
|
-
const isDataChannelTokenEnabled = await this.webex.internal.llm.isDataChannelTokenEnabled();
|
|
651
|
-
// @ts-ignore
|
|
652
|
-
if (!this.isLLMConnected() || !isDataChannelTokenEnabled) return;
|
|
744
|
+
if (!this.isLLMConnected()) return;
|
|
653
745
|
|
|
654
|
-
const
|
|
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();
|
|
655
752
|
|
|
656
|
-
// @ts-ignore
|
|
657
753
|
socket.send({
|
|
658
754
|
id: `${this.seqNum}`,
|
|
659
755
|
type: 'subchannelSubscriptionRequest',
|
|
660
756
|
data: {
|
|
661
|
-
// @ts-ignore
|
|
662
757
|
datachannelUri: datachannelUrl,
|
|
663
758
|
subscribe,
|
|
664
759
|
unsubscribe,
|
|
@@ -670,13 +765,14 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
670
765
|
};
|
|
671
766
|
|
|
672
767
|
/**
|
|
673
|
-
*
|
|
674
|
-
*
|
|
768
|
+
* Updates transcription subchannel subscriptions and records whether the
|
|
769
|
+
* transcription subscription should be kept (and restored on reconnect).
|
|
675
770
|
*
|
|
676
771
|
* @param {Object} [options] - Subscription options.
|
|
677
772
|
* @param {string[]} [options.subscribe] - Subchannels to subscribe to.
|
|
678
773
|
* @param {string[]} [options.unsubscribe] - Subchannels to unsubscribe from.
|
|
679
|
-
* @param {boolean} [
|
|
774
|
+
* @param {boolean} [keepSubscribed=false] - Whether the transcription
|
|
775
|
+
* subscription should be kept and restored on reconnect.
|
|
680
776
|
*
|
|
681
777
|
* @returns {Promise<void>}
|
|
682
778
|
*/
|
|
@@ -685,9 +781,9 @@ export class VoiceaChannel extends WebexPlugin implements IVoiceaChannel {
|
|
|
685
781
|
subscribe?: string[];
|
|
686
782
|
unsubscribe?: string[];
|
|
687
783
|
} = {},
|
|
688
|
-
|
|
784
|
+
keepSubscribed = false
|
|
689
785
|
): Promise<void> => {
|
|
690
|
-
this.
|
|
786
|
+
this.keepTranscriptionSubscribed = keepSubscribed;
|
|
691
787
|
|
|
692
788
|
return this.updateSubchannelSubscriptions(options);
|
|
693
789
|
};
|