async startBot(startBotParams: APIEndpoint): Promise<TransportConnectionParams | unknown>
This method hits your server endpoint to start the bot and optionally obtain the connection parameters needed for connect()
to connect the Transport
. It returns a Promise that resolves with the response from the server.
APIEndpoint
object should have the following shape:startBot()
process, the transport state will transition through the states: “authenticating” and “authenticated”.
async connect(connectParams): Promise<BotReadyData>
This method initiates the connection process, optionally passing parameters that your transport class requires to establish a connection or an endpoint to your server for obtaining those parameters.
TransportConnectionParams
your Transport expects.Check your transport class documentation for the expected shape of TransportConnectionParams
. For example, the DailyTransport expects a url
and token
.ConnectionEndpoint
object directly to connect()
. Instead, you should use the startBot()
or startBotAndConnect()
methods to fetch connection parameters from your server endpoint and then pass those parameters directly to connect()
.connect()
asynchronously will resolve when the bot and client signal that they are ready. See messages and events. If you want to call connect()
without await
, you can use the onBotReady
callback or BotReady
event to know when you can interact with the bot.connect()
when the transport is already in a ‘connected’ or ‘ready’ state will throw an error. You should disconnect from a session first before attempting to connect again.async startBotAndConnect(startBotParams: APIEndpoint): Promise<BotReadyData>
This method combines the functionality of startBot()
and connect()
. It first starts the bot by hitting your server endpoint and then connects the transport passing the response from the endpoint to the transport as connection parameters.
pcClient.startBot(...).then((resp) => pcClient.connect(resp))
.
async disconnect(): Promise<void>
Disconnects from the active session. The transport state will transition to “disconnecting” and then “disconnected”.
It is common practice for bots to exit and cleanup when the client disconnects.
disconnectBot(): void
Triggers the bot to disconnect from the session, leaving the client connected.
sendClientMessage(msgType: string, data?: unknown): void
Sends a custom message to the bot and does not expect a response. This is useful for sending data to the bot or triggering specific actions.
async sendClientRequest(msgType: string, data: unknown, timeout?: number): Promise<unknown>
Sends a custom request to the bot and expects a response. This is useful for querying the server or triggering specific actions that require a response. The method returns a Promise that resolves with the data from response.
'error-response'
.async initDevices(): Promise<void>
Initializes the media device selection machinery, based on enableCam
/enableMic
selections and defaults (i.e. turns on the local cam/mic). This method can be called before connect()
to test and switch between camera and microphone sources.
async getAllMics(): Promise<MediaDeviceInfo[]>
Returns a list of available microphones in the form of MediaDeviceInfo[]
.
async getAllCams(): Promise<MediaDeviceInfo[]>
Returns a list of available cameras in the form of MediaDeviceInfo[]
.
async getAllSpeakers(): Promise<MediaDeviceInfo[]>
Returns a list of available speakers in the form of MediaDeviceInfo[]
.
selectedMic: MediaDeviceInfo | {}
The currently selected microphone, represented as a MediaDeviceInfo
object. If no microphone is selected, it returns an empty object.
selectedCam: MediaDeviceInfo | {}
The currently selected camera, represented as a MediaDeviceInfo
object. If no camera is selected, it returns an empty object.
selectedSpeaker: MediaDeviceInfo | {}
The currently selected speaker, represented as a MediaDeviceInfo
object. If no speaker is selected, it returns an empty object.
updateMic(micId: string): void
Switches to the microphone identified by the provided micId
, which should match a deviceId
in the list returned from getAllMics()
.
updateCam(camId: string): void
Switches to the camera identified by the provided camId
, which should match a deviceId
in the list returned from getAllCams()
.
updateSpeaker(speakerId: string): void
Switches to the speaker identified by the provided speakerId
, which should match a deviceId
in the list returned from getAllSpeakers()
.
enableMic(enable: boolean): void
Turn on or off (unmute or mute) the client mic input.
true
) or disable (false
) the microphone.enableCam(enable: boolean): void
Turn on or off the client cam input.
true
) or disable (false
) the camera.enableScreenShare(enable: boolean): void
Start a screen share from the client’s device.
true
) or disable (false
) screen sharing.isMicEnabled: boolean
An accessor to determine if the client’s microphone is enabled.
isCamEnabled: boolean
An accessor to determine if the client’s camera is enabled.
tracks(): Tracks
Returns a Tracks
object with available MediaStreamTrack
objects for both the client and the bot.
async appendToContext(context: LLMContextMessage): boolean
A method to append data to the bot’s context. This is useful for providing additional information or context to the bot during the conversation.
registerFunctionCallHandler(functionName: string, callback: FunctionCallCallback): void
Registers a function call handler that will be called when the bot requests a function call. This is useful for when the server-side function handler needs information from the client to execute the function call or when the client needs to perform some action based on the running of function call.
type FunctionCallCallback = (fn: FunctionCallParams) => Promise<LLMFunctionCallResult | void>
The callback function to call when the bot sends a function call request. This function should accept the following parameters:The callback should return a Promise that resolves with the result of the function call or void if no result is needed. If returning a result, it should be a string
or Record<string, unknown>
.transport: Transport
A safe accessor for the transport instance used by the client. This is useful for accessing transport-specific methods or properties that are not exposed directly on the client.
setLogLevel(level: LogLevel): void
Sets the log level for the client. This is useful for debugging and controlling the verbosity of logs. The log levels are defined in the LogLevel
enum:
LogLevel.DEBUG
.