Transports are the means by which RTVI clients communicate with the RTVI-enable bot. They are responsible for sending and receiving messages between the client and the server as well as handling real-time media transport.

Transport lifecycle

Your transport instance is constructed when you call connect() on your client instance.

import { RTVIClient } from 'realtime-ai;
import { DailyTransport } from "@daily-co/realtime-ai-daily";

const rtviClient = new RTVIClient({
  transport: new DailyTransport(),
  ...
});

await rtviClient.connect(); // Transport instance is created here
await rtviClient.disconnect(); // Transport instance is destroyed here

Transport states

TransportState

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

1

Disconnected

Transport is idle and has not yet been initialized (default state).

2

Initializing

Transport is being initialized. Typically in response to a rtviClient.initDevices() call, where the transport is being set up in order to enumerate local media devices.

3

Initialized

Transport has been initialized and is ready to connect. This state is typically reached after a successful rtviClient.initDevices() call.

4

Authenticating

Your client has called rtviClient.connect() and is waiting for a response from your server containing ‘auth bundle’ credentials (such as a session URL and token.)

5

Connecting

Transport has received the ‘auth bundle’ and is connecting to the server.

6

Connected

Transport has successfully connected to the session and is awaiting a client-ready signal (indicicated audio and video tracks are ready to be sent.)

7

Ready

Transport is ready and the session can begin.
8

Disconnecting

Transport is disconnecting from the session.

9

Error

An error occurred during the transport lifecycle.

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

// Callback
const rtviClient = new RTVIClient({
  transport: new DailyTransport(),
  callbacks: {
	onTransportStateChange: (state) => {
	  console.log(state);
  }
  //...
});

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

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