Assistant

The Assistant class is the main entry point of the Assistants SDK. It runs in Node.js and provides everything that you need to connect an AI agent into a Whereby room - to access audio, manage in room actions and integrate with external services of your choice.

Constructor

const assistant = new Assistant(options: AssistantOptions)

AssistantOptions

Parameter
Type
Default
Description

assistantKey

string

-

Assistant key generated from the Whereby Dashboard

startCombinedAudioStream?

boolean

false

If true, creates a mixed audio stream of all remote participants FFmpeg is required if using this feature.

startLocalMedia?

boolean

false

If true, initializes local media for the assistant

Methods

Room Lifecycle

Method
Parameters
Returns
Description

joinRoom

roomUrl: string

Promise<void>

Connects the assistant to the specified room

getRoomConnection

Returns the underlying room connection

Media

Method
Parameters
Returns
Description

startLocalMedia

void

Creates and starts local media for the assistant

getLocalMediaStream

Returns the assistant's local media stream if started

getLocalAudioSource

RTCAudioSource | null

Returns the raw Node WebRTC audio source

getCombinedAudioStream

Returns the mixed audio stream of all the remote participants

Remote Participants

Method
Parameters
Returns
Description

getRemoteParticipants

List of current participants in the room

spotlightParticipant

id: string

void

Spotlights the specified participant in the room

removeSpotlight`

void

Removes spotlight from a participant in the room

requestAudioEnable

id: string, enable: boolean

void

Requests that the specified participant enables their audio

requestVideoEnabled

id: string, enable: boolean

void

Requests that the specified participant enables their video

acceptWaitingParticipant

id string

void

Accepts a participant from the waiting room

rejectWaitingParticipant

void

Rejects a participant in the waiting room

Chat

Method
Parameters
Returns
Description

sendChatMessage

message: string

void

Send a chat message into the room

Recording

Method
Parameters
Returns
Description

startCloudRecording

void

Starts a cloud recording. Must be enabled to be successful.

stopCloudRecording

void

Stops the active cloud recording.

State Subscriptions

All subscribe methods follow this format:

  • Call signature: subscribeX(callback: (payload: T) => void: () => void

  • Contract: Invokes a callback on initial subscription and whenever the state changes.

  • Returns: an unsubscribe function

Method
Payload Type
Description

subscribeToChatMessages

messages: ChatMessage[]

Emits chat messages from remote participants

subscribeToRemoteParticipants

participants: RemoteParticipantState[]

Emits the remote participant state

Events

Assistant extends EventEmitter . You can listen to lifecycle and state change events directly:

import { Assistant } from "@whereby.com/assistant";

const assistant = new Assistant({
  assistantKey: process.env.ASSISTANT_KEY,
  startCombinedAudioStream: true,
});

assistant.on(AUDIO_STREAM_READY, ({ stream }) => {
  console.log("Combined audio stream available", stream.id);
});

assistant.on(ASSISTANT_LEFT_ROOM, ({ roomUrl }) => {
  console.log("Assistant has left the room: ", roomUrl);
});
Event
Payload
Emitted when

AUDIO_STREAM_READY

{stream: MediaStream; track: MediaStreamTrack}

Combined audio stream is available

ASSISTANT_JOINED_ROOM

{ roomUrl: string }

Assistant has joined the room

ASSISTANT_LEFT_ROOM

{ roomUrl: string }

Assistant has left the room

PARTICIPANT_VIDEO_TRACK_ADDED

{ participantId: string; stream: MediaStream; track: MediaStreamTrack }

A remote participant has added or changed a video track

PARTICIPANT_VIDEO_TRACK_REMOVED

{ participantId: string; stream: MediaStream; track: MediaStreamTrack }

A remote participant has removed a video track

PARTICIPANT_AUDIO_TRACK_ADDED

{ participantId: string; stream: MediaStream; track: MediaStreamTrack }

A remote participant has added or changed an audio track

PARTICIPANT_AUDIO_TRACK_REMOVED

{ participantId: string; stream: MediaStream; track: MediaStreamTrack }

A remote participant has removed an audio track

Last updated

Was this helpful?