Core Components
Low-level components for WebSocket communication and configuration.
EstuaryClient
Low-level WebSocket client for communicating with Estuary servers. Implements Socket.IO v4 protocol.
import { EstuaryClient, setInternetModule } from 'estuary-lens-studio-sdk';
Setup
// REQUIRED: Set InternetModule before creating client
setInternetModule(internetModule);
const client = new EstuaryClient();
Methods
| Method | Parameters | Description |
|---|---|---|
connect() | serverUrl, apiKey, characterId, playerId | Connect to Estuary server |
disconnect() | - | Disconnect from server |
sendText() | text: string | Send text message |
streamAudio() | audioBase64: string | Stream audio for STT |
notifyAudioPlaybackComplete() | - | Signal audio finished playing |
dispose() | - | Clean up resources |
Properties
| Property | Type | Description |
|---|---|---|
state | ConnectionState | Current connection state |
isConnected | boolean | Whether connected |
currentSession | SessionInfo | null | Session info when connected |
debugLogging | boolean | Enable debug logs |
Events
| Event | Data | Description |
|---|---|---|
sessionConnected | SessionInfo | Successfully connected |
disconnected | string | Connection closed |
botResponse | BotResponse | AI text response |
botVoice | BotVoice | AI voice audio |
sttResponse | SttResponse | Speech transcription |
interrupt | InterruptData | Conversation interrupted |
error | string | Error occurred |
connectionStateChanged | ConnectionState | State changed |
EstuaryConfig
Configuration interface for SDK connections.
interface EstuaryConfig {
serverUrl: string; // Server URL (wss://...)
apiKey?: string; // API key
characterId: string; // Character UUID
playerId: string; // User identifier
recordingSampleRate?: number; // Default: 16000
playbackSampleRate?: number; // Default: 24000
audioChunkDurationMs?: number; // Default: 100
autoReconnect?: boolean; // Default: true
maxReconnectAttempts?: number; // Default: 5
reconnectDelayMs?: number; // Default: 2000
debugLogging?: boolean; // Default: false
}
Helper Functions
// Merge with defaults
const config = mergeWithDefaults(partialConfig);
// Validate configuration
const error = validateConfig(config); // null if valid
// Check if valid
if (isConfigValid(config)) { ... }
// Create dev config
const devConfig = createDevConfig(apiKey, characterId, playerId);
ConnectionState
Enum representing connection states.
enum ConnectionState {
Disconnected = 'disconnected',
Connecting = 'connecting',
Connected = 'connected',
Reconnecting = 'reconnecting',
Error = 'error'
}