Skip to main content

Overview

This document provides comprehensive API documentation for the akool-streaming-avatar-sdk package. The SDK provides a generic JavaScript interface for integrating Agora RTC streaming avatar functionality into any JavaScript application. Package Links:

GenericAgoraSDK Class Documentation

Constructor

new GenericAgoraSDK(options?: { mode?: string; codec?: SDK_CODEC })

Creates an instance of the Generic Agora SDK.

Parameters:

  • options.mode (string) - Optional. SDK mode (default: “rtc”)
  • options.codec (SDK_CODEC) - Optional. Video codec (e.g., “vp8”, “h264”)

Example Usage:


Connection Management

async joinChannel(credentials: AgoraCredentials): Promise<void>

Joins an Agora RTC channel using the provided credentials.

Parameters:

  • credentials (AgoraCredentials) - Agora connection credentials

Example Usage:

async leaveChannel(): Promise<void>

Leaves the current Agora RTC channel.

Example Usage:

async closeStreaming(cb?: () => void): Promise<void>

Closes all connections and performs cleanup.

Parameters:

  • cb (function) - Optional callback function to execute after closing

Example Usage:

isConnected(): boolean

Checks if the SDK is connected to Agora services.

Returns:

  • boolean - Connection status

Example Usage:

isChannelJoined(): boolean

Checks if the SDK has joined a channel.

Returns:

  • boolean - Channel join status

Example Usage:


Chat Management

async joinChat(metadata: Metadata): Promise<void>

Initializes the avatar chat session with the specified parameters.

Parameters:

  • metadata (Metadata) - Avatar configuration parameters

Example Usage:

setParameters(metadata: Metadata): void

Sets avatar parameters. Refer to the avatar parameter documentation for details.

Parameters:

  • metadata (Metadata) - Avatar configuration parameters

Example Usage:

async leaveChat(): Promise<void>

Leaves the chat session but maintains the channel connection.

Example Usage:

async sendMessage(content: string): Promise<void>

Sends a text message to the avatar.

Parameters:

  • content (string) - The message content to send

Example Usage:

async interrupt(): Promise<void>

Interrupts the current avatar response.

Example Usage:

getMessages(): Message[]

Returns all chat messages in the current session.

Returns:

  • Message[] - Array of chat messages

Example Usage:

getMessage(messageId: string): Message | undefined

Returns a specific message by its ID.

Parameters:

  • messageId (string) - The ID of the message to retrieve

Returns:

  • Message | undefined - The message object or undefined if not found

Example Usage:


Audio Management

async toggleMic(): Promise<void>

Toggles the microphone on or off.

Example Usage:

isMicEnabled(): boolean

Checks if the microphone is currently enabled.

Returns:

  • boolean - Microphone status

Example Usage:


Client Access

getClient(): RTCClient

Returns the underlying Agora RTC client instance for advanced operations.

Returns:

  • RTCClient - The Agora RTC client

Example Usage:


Event Handling

on(events: SDKEvents): void

Registers event handlers for various SDK events.

Parameters:

  • events (SDKEvents) - Object containing event handler functions

Example Usage:


Type Definitions

AgoraCredentials

Interface for Agora connection credentials.

Metadata

Interface for avatar configuration parameters.

Message

Interface for chat messages.

NetworkStats

Interface for network statistics.

SDKEvents

Interface defining all available event handlers.

Complete Example

Here’s a comprehensive example demonstrating how to use the SDK:

Error Handling

The SDK provides comprehensive error handling through the onException event:

Requirements

  • Node.js 14 or higher (for development)
  • Modern browser with WebRTC support
  • Valid Agora credentials
  • Akool API access

Browser Support

  • Chrome 56+
  • Firefox 44+
  • Safari 11+
  • Edge 79+
  • Opera 43+

Additional Resources