@convai/web-sdk 1.9.1 → 1.9.3
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/README.md +3 -3
- package/dist/core/AudioManager.d.ts +2 -0
- package/dist/core/AudioManager.js +30 -9
- package/dist/core/ConvaiClient.js +10 -1
- package/dist/core/ScreenShareManager.d.ts +11 -2
- package/dist/core/ScreenShareManager.js +46 -36
- package/dist/core/VideoManager.d.ts +2 -0
- package/dist/core/VideoManager.js +18 -5
- package/dist/core/characterInfo.d.ts +4 -1
- package/dist/core/characterInfo.js +5 -1
- package/dist/core/types.d.ts +13 -3
- package/dist/core/websocketUrl.d.ts +11 -0
- package/dist/core/websocketUrl.js +17 -0
- package/dist/lipsync-helpers/mhaLimitDrivers.d.ts +2 -0
- package/dist/lipsync-helpers/mhaLimitDrivers.js +7 -0
- package/dist/lipsync-helpers/naturalness/processor.d.ts +2 -0
- package/dist/lipsync-helpers/naturalness/processor.js +8 -0
- package/dist/lipsync-helpers/naturalness/profiles/mha.js +8 -0
- package/dist/lipsync-helpers/naturalness/types.d.ts +7 -0
- package/dist/react/hooks/useCharacterInfo.d.ts +1 -1
- package/dist/react/hooks/useCharacterInfo.js +1 -1
- package/dist/react/hooks/useConvaiClient.js +0 -16
- package/dist/utils/inlineMarkdown.d.ts +7 -5
- package/dist/utils/inlineMarkdown.js +7 -5
- package/dist/vanilla/ConvaiWidget.js +1 -1
- package/dist/vanilla/WebSocketSession.d.ts +19 -13
- package/dist/vanilla/WebSocketSession.js +58 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -400,8 +400,8 @@ personal access token; every method rejects with `CharacterApiError` (`status`,
|
|
|
400
400
|
non-2xx answer. Point `characterApiUrl` at `https://api2-stg.convai.com` to author against
|
|
401
401
|
staging.
|
|
402
402
|
|
|
403
|
-
Explicit selectors are resolved by the runtime through the Character REST platform
|
|
404
|
-
|
|
403
|
+
Explicit selectors are resolved by the runtime through the Character REST platform, on both
|
|
404
|
+
production and staging. A runtime without version resolution answers them with `503`.
|
|
405
405
|
Full guide: [Character Versioning](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/character-versioning).
|
|
406
406
|
|
|
407
407
|
---
|
|
@@ -448,7 +448,7 @@ Key points:
|
|
|
448
448
|
|
|
449
449
|
- `characters` and `characterId` are mutually exclusive, and roster entries take a bare character UUID (no `-draft` / `-1.2` selectors).
|
|
450
450
|
- `provisioningStatus` describes dispatch only; a member is usable when its own `characterReady` arrives.
|
|
451
|
-
- Transcript rows, `characterAudioTrack` events and `
|
|
451
|
+
- Transcript rows, `characterAudioTrack` events and `characterReady` payloads carry `membershipId`, so two copies of one character never merge. (`botReady` takes no arguments.)
|
|
452
452
|
- Room-topology failures throw `ConvaiRoomError` with `status`, `code`, `requestTraceId` and `isRetryable`; the SDK retries `ROSTER_PROVISIONING_IN_PROGRESS` for you (`rosterProvisioningRetry`).
|
|
453
453
|
- Action protocol v2 and `actionConfig.tools` are single-character only and cannot be combined with a roster.
|
|
454
454
|
|
|
@@ -9,6 +9,8 @@ import type { IWebSocketSession } from "./types.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class AudioManager extends EventEmitter implements AudioControls {
|
|
11
11
|
private room;
|
|
12
|
+
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
13
|
+
private listeners;
|
|
12
14
|
private _wsSession;
|
|
13
15
|
private _isAudioEnabled;
|
|
14
16
|
private _isAudioMuted;
|
|
@@ -8,6 +8,8 @@ export class AudioManager extends EventEmitter {
|
|
|
8
8
|
constructor(room) {
|
|
9
9
|
super();
|
|
10
10
|
this.room = null;
|
|
11
|
+
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
12
|
+
this.listeners = [];
|
|
11
13
|
this._wsSession = null;
|
|
12
14
|
this._isAudioEnabled = false;
|
|
13
15
|
this._isAudioMuted = false;
|
|
@@ -45,8 +47,14 @@ export class AudioManager extends EventEmitter {
|
|
|
45
47
|
this.cleanupListeners();
|
|
46
48
|
}
|
|
47
49
|
this.room = room;
|
|
48
|
-
if (room
|
|
49
|
-
|
|
50
|
+
if (!room)
|
|
51
|
+
return;
|
|
52
|
+
// Listen even while the room is disconnected: ConvaiClient builds this
|
|
53
|
+
// manager with a fresh Room before connect(), and LiveKit keeps that Room's
|
|
54
|
+
// localParticipant across connections. Gating on a live room meant the
|
|
55
|
+
// listeners were never attached in a real client.
|
|
56
|
+
this.setupListeners();
|
|
57
|
+
if (room.state !== 'disconnected') {
|
|
50
58
|
this.updateState();
|
|
51
59
|
}
|
|
52
60
|
}
|
|
@@ -85,10 +93,17 @@ export class AudioManager extends EventEmitter {
|
|
|
85
93
|
this.emit('audioStateChange', { isAudioMuted: true, isAudioEnabled: false });
|
|
86
94
|
}
|
|
87
95
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
// The local participant's publish events are localTrackPublished /
|
|
97
|
+
// localTrackUnpublished; trackPublished / trackUnpublished are emitted
|
|
98
|
+
// only by RemoteParticipant (livekit-client 2.17.3).
|
|
99
|
+
this.listeners = [
|
|
100
|
+
['trackMuted', handleTrackMuted],
|
|
101
|
+
['trackUnmuted', handleTrackUnmuted],
|
|
102
|
+
['localTrackPublished', handleTrackPublished],
|
|
103
|
+
['localTrackUnpublished', handleTrackUnpublished],
|
|
104
|
+
];
|
|
105
|
+
for (const [event, handler] of this.listeners)
|
|
106
|
+
localParticipant.on(event, handler);
|
|
92
107
|
}
|
|
93
108
|
/**
|
|
94
109
|
* Clean up event listeners
|
|
@@ -96,7 +111,10 @@ export class AudioManager extends EventEmitter {
|
|
|
96
111
|
cleanupListeners() {
|
|
97
112
|
if (!this.room)
|
|
98
113
|
return;
|
|
99
|
-
|
|
114
|
+
const localParticipant = this.room.localParticipant;
|
|
115
|
+
for (const [event, handler] of this.listeners)
|
|
116
|
+
localParticipant.off(event, handler);
|
|
117
|
+
this.listeners = [];
|
|
100
118
|
}
|
|
101
119
|
/**
|
|
102
120
|
* Force-sync the stored audio state with the underlying LiveKit room.
|
|
@@ -275,11 +293,14 @@ export class AudioManager extends EventEmitter {
|
|
|
275
293
|
* Reset state on disconnect
|
|
276
294
|
*/
|
|
277
295
|
reset() {
|
|
296
|
+
// Disconnected means the mic is not transmitting: muted, as
|
|
297
|
+
// syncStateFromRoom already reports for a disconnected room and as
|
|
298
|
+
// useConvaiClient sets on `disconnect` (which this event used to undo).
|
|
278
299
|
this._isAudioEnabled = false;
|
|
279
|
-
this._isAudioMuted =
|
|
300
|
+
this._isAudioMuted = true;
|
|
280
301
|
this._audioLevel = 0;
|
|
281
302
|
this.emit('audioStateChange', {
|
|
282
|
-
isAudioMuted:
|
|
303
|
+
isAudioMuted: true,
|
|
283
304
|
isAudioEnabled: false,
|
|
284
305
|
audioLevel: 0
|
|
285
306
|
});
|
|
@@ -2,6 +2,7 @@ import { Room, RoomEvent, ConnectionState, DefaultReconnectPolicy, setLogLevel,
|
|
|
2
2
|
setLogLevel("warn");
|
|
3
3
|
import { DisconnectReasonEnum, } from "./types.js";
|
|
4
4
|
import { AudioManager } from "./AudioManager.js";
|
|
5
|
+
import { secureWebSocketUrl } from "./websocketUrl.js";
|
|
5
6
|
import { VideoManager } from "./VideoManager.js";
|
|
6
7
|
import { ScreenShareManager } from "./ScreenShareManager.js";
|
|
7
8
|
import { MessageHandler } from "./MessageHandler.js";
|
|
@@ -435,6 +436,9 @@ export class ConvaiClient extends EventEmitter {
|
|
|
435
436
|
// session-wide setting is the only one that can apply to it.
|
|
436
437
|
this._wsBotAudioTrack.enabled = !this._characterMuted;
|
|
437
438
|
}
|
|
439
|
+
// Pipecat's WebSocket transport plays the character's audio itself and
|
|
440
|
+
// exposes no track, so the session silences its own player instead.
|
|
441
|
+
this._wsSession?.setBotAudioMuted?.(this._characterMuted);
|
|
438
442
|
if (this._room.state !== ConnectionState.Connected)
|
|
439
443
|
return;
|
|
440
444
|
this._room.remoteParticipants.forEach((participant) => {
|
|
@@ -1562,7 +1566,9 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1562
1566
|
if (transportType === "websocket") {
|
|
1563
1567
|
// ── WebSocket (Pipecat) transport path ────────────────────────────
|
|
1564
1568
|
// Server returns the WebSocket URL in room_url (same field as LiveKit).
|
|
1565
|
-
|
|
1569
|
+
// Hosted Convai returns ws:// for a TLS-only endpoint; see websocketUrl.ts.
|
|
1570
|
+
const roomUrl = connectionData.room_url;
|
|
1571
|
+
const wsUrl = roomUrl && secureWebSocketUrl(roomUrl, configWithDefaults.url);
|
|
1566
1572
|
if (!wsUrl) {
|
|
1567
1573
|
throw new Error("No WebSocket URL returned from /connect endpoint (expected room_url)");
|
|
1568
1574
|
}
|
|
@@ -1575,6 +1581,9 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1575
1581
|
// after the connection is established (enableMic(false) works once the
|
|
1576
1582
|
// stream exists, but not before it is initialized).
|
|
1577
1583
|
this._wsSession = _wsFactory((payload) => this._messageHandler.handleDataReceivedPublic(payload), true);
|
|
1584
|
+
// The mute setting outlives sessions: a reconnect must not hand back an
|
|
1585
|
+
// audible character.
|
|
1586
|
+
this._wsSession.setBotAudioMuted?.(this._characterMuted);
|
|
1578
1587
|
const webSocketVisionEnabled = configWithDefaults.enableVideo === true &&
|
|
1579
1588
|
effectiveVisionInputConfig?.enabled !== false;
|
|
1580
1589
|
if (webSocketVisionEnabled) {
|
|
@@ -10,6 +10,8 @@ export declare class ScreenShareManager extends EventEmitter implements ScreenSh
|
|
|
10
10
|
private room;
|
|
11
11
|
private _isScreenShareEnabled;
|
|
12
12
|
private _isScreenShareActive;
|
|
13
|
+
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
14
|
+
private listeners;
|
|
13
15
|
constructor(room?: Room);
|
|
14
16
|
get isScreenShareEnabled(): boolean;
|
|
15
17
|
get isScreenShareActive(): boolean;
|
|
@@ -18,11 +20,18 @@ export declare class ScreenShareManager extends EventEmitter implements ScreenSh
|
|
|
18
20
|
*/
|
|
19
21
|
setRoom(room: Room): void;
|
|
20
22
|
/**
|
|
21
|
-
*
|
|
23
|
+
* Follow the local screen-share track.
|
|
24
|
+
*
|
|
25
|
+
* The local participant emits `localTrackPublished` / `localTrackUnpublished`
|
|
26
|
+
* (livekit-client's `ParticipantEvent.LocalTrack*`). `trackPublished` /
|
|
27
|
+
* `trackUnpublished` are `RemoteParticipant` events and never fire here, which
|
|
28
|
+
* is how a share ended from the browser's own "Stop sharing" bar — LiveKit
|
|
29
|
+
* unpublishes the ended track — used to leave `isScreenShareActive` true.
|
|
22
30
|
*/
|
|
23
31
|
private setupListeners;
|
|
24
32
|
/**
|
|
25
|
-
*
|
|
33
|
+
* Detach from the current room, so a reconnect's new room is the only one
|
|
34
|
+
* driving state.
|
|
26
35
|
*/
|
|
27
36
|
private cleanupListeners;
|
|
28
37
|
/**
|
|
@@ -11,6 +11,8 @@ export class ScreenShareManager extends EventEmitter {
|
|
|
11
11
|
this.room = null;
|
|
12
12
|
this._isScreenShareEnabled = false;
|
|
13
13
|
this._isScreenShareActive = false;
|
|
14
|
+
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
15
|
+
this.listeners = [];
|
|
14
16
|
if (room) {
|
|
15
17
|
this.setRoom(room);
|
|
16
18
|
}
|
|
@@ -30,54 +32,61 @@ export class ScreenShareManager extends EventEmitter {
|
|
|
30
32
|
this.cleanupListeners();
|
|
31
33
|
}
|
|
32
34
|
this.room = room;
|
|
33
|
-
if (room
|
|
34
|
-
|
|
35
|
+
if (!room)
|
|
36
|
+
return;
|
|
37
|
+
// Listen even while the room is disconnected. ConvaiClient builds this
|
|
38
|
+
// manager with a fresh Room before connect(), and LiveKit keeps that Room's
|
|
39
|
+
// localParticipant across connections — so gating on a live room meant the
|
|
40
|
+
// listeners were never attached in a real client.
|
|
41
|
+
this.setupListeners();
|
|
42
|
+
if (room.state !== 'disconnected') {
|
|
35
43
|
this.updateState();
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
/**
|
|
39
|
-
*
|
|
47
|
+
* Follow the local screen-share track.
|
|
48
|
+
*
|
|
49
|
+
* The local participant emits `localTrackPublished` / `localTrackUnpublished`
|
|
50
|
+
* (livekit-client's `ParticipantEvent.LocalTrack*`). `trackPublished` /
|
|
51
|
+
* `trackUnpublished` are `RemoteParticipant` events and never fire here, which
|
|
52
|
+
* is how a share ended from the browser's own "Stop sharing" bar — LiveKit
|
|
53
|
+
* unpublishes the ended track — used to leave `isScreenShareActive` true.
|
|
40
54
|
*/
|
|
41
55
|
setupListeners() {
|
|
42
56
|
if (!this.room)
|
|
43
57
|
return;
|
|
44
58
|
const localParticipant = this.room.localParticipant;
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const handleTrackUnpublished = (track) => {
|
|
52
|
-
if (track.source === 'screen_share') {
|
|
53
|
-
this._isScreenShareActive = false;
|
|
54
|
-
this.emit('screenShareStateChange', { isScreenShareActive: false });
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const handleTrackMuted = (track) => {
|
|
58
|
-
if (track.source === 'screen_share') {
|
|
59
|
-
this._isScreenShareActive = false;
|
|
60
|
-
this.emit('screenShareStateChange', { isScreenShareActive: false });
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const handleTrackUnmuted = (track) => {
|
|
64
|
-
if (track.source === 'screen_share') {
|
|
65
|
-
this._isScreenShareActive = true;
|
|
66
|
-
this.emit('screenShareStateChange', { isScreenShareActive: true });
|
|
67
|
-
}
|
|
59
|
+
const set = (active, enabled = active) => {
|
|
60
|
+
this._isScreenShareActive = active;
|
|
61
|
+
this._isScreenShareEnabled = enabled;
|
|
62
|
+
this.emit('screenShareStateChange', { isScreenShareEnabled: enabled, isScreenShareActive: active });
|
|
68
63
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
const isScreen = (publication) => publication?.source === 'screen_share';
|
|
65
|
+
this.listeners = [
|
|
66
|
+
['localTrackPublished', (p) => { if (isScreen(p))
|
|
67
|
+
set(true); }],
|
|
68
|
+
['localTrackUnpublished', (p) => { if (isScreen(p))
|
|
69
|
+
set(false); }],
|
|
70
|
+
// A muted share is still published (enabled), just not showing.
|
|
71
|
+
['trackMuted', (p) => { if (isScreen(p))
|
|
72
|
+
set(false, this._isScreenShareEnabled); }],
|
|
73
|
+
['trackUnmuted', (p) => { if (isScreen(p))
|
|
74
|
+
set(true, this._isScreenShareEnabled); }],
|
|
75
|
+
];
|
|
76
|
+
for (const [event, handler] of this.listeners)
|
|
77
|
+
localParticipant.on(event, handler);
|
|
73
78
|
}
|
|
74
79
|
/**
|
|
75
|
-
*
|
|
80
|
+
* Detach from the current room, so a reconnect's new room is the only one
|
|
81
|
+
* driving state.
|
|
76
82
|
*/
|
|
77
83
|
cleanupListeners() {
|
|
78
84
|
if (!this.room)
|
|
79
85
|
return;
|
|
80
|
-
|
|
86
|
+
const localParticipant = this.room.localParticipant;
|
|
87
|
+
for (const [event, handler] of this.listeners)
|
|
88
|
+
localParticipant.off(event, handler);
|
|
89
|
+
this.listeners = [];
|
|
81
90
|
}
|
|
82
91
|
/**
|
|
83
92
|
* Update screen share state from room
|
|
@@ -159,11 +168,12 @@ export class ScreenShareManager extends EventEmitter {
|
|
|
159
168
|
surfaceSwitching: "include",
|
|
160
169
|
systemAudio: "include",
|
|
161
170
|
});
|
|
162
|
-
// Publish
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
});
|
|
171
|
+
// Publish every track before reporting the share live: a failed publish
|
|
172
|
+
// rejects here instead of surfacing later as an unhandled rejection.
|
|
173
|
+
await Promise.all(tracks.map((track) => this.room.localParticipant.publishTrack(track)));
|
|
166
174
|
this._isScreenShareEnabled = true;
|
|
175
|
+
this._isScreenShareActive = true;
|
|
176
|
+
this.emit('screenShareStateChange', { isScreenShareEnabled: true, isScreenShareActive: true });
|
|
167
177
|
}
|
|
168
178
|
catch (error) {
|
|
169
179
|
logger.error("Failed to enable screen share with audio:", error);
|
|
@@ -9,6 +9,8 @@ type WebSocketVisionMessageSender = (type: WebSocketVisionMessageType, data: Rec
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class VideoManager extends EventEmitter implements VideoControls {
|
|
11
11
|
private room;
|
|
12
|
+
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
13
|
+
private listeners;
|
|
12
14
|
private _isVideoEnabled;
|
|
13
15
|
private _isVideoHidden;
|
|
14
16
|
private _activeVisionSource;
|
|
@@ -10,6 +10,8 @@ export class VideoManager extends EventEmitter {
|
|
|
10
10
|
constructor(room) {
|
|
11
11
|
super();
|
|
12
12
|
this.room = null;
|
|
13
|
+
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
14
|
+
this.listeners = [];
|
|
13
15
|
this._isVideoEnabled = false;
|
|
14
16
|
this._isVideoHidden = false;
|
|
15
17
|
this._activeVisionSource = null;
|
|
@@ -106,10 +108,18 @@ export class VideoManager extends EventEmitter {
|
|
|
106
108
|
});
|
|
107
109
|
}
|
|
108
110
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
// The local participant's publish events are localTrackPublished /
|
|
112
|
+
// localTrackUnpublished; trackPublished / trackUnpublished are emitted
|
|
113
|
+
// only by RemoteParticipant (livekit-client 2.17.3), so a camera or vision
|
|
114
|
+
// track unpublished outside videoControls never cleared its source.
|
|
115
|
+
this.listeners = [
|
|
116
|
+
["trackMuted", handleTrackMuted],
|
|
117
|
+
["trackUnmuted", handleTrackUnmuted],
|
|
118
|
+
["localTrackPublished", handleTrackPublished],
|
|
119
|
+
["localTrackUnpublished", handleTrackUnpublished],
|
|
120
|
+
];
|
|
121
|
+
for (const [event, handler] of this.listeners)
|
|
122
|
+
localParticipant.on(event, handler);
|
|
113
123
|
}
|
|
114
124
|
/**
|
|
115
125
|
* Clean up event listeners
|
|
@@ -117,7 +127,10 @@ export class VideoManager extends EventEmitter {
|
|
|
117
127
|
cleanupListeners() {
|
|
118
128
|
if (!this.room)
|
|
119
129
|
return;
|
|
120
|
-
|
|
130
|
+
const localParticipant = this.room.localParticipant;
|
|
131
|
+
for (const [event, handler] of this.listeners)
|
|
132
|
+
localParticipant.off(event, handler);
|
|
133
|
+
this.listeners = [];
|
|
121
134
|
}
|
|
122
135
|
/**
|
|
123
136
|
* Update video state from room
|
|
@@ -21,7 +21,10 @@ export interface CharacterInfo {
|
|
|
21
21
|
export declare const FALLBACK_CHARACTER_NAME = "Convi";
|
|
22
22
|
export interface FetchCharacterInfoOptions {
|
|
23
23
|
characterId: string;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Sent as `CONVAI-API-KEY`, the header Convai's REST hosts have always taken.
|
|
26
|
+
* Ignored when `authToken` is present.
|
|
27
|
+
*/
|
|
25
28
|
apiKey?: string | null;
|
|
26
29
|
/** Sent as `API-AUTH-TOKEN`, and preferred over `apiKey`. */
|
|
27
30
|
authToken?: string | null;
|
|
@@ -37,10 +37,14 @@ export async function fetchCharacterInfo(options) {
|
|
|
37
37
|
const headers = {
|
|
38
38
|
"Content-Type": "application/json",
|
|
39
39
|
};
|
|
40
|
+
// CONVAI-API-KEY, not the X-API-Key that /connect takes. api.convai.com
|
|
41
|
+
// accepts either, but self-hosted deployments authenticate this route the
|
|
42
|
+
// way the legacy convai-web-sdk called it, with CONVAI-API-KEY, and answer
|
|
43
|
+
// X-API-Key with 401.
|
|
40
44
|
if (authToken)
|
|
41
45
|
headers["API-AUTH-TOKEN"] = authToken;
|
|
42
46
|
else if (apiKey)
|
|
43
|
-
headers["
|
|
47
|
+
headers["CONVAI-API-KEY"] = apiKey;
|
|
44
48
|
const origin = (baseUrl || DEFAULT_CHARACTER_INFO_URL).replace(/\/+$/, "");
|
|
45
49
|
const response = await fetch(`${origin}/character/get`, {
|
|
46
50
|
method: "POST",
|
package/dist/core/types.d.ts
CHANGED
|
@@ -72,6 +72,12 @@ export interface IWebSocketSession {
|
|
|
72
72
|
disconnect(): Promise<void>;
|
|
73
73
|
sendMessage(type: string, data: unknown): void;
|
|
74
74
|
enableMic(enable: boolean): void;
|
|
75
|
+
/**
|
|
76
|
+
* Silence (or restore) the character's audio for the listener. Optional: an
|
|
77
|
+
* implementation that exposes the bot audio as a track can leave it out and
|
|
78
|
+
* let `botAudioTrack` carry the mute instead.
|
|
79
|
+
*/
|
|
80
|
+
setBotAudioMuted?(muted: boolean): void;
|
|
75
81
|
on(event: string, listener: (...args: any[]) => void): () => void;
|
|
76
82
|
off(event: string, listener: (...args: any[]) => void): void;
|
|
77
83
|
}
|
|
@@ -922,9 +928,13 @@ export interface ConvaiConfig {
|
|
|
922
928
|
* which also drops link targets: `[Doc](https://…/a.pdf)` reaches the client
|
|
923
929
|
* as `Doc`. With this on, the session preserves `[text](url)`, ``
|
|
924
930
|
* and bare `http(s)://` URLs verbatim (trailing sentence punctuation stays
|
|
925
|
-
* outside the URL,
|
|
926
|
-
*
|
|
927
|
-
*
|
|
931
|
+
* outside the URL) while bold, headings, tables and code are flattened as
|
|
932
|
+
* before. Speech is unaffected — URLs are never read aloud.
|
|
933
|
+
*
|
|
934
|
+
* The server does not sanitise schemes: a markdown link keeps its target
|
|
935
|
+
* whatever the scheme, `[x](javascript:…)` included (only bare URLs are
|
|
936
|
+
* limited to http(s)). The SDK's renderers allow only safe schemes; a custom
|
|
937
|
+
* renderer must check every href with `isSafeHref`.
|
|
928
938
|
*
|
|
929
939
|
* Both widgets render the preserved form as clickable links, with inline
|
|
930
940
|
* previews for image and video URLs. If you render `chatMessages` yourself,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebSocket URL from a `/connect` response, made safe to open.
|
|
3
|
+
*
|
|
4
|
+
* Hosted Convai answers `/connect` over https but returns `ws://…/chat` in
|
|
5
|
+
* `room_url`, and that endpoint only accepts TLS: a plain `ws://` socket is
|
|
6
|
+
* refused (the browser reports close code 1006). A `ws://` URL is upgraded to
|
|
7
|
+
* `wss://` when the `/connect` URL was https, or when the page itself is https,
|
|
8
|
+
* where the browser would block an insecure socket anyway. Local development
|
|
9
|
+
* over http keeps `ws://`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function secureWebSocketUrl(roomUrl: string, connectUrl?: string | null, pageProtocol?: string | undefined): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebSocket URL from a `/connect` response, made safe to open.
|
|
3
|
+
*
|
|
4
|
+
* Hosted Convai answers `/connect` over https but returns `ws://…/chat` in
|
|
5
|
+
* `room_url`, and that endpoint only accepts TLS: a plain `ws://` socket is
|
|
6
|
+
* refused (the browser reports close code 1006). A `ws://` URL is upgraded to
|
|
7
|
+
* `wss://` when the `/connect` URL was https, or when the page itself is https,
|
|
8
|
+
* where the browser would block an insecure socket anyway. Local development
|
|
9
|
+
* over http keeps `ws://`.
|
|
10
|
+
*/
|
|
11
|
+
export function secureWebSocketUrl(roomUrl, connectUrl, pageProtocol = typeof location !== "undefined" ? location.protocol : undefined) {
|
|
12
|
+
if (!/^ws:\/\//i.test(roomUrl))
|
|
13
|
+
return roomUrl;
|
|
14
|
+
const secureConnect = typeof connectUrl === "string" && /^https:\/\//i.test(connectUrl);
|
|
15
|
+
const securePage = pageProtocol === "https:";
|
|
16
|
+
return secureConnect || securePage ? roomUrl.replace(/^ws:\/\//i, "wss://") : roomUrl;
|
|
17
|
+
}
|
|
@@ -14,6 +14,8 @@ export declare const MHA_LIMIT_DRIVERS: readonly {
|
|
|
14
14
|
/**
|
|
15
15
|
* Apply the MetaHuman limit drivers to a 251-dim frame IN PLACE:
|
|
16
16
|
* each target channel becomes max(target, source). No-op for other formats.
|
|
17
|
+
* A channel the stream pins at 1.0 (noseWrinkleUpperL/R) is cleared first,
|
|
18
|
+
* so it follows its source instead of holding a sneer.
|
|
17
19
|
*/
|
|
18
20
|
export declare function applyMhaLimits(frame: Float32Array): void;
|
|
19
21
|
/** Production-tuned per-channel gains (short control name → gain). */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { METAHUMAN_ORDER_251 } from "./metahumanOrder251.js";
|
|
2
2
|
import { MHA_PROFILE, MHA_RECOMMENDED_GAIN_TABLE, mhaChannelIndex, } from "./naturalness/profiles/mha.js";
|
|
3
|
+
import { PINNED_THRESHOLD } from "./naturalness/processor.js";
|
|
3
4
|
/**
|
|
4
5
|
* Flat MHA convenience helpers — thin wrappers over the modular
|
|
5
6
|
* naturalness profile (see `naturalness/`). Prefer
|
|
@@ -16,10 +17,16 @@ export const MHA_LIMIT_DRIVERS = MHA_PROFILE.limits.map(([sourceIdx, targetIdx])
|
|
|
16
17
|
/**
|
|
17
18
|
* Apply the MetaHuman limit drivers to a 251-dim frame IN PLACE:
|
|
18
19
|
* each target channel becomes max(target, source). No-op for other formats.
|
|
20
|
+
* A channel the stream pins at 1.0 (noseWrinkleUpperL/R) is cleared first,
|
|
21
|
+
* so it follows its source instead of holding a sneer.
|
|
19
22
|
*/
|
|
20
23
|
export function applyMhaLimits(frame) {
|
|
21
24
|
if (frame.length < METAHUMAN_ORDER_251.length)
|
|
22
25
|
return;
|
|
26
|
+
for (const i of MHA_PROFILE.pinnedChannels ?? []) {
|
|
27
|
+
if (frame[i] >= PINNED_THRESHOLD)
|
|
28
|
+
frame[i] = 0;
|
|
29
|
+
}
|
|
23
30
|
for (const [s, t] of MHA_PROFILE.limits) {
|
|
24
31
|
if (frame[s] > frame[t])
|
|
25
32
|
frame[t] = frame[s];
|
|
@@ -20,4 +20,6 @@ export interface LipsyncProcessor {
|
|
|
20
20
|
/** process + apply in one call. */
|
|
21
21
|
tick(frame: Float32Array | null, deltaSeconds: number, bindings: LipsyncMeshBinding[]): void;
|
|
22
22
|
}
|
|
23
|
+
/** A pinned channel at or above this value is a stream artifact, not an expression. */
|
|
24
|
+
export declare const PINNED_THRESHOLD = 0.999;
|
|
23
25
|
export declare function createLipsyncProcessor(formatOrProfile: LipsyncFormat | LipsyncFormatProfile, options?: LipsyncProcessorOptions): LipsyncProcessor;
|
|
@@ -28,6 +28,8 @@ export function getLipsyncProfile(format) {
|
|
|
28
28
|
}
|
|
29
29
|
return profile;
|
|
30
30
|
}
|
|
31
|
+
/** A pinned channel at or above this value is a stream artifact, not an expression. */
|
|
32
|
+
export const PINNED_THRESHOLD = 0.999;
|
|
31
33
|
export function createLipsyncProcessor(formatOrProfile, options = {}) {
|
|
32
34
|
const profile = typeof formatOrProfile === "string"
|
|
33
35
|
? getLipsyncProfile(formatOrProfile)
|
|
@@ -61,6 +63,12 @@ export function createLipsyncProcessor(formatOrProfile, options = {}) {
|
|
|
61
63
|
let env = envelope === false ? 1 : 0;
|
|
62
64
|
const shape = (src) => {
|
|
63
65
|
work.set(src.subarray(0, dim));
|
|
66
|
+
if (profile.pinnedChannels) {
|
|
67
|
+
for (const i of profile.pinnedChannels) {
|
|
68
|
+
if (work[i] >= PINNED_THRESHOLD)
|
|
69
|
+
work[i] = 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
if (symmetrizeMouth) {
|
|
65
73
|
for (const [li, ri] of profile.mouthPairs) {
|
|
66
74
|
const m = (work[li] + work[ri]) / 2;
|
|
@@ -28,6 +28,13 @@ const LIMIT_DEFS = [
|
|
|
28
28
|
["jawOpen", "mouthLipsTogetherDL"],
|
|
29
29
|
["jawOpen", "mouthLipsTogetherDR"],
|
|
30
30
|
];
|
|
31
|
+
/**
|
|
32
|
+
* Channels the stream pins at 1.0 for a whole reply. noseWrinkleUpperL/R
|
|
33
|
+
* arrive at exactly 1.0 on every frame (measured 2026-10-14 on staging and
|
|
34
|
+
* production, 15/15 replies), while the other limit-driver targets arrive
|
|
35
|
+
* near 0 for the rig to derive. Applied raw it is a frozen sneer.
|
|
36
|
+
*/
|
|
37
|
+
const PINNED_DEFS = ["noseWrinkleUpperL", "noseWrinkleUpperR"];
|
|
31
38
|
/** Production-tuned per-channel gains (short name → gain). */
|
|
32
39
|
export const MHA_RECOMMENDED_GAIN_TABLE = {
|
|
33
40
|
// Conversational aperture: 0.6 reads mumbled, raw bares the teeth.
|
|
@@ -73,6 +80,7 @@ export const MHA_PROFILE = {
|
|
|
73
80
|
limits: LIMIT_DEFS.flatMap(([s, t]) => MHA_INDEX[s] !== undefined && MHA_INDEX[t] !== undefined
|
|
74
81
|
? [[MHA_INDEX[s], MHA_INDEX[t]]]
|
|
75
82
|
: []),
|
|
83
|
+
pinnedChannels: new Set(PINNED_DEFS.flatMap((n) => (MHA_INDEX[n] !== undefined ? [MHA_INDEX[n]] : []))),
|
|
76
84
|
recommendedGains: (() => {
|
|
77
85
|
const g = new Float32Array(METAHUMAN_ORDER_251.length).fill(1);
|
|
78
86
|
for (const [name, gain] of Object.entries(MHA_RECOMMENDED_GAIN_TABLE)) {
|
|
@@ -18,6 +18,13 @@ export interface LipsyncFormatProfile {
|
|
|
18
18
|
* jawOpen → mouthLipsTogether*). Empty for formats without them.
|
|
19
19
|
*/
|
|
20
20
|
limits: ReadonlyArray<readonly [sourceIdx: number, targetIdx: number]>;
|
|
21
|
+
/**
|
|
22
|
+
* Channels the stream is known to pin at 1.0 as an artifact rather than
|
|
23
|
+
* an expression. A value at or above 0.999 on one of these is treated as
|
|
24
|
+
* 0 before the couplings run, so the coupling derives the channel from its
|
|
25
|
+
* source instead. Omit for formats without such channels.
|
|
26
|
+
*/
|
|
27
|
+
pinnedChannels?: ReadonlySet<number>;
|
|
21
28
|
/** Per-channel production-tuned gains (length = frame dim, default 1). */
|
|
22
29
|
recommendedGains: Float32Array;
|
|
23
30
|
/** Channel indices owned by procedural blink/gaze systems. */
|
|
@@ -6,7 +6,7 @@ import { type CharacterInfo } from "../../core/characterInfo.js";
|
|
|
6
6
|
* the same code rather than a hand-synced copy of it.
|
|
7
7
|
*
|
|
8
8
|
* @param characterId - Character to look up
|
|
9
|
-
* @param apiKey - Convai API key, sent as `
|
|
9
|
+
* @param apiKey - Convai API key, sent as `CONVAI-API-KEY`
|
|
10
10
|
* @param authToken - Preferred over `apiKey`, sent as `API-AUTH-TOKEN`
|
|
11
11
|
* @param baseUrl - Origin to ask; defaults to `https://api.convai.com`. Pass
|
|
12
12
|
* `client.characterInfoUrl` so a non-SaaS deployment is not asked to send
|
|
@@ -8,7 +8,7 @@ import { fetchCharacterInfo, FALLBACK_CHARACTER_NAME, } from "../../core/charact
|
|
|
8
8
|
* the same code rather than a hand-synced copy of it.
|
|
9
9
|
*
|
|
10
10
|
* @param characterId - Character to look up
|
|
11
|
-
* @param apiKey - Convai API key, sent as `
|
|
11
|
+
* @param apiKey - Convai API key, sent as `CONVAI-API-KEY`
|
|
12
12
|
* @param authToken - Preferred over `apiKey`, sent as `API-AUTH-TOKEN`
|
|
13
13
|
* @param baseUrl - Origin to ask; defaults to `https://api.convai.com`. Pass
|
|
14
14
|
* `client.characterInfoUrl` so a non-SaaS deployment is not asked to send
|
|
@@ -103,18 +103,6 @@ export const useConvaiClient = (config) => {
|
|
|
103
103
|
setIsVideoEnabled(false);
|
|
104
104
|
setIsScreenShareActive(false);
|
|
105
105
|
});
|
|
106
|
-
// WebSocket transport: play bot audio track via a hidden <audio> element
|
|
107
|
-
const wsAudioEl = document.createElement("audio");
|
|
108
|
-
wsAudioEl.autoplay = true;
|
|
109
|
-
wsAudioEl.dataset.convaiWs = "true";
|
|
110
|
-
document.body.appendChild(wsAudioEl);
|
|
111
|
-
const unsubBotAudioTrack = client.on("botAudioTrack", (track) => {
|
|
112
|
-
wsAudioEl.srcObject = new MediaStream([track]);
|
|
113
|
-
});
|
|
114
|
-
// Disconnect listener also clears WS audio
|
|
115
|
-
const unsubDisconnectWsAudio = client.on("disconnect", () => {
|
|
116
|
-
wsAudioEl.srcObject = null;
|
|
117
|
-
});
|
|
118
106
|
// Audio controls state change listener
|
|
119
107
|
const unsubAudioState = client.audioControls.on("audioStateChange", (audioState) => {
|
|
120
108
|
if (audioState.isAudioMuted !== undefined) {
|
|
@@ -142,13 +130,9 @@ export const useConvaiClient = (config) => {
|
|
|
142
130
|
unsubBotReady();
|
|
143
131
|
unsubConnect();
|
|
144
132
|
unsubDisconnect();
|
|
145
|
-
unsubBotAudioTrack();
|
|
146
|
-
unsubDisconnectWsAudio();
|
|
147
133
|
unsubAudioState();
|
|
148
134
|
unsubVideoState();
|
|
149
135
|
unsubScreenShareState();
|
|
150
|
-
wsAudioEl.srcObject = null;
|
|
151
|
-
wsAudioEl.remove();
|
|
152
136
|
};
|
|
153
137
|
}, [client]);
|
|
154
138
|
// Create enhanced connect function that can use stored config
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Core-service can hand the client bot text with links preserved
|
|
5
5
|
* (`preserve_links_in_output` on /connect): `[text](url)`, `` and
|
|
6
|
-
* bare `http(s)://` URLs arrive verbatim,
|
|
7
|
-
* server-side.
|
|
8
|
-
* map onto DOM or JSX.
|
|
6
|
+
* bare `http(s)://` URLs arrive verbatim, other markdown is still flattened
|
|
7
|
+
* server-side. A markdown link keeps its target whatever the scheme. This
|
|
8
|
+
* turns one line of that text into nodes a renderer can map onto DOM or JSX.
|
|
9
9
|
*
|
|
10
|
-
* Only
|
|
11
|
-
*
|
|
10
|
+
* Only the schemes in `SAFE_SCHEMES` (http, https, ftp, ftps, mailto, tel,
|
|
11
|
+
* sms) become links or images. Anything else — including
|
|
12
|
+
* `javascript:` and `data:` — becomes a `blocked` node, regardless of what the
|
|
13
|
+
* server sent.
|
|
12
14
|
* A link whose closing paren has not streamed in yet is left as text too, so
|
|
13
15
|
* a bubble does not flicker between shapes mid-response.
|
|
14
16
|
*/
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Core-service can hand the client bot text with links preserved
|
|
5
5
|
* (`preserve_links_in_output` on /connect): `[text](url)`, `` and
|
|
6
|
-
* bare `http(s)://` URLs arrive verbatim,
|
|
7
|
-
* server-side.
|
|
8
|
-
* map onto DOM or JSX.
|
|
6
|
+
* bare `http(s)://` URLs arrive verbatim, other markdown is still flattened
|
|
7
|
+
* server-side. A markdown link keeps its target whatever the scheme. This
|
|
8
|
+
* turns one line of that text into nodes a renderer can map onto DOM or JSX.
|
|
9
9
|
*
|
|
10
|
-
* Only
|
|
11
|
-
*
|
|
10
|
+
* Only the schemes in `SAFE_SCHEMES` (http, https, ftp, ftps, mailto, tel,
|
|
11
|
+
* sms) become links or images. Anything else — including
|
|
12
|
+
* `javascript:` and `data:` — becomes a `blocked` node, regardless of what the
|
|
13
|
+
* server sent.
|
|
12
14
|
* A link whose closing paren has not streamed in yet is left as text too, so
|
|
13
15
|
* a bubble does not flicker between shapes mid-response.
|
|
14
16
|
*/
|
|
@@ -259,7 +259,7 @@ export function createConvaiWidget(container, options) {
|
|
|
259
259
|
// behave identically in both places.
|
|
260
260
|
//
|
|
261
261
|
// The two travel in *different* headers, which requestCharacterInfo
|
|
262
|
-
// handles: an auth token goes in API-AUTH-TOKEN, an API key in
|
|
262
|
+
// handles: an auth token goes in API-AUTH-TOKEN, an API key in CONVAI-API-KEY,
|
|
263
263
|
// and the host answers an API key sent as API-AUTH-TOKEN with `400 Your
|
|
264
264
|
// session has expired.` The failure is swallowed below, so getting it
|
|
265
265
|
// wrong showed up only as a header stuck on the fallback name.
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { EventEmitter } from "../core/EventEmitter.js";
|
|
2
|
-
/**
|
|
3
|
-
* Adapter that wraps PipecatClient + WebSocketTransport for use in ConvaiClient.
|
|
4
|
-
*
|
|
5
|
-
* Responsibilities:
|
|
6
|
-
* - Manage PipecatClient lifecycle (connect, disconnect)
|
|
7
|
-
* - Forward all RTVI events back to MessageHandler by re-encoding them as {type, data} payloads
|
|
8
|
-
* - Send outgoing messages via PipecatClient.sendClientMessage (Pipecat wraps to {t, d} envelope)
|
|
9
|
-
* - Expose mic control and bot audio track
|
|
10
|
-
*
|
|
11
|
-
* The caller is responsible for making the HTTP /connect request.
|
|
12
|
-
* Pass the parsed response object to connect() — WebSocketTransport extracts
|
|
13
|
-
* wsUrl/ws_url automatically.
|
|
14
|
-
*/
|
|
15
2
|
export declare class WebSocketSession extends EventEmitter {
|
|
16
3
|
private _pcClient;
|
|
4
|
+
private readonly _transport;
|
|
17
5
|
private _isConnected;
|
|
18
6
|
private readonly _onMessage;
|
|
7
|
+
private _botAudioMuted;
|
|
8
|
+
private _botGain;
|
|
9
|
+
private _player;
|
|
19
10
|
constructor(onMessage: (payload: Uint8Array) => void, enableMic?: boolean);
|
|
20
11
|
get isConnected(): boolean;
|
|
21
12
|
/**
|
|
@@ -38,6 +29,21 @@ export declare class WebSocketSession extends EventEmitter {
|
|
|
38
29
|
* silence (no speech), and Daily's internal state never changes.
|
|
39
30
|
*/
|
|
40
31
|
enableMic(enable: boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* Silence (or restore) the character's audio for the listener. The
|
|
34
|
+
* character keeps speaking; what it says while muted is dropped, not queued.
|
|
35
|
+
*/
|
|
36
|
+
setBotAudioMuted(muted: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Pipecat's WebSocket transport plays the character through its own
|
|
39
|
+
* WavStreamPlayer, wiring each new stream straight to the speakers, and
|
|
40
|
+
* exposes no track to mute. Wrap the player's stream start so every stream
|
|
41
|
+
* goes through a GainNode instead. These are Pipecat internals, so each one
|
|
42
|
+
* is feature-checked: if they are missing, mute degrades to a warning rather
|
|
43
|
+
* than breaking playback.
|
|
44
|
+
*/
|
|
45
|
+
private _routePlayerThroughGain;
|
|
46
|
+
private _attachGain;
|
|
41
47
|
getBotAudioTrack(): MediaStreamTrack | null;
|
|
42
48
|
private _getLocalAudioTrack;
|
|
43
49
|
private _setupMessageForwarding;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import { PipecatClient, RTVIEvent } from "@pipecat-ai/client-js";
|
|
2
2
|
import { WebSocketTransport } from "@pipecat-ai/websocket-transport";
|
|
3
3
|
import { EventEmitter } from "../core/EventEmitter.js";
|
|
4
|
-
/**
|
|
5
|
-
* Adapter that wraps PipecatClient + WebSocketTransport for use in ConvaiClient.
|
|
6
|
-
*
|
|
7
|
-
* Responsibilities:
|
|
8
|
-
* - Manage PipecatClient lifecycle (connect, disconnect)
|
|
9
|
-
* - Forward all RTVI events back to MessageHandler by re-encoding them as {type, data} payloads
|
|
10
|
-
* - Send outgoing messages via PipecatClient.sendClientMessage (Pipecat wraps to {t, d} envelope)
|
|
11
|
-
* - Expose mic control and bot audio track
|
|
12
|
-
*
|
|
13
|
-
* The caller is responsible for making the HTTP /connect request.
|
|
14
|
-
* Pass the parsed response object to connect() — WebSocketTransport extracts
|
|
15
|
-
* wsUrl/ws_url automatically.
|
|
16
|
-
*/
|
|
17
4
|
export class WebSocketSession extends EventEmitter {
|
|
18
5
|
constructor(onMessage, enableMic = true) {
|
|
19
6
|
super();
|
|
20
7
|
this._isConnected = false;
|
|
8
|
+
this._botAudioMuted = false;
|
|
9
|
+
this._botGain = null;
|
|
10
|
+
this._player = null;
|
|
21
11
|
this._onMessage = onMessage;
|
|
12
|
+
this._transport = new WebSocketTransport();
|
|
22
13
|
this._pcClient = new PipecatClient({
|
|
23
|
-
transport:
|
|
14
|
+
transport: this._transport,
|
|
24
15
|
enableMic,
|
|
25
16
|
enableCam: false,
|
|
26
17
|
callbacks: {
|
|
@@ -38,6 +29,7 @@ export class WebSocketSession extends EventEmitter {
|
|
|
38
29
|
},
|
|
39
30
|
});
|
|
40
31
|
this._setupMessageForwarding();
|
|
32
|
+
this._routePlayerThroughGain();
|
|
41
33
|
}
|
|
42
34
|
get isConnected() {
|
|
43
35
|
return this._isConnected;
|
|
@@ -83,6 +75,58 @@ export class WebSocketSession extends EventEmitter {
|
|
|
83
75
|
this._pcClient.enableMic(enable);
|
|
84
76
|
}
|
|
85
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Silence (or restore) the character's audio for the listener. The
|
|
80
|
+
* character keeps speaking; what it says while muted is dropped, not queued.
|
|
81
|
+
*/
|
|
82
|
+
setBotAudioMuted(muted) {
|
|
83
|
+
this._botAudioMuted = muted;
|
|
84
|
+
if (this._botGain)
|
|
85
|
+
this._botGain.gain.value = muted ? 0 : 1;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Pipecat's WebSocket transport plays the character through its own
|
|
89
|
+
* WavStreamPlayer, wiring each new stream straight to the speakers, and
|
|
90
|
+
* exposes no track to mute. Wrap the player's stream start so every stream
|
|
91
|
+
* goes through a GainNode instead. These are Pipecat internals, so each one
|
|
92
|
+
* is feature-checked: if they are missing, mute degrades to a warning rather
|
|
93
|
+
* than breaking playback.
|
|
94
|
+
*/
|
|
95
|
+
_routePlayerThroughGain() {
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
const player = this._transport?._mediaManager?._wavStreamPlayer;
|
|
98
|
+
if (!player || typeof player._start !== "function") {
|
|
99
|
+
console.warn("[ConvaiClient] This @pipecat-ai/websocket-transport version exposes no audio player to mute; " +
|
|
100
|
+
"setCharacterMuted() will not silence the character on the WebSocket transport.");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this._player = player;
|
|
104
|
+
const start = player._start.bind(player);
|
|
105
|
+
player._start = () => {
|
|
106
|
+
const result = start();
|
|
107
|
+
this._attachGain();
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
this._attachGain();
|
|
111
|
+
}
|
|
112
|
+
_attachGain() {
|
|
113
|
+
const context = this._player?.context;
|
|
114
|
+
const node = this._player?.stream;
|
|
115
|
+
if (!context || !node)
|
|
116
|
+
return;
|
|
117
|
+
if (!this._botGain || this._botGain.context !== context) {
|
|
118
|
+
this._botGain = context.createGain();
|
|
119
|
+
this._botGain.connect(context.destination);
|
|
120
|
+
}
|
|
121
|
+
this._botGain.gain.value = this._botAudioMuted ? 0 : 1;
|
|
122
|
+
try {
|
|
123
|
+
node.disconnect(context.destination);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Not connected to the destination (already routed through the gain).
|
|
127
|
+
}
|
|
128
|
+
node.connect(this._botGain);
|
|
129
|
+
}
|
|
86
130
|
getBotAudioTrack() {
|
|
87
131
|
return this._pcClient.tracks().bot?.audio ?? null;
|
|
88
132
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.9.
|
|
1
|
+
export declare const SDK_VERSION = "1.9.3";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@convai/web-sdk",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"description": "Build web apps with lifelike AI characters. The Convai Web SDK gives you real-time voice, lipsync, emotions, and dynamic context — with first-class support for React and vanilla TypeScript.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|