Skip to content
TriedDocs
Realtime and SDK

Web SDK

The browser client for web calls: methods, options and events of TriedWebClient.


title: Web SDK description: The browser client for web calls: methods, options and events of TriedWebClient. order: 2#

@tried/web-sdk connects a browser to a web call. It wraps livekit-client: you create the call on your server with Create web call, pass access_token and livekit_url to the browser, and call startCall(). The package lives in packages/web-sdk of the Tried repo.

The class is also exported as RetellWebClient, and its methods and event names follow the Retell browser SDK, so code written for it needs only the import changed.

Quick start#

import { TriedWebClient } from "@tried/web-sdk";

const client = new TriedWebClient();

client.on("call_started", () => console.log("connected"));
client.on("agent_start_talking", () => console.log("agent speaking"));
client.on("update", ({ transcript }) => console.log(transcript));
client.on("call_ended", () => console.log("ended"));
client.on("error", (err) => console.error(err));

// from your server: POST /v3/create-web-call
const { access_token, livekit_url } = await fetch("/api/web-call", { method: "POST" }).then((r) => r.json());
await client.startCall({ accessToken: access_token, livekitUrl: livekit_url });

Constructor options#

new TriedWebClient(options?)

Option Type Description
url string LiveKit URL used when startCall gets no livekitUrl. Default wss://livekit.tried.com.au.
audioContainer () => HTMLElement | null Where agent audio elements are attached. Default document.body.
roomFactory function Supplies the room object instead of a new livekit-client Room. Used by tests.

Methods#

Method Description
startCall(config) Connects to the room, turns on the microphone and emits call_started. Rejects (and emits error) when it fails. Throws if accessToken is missing.
stopCall() Leaves the room, removes the audio elements and emits call_ended.
mute() Turns the microphone off.
unmute() Turns the microphone on.
startAudioPlayback() Starts audio after a user gesture. Call it from a click handler if the browser blocked autoplay.
on(event, fn), once(event, fn), off(event, fn), removeAllListeners(event?) Manage listeners.

startCall config#

Field Type Required Description
accessToken string Yes access_token from Create web call.
livekitUrl string No livekit_url from Create web call.
sampleRate number No Microphone sample rate.
captureDeviceId string No Microphone device ID.
playbackDeviceId string No Speaker device ID.
emitRawAudioSamples boolean No Emit audio events with the agent's samples.

The microphone is opened with echo cancellation, noise suppression and auto gain control on.

Properties#

Property Type Description
isAgentTalking boolean Whether the agent is speaking now.
room object or null The underlying LiveKit room while connected.

Events#

Event Payload When
call_started none The browser joined the room and the microphone is on.
call_ready none The agent joined the room.
agent_start_talking none The agent's state changed to speaking.
agent_stop_talking none The agent stopped speaking.
update { transcript: [{ role, content }] } The live transcript changed. role is agent or user. Each segment updates in place as it streams.
metadata any The agent sent a JSON data message (no topic, or topic metadata).
audio Float32Array Agent audio samples, only with emitRawAudioSamples.
call_ended none The call ended: stopCall(), the room disconnected, or the agent left. Emitted once.
error unknown Connection failure, a transcript stream error, or an error thrown by one of your listeners.

The agent's speaking state comes from the lk.agent.state participant attribute, and transcripts from the lk.transcription text stream that the agent worker publishes.