Skip to main content
WebSocketTransport enables a purely WebSocket based connection between clients and your Pipecat application. It implements bidirectional audio streaming using a WebSocket for real-time communication. This transport is intended for lightweight implementations, particularly for local development and testing. It expects your Pipecat server to include the corresponding WebSocketTransport server-side implementation.
The WebSocketTransport is best suited for server-server applications and prototyping client/server apps.For client/server production applications, we strongly recommend using a WebRTC-based transport for robust network and media handling. For more on WebRTC vs. Websocket communication, check out this article.

Usage

Basic Setup

API Reference

Constructor Options

Properties

TransportConnectionParams

connect() accepts WebSocketTransportOptions: wsUrl (or the deprecated ws_url) and token. wsUrl overrides the value set in the constructor. token is appended to the URL as a URL-encoded token query parameter; it is read only from connect(), so a token passed to the constructor is ignored. Any other key raises an RTVIError, so the serializer, media manager and sample rates are constructor-only.

Methods

For most operations, you will not interact with the transport directly. Most methods have an equivalent in the PipecatClient and should be called from the PipecatClient. However, there are a few transport-specific methods that you may need to call directly. When doing so, be sure to access your transport via the transport property of the PipecatClient instance.
method
Sends an ArrayBuffer of user audio to the bot through the serializer, queuing it until the transport is ready. The transport registers this method as the media manager’s audio callback, so microphone audio is sent without calling it; call it only for audio from another source.
method
Sends a message that is not an RTVI message, encoded with the serializer’s serialize(). Use it to send Twilio media stream events, such as connected and start, with TwilioSerializer.

Media Support

WebSocketTransport carries audio only. cam, screenShare, and botVideo are false, and mic follows the configured media manager. See mediaSupport.

Events

The transport implements the various PipecatClient event handlers.

Reconnection Handling

WebSocketTransport does not reconnect. If the WebSocket connection closes unexpectedly, the transport reports a fatal error through onError and the PipecatClient disconnects.

More Information

WebSocket Demo

Basic Agent example using a WebSocket transport

Twilio Demo

Example using a WebSocket transport to simulate a Twilio connection to a bot

Source

WebSocketTransport

Package

@pipecat-ai/websocket-transport