Learn what is in the Akool-Jssdk
StreamingAvatar
class and its usage, including the parameters, methods, events, and examples.
new StreamingAvatar(params?: { token: string, openapiHost?: string })
StreamingAvatar
.
params.token
(string) - Required. Open API authentication token.params.openapiHost
(string) - Optional. API host URL.async startSession(videoContainer?: string, params?: InitParams): Promise<void>
videoContainer
(string) - The ID of the HTML container where the avatar video will be displayed.params
(InitParams) - Configuration options for the avatar session.async startSessionWithCredentials(videoContainer?: string, params?: CredentialParams): Promise<void>
videoContainer
(string) - The ID of the HTML container for the avatar video.params
(CredentialParams) - Credential details for joining an Agora session.async closeStreaming(): Promise<void>
async sendMessage(message: string): Promise<void>
message
(string) - The message to send.async toggleMic(): Promise<void>
initDom(containerId: string, params?: InitParams): void
containerId
(string) - The ID of the HTML element to contain the avatar UI.params
(InitParams) - Optional parameters for session configuration.on(event: StreamEvents, handler: (event: CustomEvent) => void): void
event
(StreamEvents) - The event name.handler
(function) - The callback function to execute when the event occurs.off(event: StreamEvents, handler: (event: CustomEvent) => void): void
emit(event: StreamEvents, params?: any): void
micStatus: boolean
classStatus: object
StreamingAvatar
instance.
StreamEvents
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. |
InitParams
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
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. |