Skip to main content
FreyaClient is the main class exposed by the SDK. Access it via window.Freya.FreyaClient after loading the script.

Methods

connect()

Opens the WebRTC session and, in call mode, activates the microphone. Returns a promise that resolves once the connection is established.
Throws if called while already connected. Call disconnect() first if you need to start a new session.

disconnect()

Ends the current session and releases all media resources. Safe to call multiple times — subsequent calls after the session is already closed are no-ops.

sendMessage(text)

Sends a text message to the agent. Primarily used in "chat" mode, where the microphone is off and the user communicates by typing.

mute()

Stops sending microphone audio to the agent without disconnecting the session. Has no effect in "chat" mode.

unmute()

Resumes sending microphone audio after a call to mute().

on(event, handler)

Registers a handler for the given event. Returns the client instance so calls can be chained.
See Events below for the full list.

off(event, handler)

Removes a previously registered handler. The handler reference must be the same function passed to on().

Properties

state

The current transport state as a string. Reflects the underlying WebRTC connection lifecycle.

isMicEnabled

Boolean. true when the microphone is active and sending audio. Always false in "chat" mode and when the session is not connected.

Events

Register handlers with client.on(event, handler) and remove them with client.off(event, handler). All handlers receive a single payload argument (or none, for events with no data).

Connection events

stateChanged

Fires whenever the connection state changes. Use this to drive loading indicators, connected states, and error UI.

disconnected

Fires when the session ends, whether closed locally via disconnect() or terminated remotely. No payload.

error

Fires when an error occurs. When fatal is true the session has already ended — you do not need to call disconnect().

Agent speech events

botReady

Fires once after connect() when the agent has fully initialized and is ready to receive input. No payload.

botStartedSpeaking

Fires when the agent begins a spoken response. No payload. Use this to show a speaking indicator or pause user input.

botStoppedSpeaking

Fires when the agent finishes speaking. No payload. Use this to seal the current transcript turn and reset streaming state.

botLlmText

Fires for each token as the LLM generates its response. Concatenate the text values to build the full message in real time. Stops firing before botStoppedSpeaking.

botTranscript

Fires once per agent turn with the complete response text, after the agent finishes speaking. Use this instead of botLlmText if you only need the final result rather than a streaming view.

botOutput

Fires with TTS-level text chunks. Only fires when LLM streaming (botLlmText) is not available. In most configurations you can ignore this event and use botLlmText / botTranscript instead.

User speech events

userStartedSpeaking

Fires when voice activity is detected from the user’s microphone. No payload. Use this to show a recording indicator.

userStoppedSpeaking

Fires when the user’s voice activity stops. No payload.

userTranscript

Fires with the transcription of the user’s speech. Partial results arrive with final: false as the user speaks; the completed turn arrives with final: true.

Tool call events

toolCallStarted

Fires when the agent decides to invoke a tool, before arguments are assembled.

toolCallInProgress

Fires once the agent has fully assembled the arguments for a tool call. This is the right place to update your UI in response to agent actions — you know exactly what the agent is about to do.

toolCallStopped

Fires when a tool call completes.

Media track events

trackStarted

Fires when a remote media track becomes active. The SDK handles remote audio playback automatically — you only need this event if you want access to the raw MediaStreamTrack for custom processing.

trackStopped

Fires when a remote media track ends.