> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Transport Overview

Transports are the means by which `PipecatClient`s communicate with their bot services. Transports implement the underlying device management, connectivity, media transmission, and state logic that manage the lifecycle of your session.

All transport packages (such as `DailyTransport`) extend from the `Transport` base class defined in the `client-js` library. You can extend this class if you are looking to implement your own or add additional functionality.

## Transport lifecycle

Each Pipecat client instance is associated with a transport instance. The instance will re-use the transport instance across multiple calls to `connect()`, allowing you to connect to different bot services without needing to create a new transport or client each time.

```typescript theme={null}
import { PipecatClient } from "@pipecat-ai/client-js";
import { DailyTransport } from "@pipecat-ai/daily-transport";

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

await pcClient.startBotAndConnect({ endpoint: "/api/start" });
await pcClient.disconnect();
await pcClient.connect(); // re-uses url returned from previous startBotAndConnect call, skipping the endpoint
```

## Transport states

`TransportState`

Your transport instance goes through a series of states during its lifecycle. These states are:

<Steps>
  <Step title="Disconnected">
    Transport is idle and has not yet been initialized (default state).
  </Step>

  <Step title="Initializing">
    Transport is being initialized. This occurs in response to a
    `pcClient.initDevices()` call, where the transport is being set up in order
    to enumerate local media devices. If you call `connect()` and bypass
    `initDevices()`, the transport will skip this state and go directly to
    `Connecting`.
  </Step>

  <Step title="Initialized">
    Transport has been initialized and is ready to connect. This state is
    reached after a successful `pcClient.initDevices()` call and skipped if
    `initDevices()` is not used.
  </Step>

  <Step title="Authenticating">
    Your client has called `pcClient.startBot()` or
    `pcClient.startBotAndConnect()` and is waiting for a response from your
    server containing connection details for your transport (such as a session
    URL and token). Note: If you provide the `TransportConnectionParams`
    directly to `connect()` without calling either `startBot` methods, the
    transport will skip this state and go directly to `Connecting`.
  </Step>

  <Step title="Authenticated">
    Your client has called `pcClient.startBot()` or
    `pcClient.startBotAndConnect()` and has successfully received a response. If
    using `startBotAndConnect()`, it will quickly move into the `Connecting`
    state. Note: If you provide the `TransportConnectionParams` directly to
    `connect()` without calling either `startBot` methods, the transport will
    skip this state and go directly to `Connecting`.
  </Step>

  <Step title="Connecting">The transport is connecting to the server.</Step>

  <Step title="Connected">
    The transport has successfully connected to the session and is awaiting a
    client-ready signal (indicated audio and video tracks are ready to be sent
    and received).
  </Step>

  <Step title="Ready">Transport is ready and the session can begin.</Step>

  <Step title="Disconnecting">
    Transport is disconnecting from the session.
  </Step>

  <Step title="Error">
    An error occurred during the transport lifecycle. This indicates a fatal
    error and the transport should move quickly into the `Disconnected` state.
  </Step>
</Steps>

You can access the current transport state via `pcClient.state`, or by defining a callback or event:

```typescript theme={null}
// Callback
const pcClient = new PipecatClient({
  transport: new DailyTransport(),
  callbacks: {
    onTransportStateChange: (state) => {
      console.log(state);
    }
  //...
});

// Event
pcClient.on(RTVIEvent.TransportStateChanged, (e) => console.log(e));

// Client getter
console.log(pcClient.state); // Disconnected <TransportState>
```
