Skip to main content

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

MethodParametersDescription
connect()serverUrl, apiKey, characterId, playerIdConnect to Estuary server
disconnect()-Disconnect from server
sendText()text: stringSend text message
streamAudio()audioBase64: stringStream audio for STT
notifyAudioPlaybackComplete()-Signal audio finished playing
dispose()-Clean up resources

Properties

PropertyTypeDescription
stateConnectionStateCurrent connection state
isConnectedbooleanWhether connected
currentSessionSessionInfo | nullSession info when connected
debugLoggingbooleanEnable debug logs

Events

EventDataDescription
sessionConnectedSessionInfoSuccessfully connected
disconnectedstringConnection closed
botResponseBotResponseAI text response
botVoiceBotVoiceAI voice audio
sttResponseSttResponseSpeech transcription
interruptInterruptDataConversation interrupted
errorstringError occurred
connectionStateChangedConnectionStateState 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'
}