For the complete documentation index, see llms.txt. This page is also available as Markdown.

WebSocket Transport Layer

The SDK defaults to WebRTC for real-time voice conversations. In environments where WebRTC is unavailable, you can opt in to a WebSocket-based transport instead.

WebSocket transport is useful in mobile webviews with WebRTC restrictions, corporate networks that block UDP, or any platform where WebRTC is unsupported. It uses Pipecat under the hood and is fully opt-in — the pipecat packages are never bundled unless you explicitly import the transport subpath.


When to use WebSocket transport

Situation
Recommendation

Standard web app

WebRTC (default) — lower latency, better audio quality

Mobile webview with WebRTC restrictions

WebSocket

Corporate network blocking UDP/STUN/TURN

WebSocket

Bundle must not include @pipecat-ai

WebRTC (default — no extra import needed)

Fallback or testing path

WebSocket


Setup

The WebSocket transport is opt-in. The pipecat packages (@pipecat-ai/client-js, @pipecat-ai/websocket-transport) are never bundled unless you explicitly import the transport subpath.

React

// 1. Register the transport — must be imported before connect() is called
import '@convai/web-sdk/vanilla/websocket';

import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk/react';

export default function App() {
  const client = useConvaiClient({
    apiKey: '...',
    characterId: '...',
    transport: 'websocket',
  });

  return <ConvaiWidget convaiClient={client} />;
}

Vanilla JS

The import order matters — register before constructing the client.


Bundle isolation

ConvaiClient itself contains zero pipecat imports. The WebSocket implementation lives entirely in the @convai/web-sdk/vanilla/websocket subpath. A bundler (Vite, webpack, Rollup) that sees no import of that subpath will not include @pipecat-ai/client-js or @pipecat-ai/websocket-transport in any chunk.

If you call connect() with transport: "websocket" without importing the subpath first, the SDK throws a clear error:


Feature comparison

Feature
WebRTC (default)
WebSocket

Works without UDP

Requires @pipecat-ai

✓ (opt-in subpath)

Mobile webview support

Varies

Better

File upload for websocket transport layer: coming soon


Microphone behaviour

On WebRTC, the microphone is activated explicitly via audioControls.enableAudio() or the startWithAudioOn config flag.

On WebSocket, the Pipecat transport initialises the audio stream during connect(). The SDK defaults to mic-on at connection time and mutes immediately if startWithAudioOn: false:


API reference

Config

Field
Type
Default
Description

transport

"livekit" | "websocket"

"livekit"

Default uses WebRTC; "websocket" opts in to Pipecat WebSocket transport

Static method

registerWebSocketTransport accepts a factory with signature:

This lets you swap in a custom WebSocket session implementation if needed.

Last updated

Was this helpful?