Streaming Avatar SDK API Reference
Learn what is in the Akool-Jssdk
Documentation for StreamingAvatar Class
This document provides a detailed explanation of the StreamingAvatar
class and its usage, including the parameters, methods, events, and examples.
StreamingAvatar Class Documentation
Constructor
new StreamingAvatar(params?: { token: string, openapiHost?: string })
Creates an instance of StreamingAvatar
.
Parameters:
params.token
(string) - Required. Open API authentication token.params.openapiHost
(string) - Optional. API host URL.
Example Usage:
Public Methods
async startSession(videoContainer?: string, params?: InitParams): Promise<void>
Starts a new avatar session.
Parameters:
videoContainer
(string) - The ID of the HTML container where the avatar video will be displayed.params
(InitParams) - Configuration options for the avatar session.
Example Usage:
async startSessionWithCredentials(videoContainer?: string, params?: CredentialParams): Promise<void>
Starts a session using predefined credentials.
Parameters:
videoContainer
(string) - The ID of the HTML container for the avatar video.params
(CredentialParams) - Credential details for joining an Agora session.
Example Usage:
async closeStreaming(): Promise<void>
Closes the current streaming session.
Example Usage:
async sendMessage(message: string): Promise<void>
Sends a text message to the avatar.
Parameters:
message
(string) - The message to send.
Example Usage:
async toggleMic(): Promise<void>
Toggles the microphone on or off.
Example Usage:
initDom(containerId: string, params?: InitParams): void
Initializes the user interface for the avatar.
Parameters:
containerId
(string) - The ID of the HTML element to contain the avatar UI.params
(InitParams) - Optional parameters for session configuration.
Example Usage:
Event Handling
on(event: StreamEvents, handler: (event: CustomEvent) => void): void
Registers an event listener.
Parameters:
event
(StreamEvents) - The event name.handler
(function) - The callback function to execute when the event occurs.
Example Usage:
off(event: StreamEvents, handler: (event: CustomEvent) => void): void
Removes an event listener.
Example Usage:
emit(event: StreamEvents, params?: any): void
Manually triggers an event.
Example Usage:
Properties
micStatus: boolean
Returns the current microphone status.
Example Usage:
classStatus: object
Returns the current state of the StreamingAvatar
instance.
Example Usage:
Enums
StreamEvents
Defines event types emitted by the class.
Event Name | Description |
---|---|
READY | Fired when the session is ready. |
ONMESSAGE | Fired when a message is received. |
ERROR | Fired when an error occurs. |
WILLEXPIRE | Fired when the session is about to expire. |
EXPIRED | Fired when the session expires. |
CLOSED | Fired when the session is closed. |
Example Usage:
Interfaces
InitParams
Defines parameters for initializing a session.
Property | Type | Description |
---|---|---|
avatarId | string | Avatar ID. |
voiceId | string | Voice ID. |
language | string | Language code (e.g., ‘en’). |
modeType | string | Interaction mode (‘Repeat’ or ‘Dialogue’). |
background | string | Background image URL. |
voice_interaction_on | boolean | Enable voice interaction. |
duration | number | Session duration in seconds. |
CredentialParams
Defines credentials for joining an existing session.
Property | Type | Description |
---|---|---|
voiceId | string | Voice ID. |
language | string | Language code. |
modeType | string | Interaction mode. |
background | string | Background image URL. |
_id | string | Session ID. |
credentials | object | Agora credentials. |