Client Constructor
RTVI projects implement a client instance that:
- Facilitates web requests to an endpoint you create.
- Dispatches single-turn actions to a HTTP bot service when disconnected.
- Provides methods that handle the connectivity state and real-time interaction with your bot service.
- Manages media transport (such as audio and video).
- Provides callbacks and events for handling bot messages and actions.
- Optionally configures your AI services and pipeline.
RTVIClient
RTVIClient
is a base class that serves as a template for building transport-specific implementations.
For connected use-cases, you must pass a transport instance to the constructor for your chosen protocol or provider. See Transport for more information.
If you were looking to use WebRTC as a transport layer, you may use a provider like Daily. In this scenario, you’d construct a transport instance and pass it to the client accordingly:
All transport packages (such as DailyTransport
) extend from the Transport
base class defined in RTVI core.
You can extend this class if you are looking to implement your own or add additional functionality.
Example
API reference
transport
Instance of Transport
required to connect to your bot service (rtviClient.connect()
). Transports define connectivity and state logic that manage the lifecycle of your session.
Transports also define a protocol for message exchange between your client and bot service (such as actions, or generic messages.
If your transport package (e.g.
@daily-co/realtime-ai-daily
) exports multiple transports classes, you can
specify which to use here.
params
A client-side mutatable object that is used to configure how your client connects or triggers actions.
Parameters can be updated at any time during the client lifecycle.
Base URL to a developer hosted API that exposes various endpoints to the RTVI application.
Endpoints appended to your client base URL. RTVI will apply defaults if not provided.
Property | Description |
---|---|
connect:string | Developer hosted endpoint that triggers authentication, transport session creation and bot instantiation. Typically returns a valid authentication bundle required to join a session. Defaults to “connect/”. |
action:string | Developer hosted endpoint that triggers disconnected action for single-turn operations. Typically implemented as a HTTP Stream or Websocket. Defaults to “action/”. |
You should ensure your endpoints have the necessary CORS headers set to allow requests from your client application.
Custom request data that is passed to the baseUrl
with any web request. This can be used to pass additional data to your server-side endpoint.
Optional Headers
object that is used when making requests to the baseUrl
.
Pipeline RTVI configuration passed to your bot pipeline. Must contain a valid RTVIClientConfigOption[]
array.
Client configuration is optional and can be passed directly to the bot via your server-side endpoint (where sensitive information can be provided, such as API keys.)
The service order of your configuration array is important. See configuration.
Optional properties
Time (in milleseconds) to wait for the bot to enter a ready state after
calling connect()
. If the timeout period is elapsed, the client will return
a ConnectionTimeoutError
error and disconnect from the transport.
Enable user’s local microphone device.
Enable user’s local webcam device. Note: please ensure you are using a transport package that supports video.
Custom Connect Handler
Calling rtviClient.connect()
will trigger a default fetch query to your baseUrl/connect
endpoint. If you need to override this behaviour, you can provide a custom connect handler.
Override the default fetch query called by rtviClient.connect()
. If your server-side infrastructure has specific requirements, you can provide custom behaviour here.
params:RTVIClientParams
Params provided in client constructor.timeout:Timeout | undefined
Start timeout. You should clear this once your method resolves e.g.clearTimeout(timeout)
.abortController:AbortController
- Aborting connection viaabortController.abort()
will reject the inflight request, clear the connection timeout and set the client to an error state.