Skip to main content
Version: 3.2.x

WebSocket Protocol

The Optave SDK uses WebSocket Secure (WSS) protocol for real-time, bidirectional communication with Optave AI services.

Connection Setup

For establishing connections and authentication, see Authentication & Connection.

Protocol Overview

The SDK uses WebSocket Secure (WSS) exclusively for all AI operations:

  • Single persistent bidirectional connection
  • JSON-encoded text frames
  • Request-response correlation via correlation IDs
  • No REST API for message operations

WebSocket Events

Standard WebSocket events:

EventWhen FiredPayload
openConnection establishedEvent
messageMessage receivedMessageEvent
errorError occurredError
closeConnection closedCloseEvent

Close Codes

Common WebSocket close codes:

CodeDescriptionAction
1000Normal closure✅ Clean close
1001Going away✅ Expected close
1006Abnormal closure⚠️ Retry connection
1008Policy violation❌ Don't retry
1011Server error⚠️ Retry with backoff
client.on('close', (event) => {
console.log(`Closed: ${event.code} - ${event.reason}`);

if (event.code === 1006) {
// Network issue - retry
reconnect();
}
});

Connection States

WebSocket connections have four states:

StateValueCan Send?
CONNECTING0❌ No
OPEN1✅ Yes
CLOSING2❌ No
CLOSED3❌ No
// Check connection state
const isConnected = client.wss?.readyState === 1;

if (isConnected) {
await client.summarize({ /* ... */ });
}

Authentication Transport

Two methods for sending authentication tokens:

Token sent via Sec-WebSocket-Protocol header:

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
tokenProvider: yourTokenProvider,
authTransport: 'subprotocol' // Default
});

Benefits:

  • ✅ Tokens not in server logs
  • ✅ More secure

Query Parameter

Token sent as URL parameter:

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
tokenProvider: yourTokenProvider,
authTransport: 'query'
});

Use cases:

  • Debugging (visible in network logs)
  • Legacy server compatibility