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
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
joinRoom
roomUrl: string
Promise<void>
Connects the assistant to the specified room
Media
startLocalMedia
void
Creates and starts local media for the assistant
getLocalAudioSource
RTCAudioSource | null
Returns the raw Node WebRTC audio source
getCombinedAudioStream
MediaStream
| null
Returns the mixed audio stream of all the remote participants
Remote Participants
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
sendChatMessage
message: string
void
Send a chat message into the room
Recording
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
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);
});
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?