import { PipecatClient } from "@pipecat-ai/client-js";

PipecatClient is the primary component for building the client-side portion of a client-bot interaction. It is designed to work with various transport layers, such as WebRTC, WebSockets, or HTTP, allowing you to pick and choose the communication layer that best suits your application while maintaining a consistent API.

When initializing the PipecatClient, you must provide a transport instance to the constructor for your chosen protocol or provider. See Transport for more information. For the purpose of this guide, we’ll demonstrate using the Daily WebRTC transport.

Example

import { RTVIEvent, RTVIMessage, PipecatClient } from "@pipecat-ai/client-js";
import { DailyTransport } from "@pipecat-ai/daily-transport";

const PipecatClient = new PipecatClient({
  transport: new DailyTransport(),
  enableMic: true,
  enableCam: false,
  enableScreenShare: false,
  timeout: 15 * 1000,
  callbacks: {
    onConnected: () => {
      console.log("[CALLBACK] User connected");
    },
    onDisconnected: () => {
      console.log("[CALLBACK] User disconnected");
    },
    onTransportStateChanged: (state: string) => {
      console.log("[CALLBACK] State change:", state);
    },
    onBotConnected: () => {
      console.log("[CALLBACK] Bot connected");
    },
    onBotDisconnected: () => {
      console.log("[CALLBACK] Bot disconnected");
    },
    onBotReady: () => {
      console.log("[CALLBACK] Bot ready to chat!");
    },
  },
});

API reference

transport

transport
Class<Transport>
default:"undefined"
required

An instance of the Transport type you will use to connect to your bot service (PipecatClient.connect()). Transports implement the underlying device management, connectivity, media transmission, and state logic that manage the lifecycle of your session.

As a best practice, we recommend you construct the transport inline in the client constructor, as opposed to holding a reference to it. Access to the transport is typically unnecessary. For advanced use cases that do require access to the transport, we recommend doing so via the PipecatClient.transport property, which provides some additional safeguards.

import { PipecatClient } from "@pipecat-ai/client-js";
import { DailyTransport } from "@pipecat-ai/daily-transport";

const pcClient = new PipecatClient({
  transport: new DailyTransport(),
});

callbacks

callbacks
RTVIEventCallbacks
required

Map of callback functions. See callbacks.

Media Initialization

enableMic
boolean
default:"true"
required

Enable user’s local microphone device.

enableCam
boolean
default:"false"
required

Enable user’s local webcam device. Note: Not all transports support video. Setting this value in that case will have no effect.

enableScreenShare
boolean
default:"false"
required

Enable user’s local screen share. Note: Not all transports support screen sharing. Setting this value in that case will have no effect.