This topic describes the APIs available in AlCallKit SDK for Web.
Overview
Earlier versions of the SDK contain deprecated parameters and methods. We recommend that you update the SDK to the latest version. For more information, see Web guide.
Class/Protocol | API | Description |
ARTCAICallEngine An engine instance | Starts a call. | |
Ends a call. Note We recommend that you call this operation to end the call before exiting the page. Failing to do so may cause the agent to remain active for approximately 90 seconds before exiting, potentially exceeding the concurrency limit of the avatar agent. | ||
Configures the rendering view for the agent. | ||
Sets the local video view. | ||
Interrupts the agent's speech. | ||
Enables or disables intelligent interruption. | ||
Enables or disables camera push. | ||
Switches between the front and rear cameras. | ||
Changes the voice. | ||
Mutes or unmutes the microphone. | ||
Mutes or unmutes the agent's audio output. | ||
Starts speaking in push-to-talk mode. | ||
Finishes speaking in push-to-talk mode. | ||
Cancels speaking in push-to-talk mode. | ||
Enables or disables push-to-talk mode. | ||
Queries the information about the real-time communication (RTC) engine instance. | ||
Sends a text message to the agent. | ||
Sends a custom message to the AppServer. | ||
Updates the system prompt for the large language model (LLM). | ||
Starts custom frame capture. | ||
Ends custom frame capture. | ||
Releases resources. | ||
ARTCAICallEngine Callback events of the engine instance | An error occurred. | |
A call has started. | ||
A call has ended. | ||
The agent's status has changed. | ||
The volume has changed. | ||
The agent recognizes the user's question. | ||
The agent returns an answer. | ||
The agent's voice has changed. | ||
The push-to-talk mode has changed. | ||
The agent is about to end the current call. | ||
A custom message has been received from the agent. | ||
The status of voice interruption has changed. | ||
A human agent is stepping in to take over from the current agent. | ||
A human agent has taken over from the current agent. | ||
The agent's data channel is ready for use. |
Details
ARTCAICallEngine details
call
Starts a call.
async call(userId: string, agentInfo: AICallAgentInfo, config?: AICallEngineConfig): Promise<void>>Parameter | Type | Description |
userId | String | The UID of the current user. |
agentInfo | AICallAgentInfo | The agent information. |
config | AICallEngineConfig | The initialization configuration. Example: |
handup
Ends a call.
async handup(): Promise<void>setAgentView
Configures the rendering view for the agent.
setAgentView(view: HTMLVideoElement | string): voidParameter | Type | Description |
view | HTMLVideoElement | string | The video element or its ID. |
setLocalView
Sets the local video view.
setLocalView(view?: HTMLVideoElement | string): voidParameter | Type | Description |
view | HTMLVideoElement | string | The video element or its ID. If it is left empty, preview is disabled. |
interruptSpeaking
Interrupts the agent's speech.
async interruptSpeaking(): Promise<void>enableVoiceInterrupt
Enables or disables intelligent interruption.
async enableVoiceInterrupt(enable: boolean): Promise<void>Parameter | Type | Description |
enable | boolean | Specifies whether to enable intelligent interruption. |
muteLocalCamera
Enables or disables camera push.
async muteLocalCamera(mute: boolean)Parameter | Type | Description |
mute | boolean | Specifies whether to enable the camera. |
switchCamera
Switches between the front and rear cameras.
async switchCamera(deviceId?: string)Parameter | Type | Description |
deviceId | string | The device ID. You can query the device ID by using ARTCAICallEngine.getCameraList(). If you do not specify this parameter, a camera switch is performed on the mobile phone. |
switchVoiceId
Changes the voice.
async switchVoiceId(voiceId: string): Promise<void>Parameter | Type | Description |
voiceId | string | The voice ID. |
mute
Mutes or unmutes the microphone.
async mute(mute: boolean): Promise<void>Parameter | Type | Description |
mute | boolean | Specifies whether to mute the microphone. |
muteAgentAudioPlaying
Mutes or unmutes the agent's audio output.
muteAgentAudioPlaying(mute: boolean)Parameter | Type | Description |
mute | boolean | Specifies whether to mute the agent's audio output. |
startPushToTalk
Starts speaking in push-to-talk mode.
startPushToTalk() :boolean;finishPushToTalk
Finishes speaking in push-to-talk mode.
finishPushToTalk() :boolean;cancelPushToTalk
Cancels speaking in push-to-talk mode.
cancelPushToTalk() :boolean;enablePushToTalk
Enables or disables push-to-talk mode. In push-to-talk mode, the agent returns a result only after the finishPushToTalk operation is called.
enablePushToTalk(enable: boolean):boolean;Parameter | Type | Description |
enable | Bool | Specifies whether to enable push-to-talk mode. |
getRTCInstance
Queries the information about the RTC engine instance.
getRTCInstance(): AliRtcEngine | undefinedsendTextToAgent
Sends a text message to the agent.
sendTextToAgent(req: AICallSendTextToAgentRequest);Parameter | Type | Description |
req | AICallSendTextToAgentRequest | The message struct to send. |
sendCustomMessageToServer
Sends a custom message to the AppServer. Call this operation after the call session is initiated.
sendCustomMessageToServer(msg: string)Parameter | Type | Description |
msg | string | The message content. |
updateLlmSystemPrompt
Updates the system prompt for the LLM. Call this operation after the call session is initiated.
updateLlmSystemPrompt(prompt: string)Parameter | Type | Description |
prompt | string | The prompt. |
startVisionCustomCapture
Starts custom frame capture. Once started, voice communication with the vision agent will be disabled. Call this operation after initiating the call with the vision agent.
startVisionCustomCapture(req: AICallVisionCustomCaptureRequest)Parameter | Type | Description |
req | AICallVisionCustomCaptureRequest | The configurations. |
stopVisionCustomCapture
Ends custom frame capture. Call this operation after initiating the call with the vision agent.
stopVisionCustomCapture()destroy
Releases resources.
async destroy()ARTCAICallEngine events
errorOccurred
An error occurred during the current call.
Parameter | Type | Description |
code | AICallErrorCode | The error code. |
callBegin
A call has started.
callEnd
A call has ended.
agentStateChanged
The agent's status has changed.
Parameter | Type | Description |
state | AICallAgentState | The agent's status. It can be listening, thinking, or speaking. |
speakingVolumeChanged
The volume has changed.
Parameter | Type | Description |
uid | string | The UID of the current speaker. The value is an empty string if the speaker is the current user. |
volume | Int32 | The volume. Valid values: 0 to 100. |
userSubtitleNotify
The agent recognizes the user's question.
Parameter | Type | Description |
subtitle | AICallSubtitleData | The subtitle. |
agentSubtitleNotify
The agent returns an answer.
Parameter | Type | Description |
subtitle | AICallSubtitleData | The subtitle. |
voiceIdChanged
The agent's voice has changed.
Parameter | Type | Description |
voiceId | string | The voice ID. |
pushToTalkChanged
The push-to-talk mode has changed.
Parameter | Type | Description |
enable | boolean | Indicates whether push-to-talk mode is enabled. |
agentWillLeave
The agent is about to end the current call.
Parameter | Type | Description |
reason | number | The reason why the agent is leaving. Valid values:
|
message | string | The description of the reason. |
receivedAgentCustomMessage
A custom message has been received from the current agent.
Parameter | Type | Description |
data | Object | The message content. |
voiceInterruptChanged
The status of voice interruption has changed.
Parameter | Type | Description |
enable | boolean | Indicates whether voice interruption is enabled for the current call. |
humanTakeoverWillStart
A human agent is stepping in to take over from the current agent.
Parameter | Type | Description |
takeoverUid | string | The UID of the human agent. |
takeoverMode | number | The takeover mode. Valid values:
|
humanTakeoverConnected
A human agent has taken over from the current agent.
Parameter | Type | Description |
takeoverUid | string | The UID of the human agent. |
agentEmotionNotify
The agent detects an emotion.
Parameter | Type | Description |
emotion | string | The emotion tag, such as neutral, happy, angry, or sad. |
userAsrSentenceId | number | The ID of the sentence to which the user's question recognized by the agent belongs. |
agentDataChannelAvailable
The agent's data channel is ready for use. Once this callback is invoked, you can send messages to the agent.