A production-ready React application showcasing Akool's Streaming Avatar service with multi-provider support, real-time voice interaction, and comprehensive network monitoring. Built with clean architecture principles and designed for scalability.
This application demonstrates enterprise-grade architecture with:
- Multi-Provider Support: Seamless switching between Agora, LiveKit, and TRTC
- Clean Architecture: Layered design with clear separation of concerns
- Design Patterns: Strategy, Factory, Provider, Observer, and Controller patterns
- Type Safety: Comprehensive TypeScript implementation with strict typing
- Event-Driven: Reactive updates through EventBus system
- Resource Management: Automatic cleanup and memory management
- Testing: Comprehensive test coverage with modern testing frameworks
- Strategy Pattern: Media operations abstracted across providers
- Factory Pattern: Centralized provider creation and management
- Provider Pattern: Unified interface for different streaming SDKs
- Observer Pattern: Event-driven communication throughout the system
- Controller Pattern: Complex logic extracted into focused controllers
π View Detailed Architecture Documentation β
- Architecture Overview
- Features
- Technology Stack
- Prerequisites
- Quick Start
- Configuration
- API Setup
- Development
- Deployment
- Troubleshooting
- License
- π Real-time Avatar Streaming - Live avatar rendering with voice synchronization
- π€ Voice Interaction - Two-way voice communication with the avatar
- π¬ Chat Interface - Text-based messaging with the avatar
- π Network Quality Monitoring - Real-time statistics and performance metrics
- π Multi-language Support - Internationalization for global users
- π¨ Customizable Avatars - Multiple avatar and voice options
- π± Responsive Design - Works seamlessly across devices
- β‘ Low Latency - Optimized for real-time interactions
- π Multi-Provider Support - Seamless switching between Agora, LiveKit, and TRTC
- ποΈ AI Denoiser - Cross-provider noise reduction support
- π Performance Monitoring - Real-time quality metrics and analytics
- π‘οΈ Error Recovery - Robust error handling and automatic reconnection
- π§ Smart Resource Management - Automatic cleanup and memory optimization
- π§ Provider-Agnostic Controls - Unified interface across different streaming SDKs
- π΅ Enhanced Voice Selection - Advanced voice preview and selection interface
- π JSON Configuration Editor - Visual configuration management
- π Real-time Notifications - Toast notifications for system events
- π¨ Draggable UI Components - Resizable and repositionable interface elements
- π§ͺ Comprehensive Testing - 90%+ code coverage with Vitest
- π Advanced Analytics - Detailed performance and usage metrics
- React 18 - Modern React with concurrent features
- TypeScript - Strict typing with comprehensive type definitions
- Vite - Fast build tool with hot module replacement
- CSS3 - Modern styling with responsive design patterns
- Agora RTC SDK - Real-time communication (primary provider)
- LiveKit Client - WebRTC implementation (secondary provider)
- TRTC SDK v5 - Tencent real-time communication (tertiary provider)
- Zustand - Lightweight state management for configuration
- React Context API - Provider state and event handling
- EventBus - Custom event-driven communication system
- Resource Manager - Automatic cleanup and memory management
- pnpm - Fast, disk space efficient package manager
- ESLint - Code linting with TypeScript support
- Prettier - Code formatting
- Vitest - Testing framework with coverage
- Husky - Git hooks for code quality
- Node.js: v22.11.0 or higher
- pnpm: Latest version (recommended package manager)
- Akool API Token: Valid authentication token for the Streaming Avatar service
- Modern Browser: Chrome, Firefox, Safari, or Edge with WebRTC support
git clone https://github.com/AKOOL-Official/akool-streaming-avatar-react-demo
cd akool-streaming-avatar-react-demopnpm installCreate a .env file in the root directory:
cp .env.development .env.development.localEdit .env.development.local with your configuration:
VITE_OPENAPI_HOST=https://openapi.akool.com
VITE_OPENAPI_TOKEN=your_access_token_here
VITE_SERVER_BASE=/streaming/avatar
# Optional: Enable debug features (noise reduction and audio dump buttons)
# VITE_DEBUG_FEATURES=trueNote: Replace your_access_token_here with the token obtained from the /api/open/v3/getToken endpoint.
pnpm devThe application will be available at http://localhost:5173/streaming/avatar
| Variable | Description | Default | Required |
|---|---|---|---|
VITE_OPENAPI_HOST |
Akool API base URL | https://openapi.akool.com |
Yes |
VITE_OPENAPI_TOKEN |
Your Akool API authentication token | - | Yes |
VITE_SERVER_BASE |
Server base URL | /streaming/avatar |
Yes |
VITE_DEBUG_FEATURES |
Enable debug buttons (noise reduction & audio dump) | undefined (disabled) |
No |
The demo includes configurable options for:
- Provider Selection: Choose between Agora, LiveKit, or TRTC
- Avatar Selection: Choose from available avatar models
- Voice Settings: Adjust voice parameters and language
- Network Configuration: Customize RTC settings
- UI Preferences: Theme and layout options
The application supports three streaming providers with seamless switching:
- Agora RTC (Default) - Full audio/video support, AI denoiser
- LiveKit - WebRTC-based, scalable architecture
- TRTC - Enterprise-grade, global CDN
π View Multi-Provider Configuration β
- Sign Up: Create an account at Akool
- Login: Access your account dashboard
- Get Credentials:
- Click the picture icon in the upper right corner
- Select "API Credentials" function
- Set up your key pair (
clientId,clientSecret) and save it
- Generate Token: Use your credentials to obtain an access token via API call
- Use Token: Include the token in your API requests as a Bearer token
To get your access token, make a POST request to:
POST https://openapi.akool.com/api/open/v3/getTokenRequest Body:
{
"clientId": "your_client_id_here",
"clientSecret": "your_client_secret_here"
}Response:
{
"code": 1000,
"token": "your_access_token_here"
}Note: The generated token is valid for more than 1 year.
Include your API token in the HTTP header for all API requests:
Authorization: Bearer your_access_token_here- π Never commit API tokens to version control
- π Rotate tokens regularly for enhanced security (tokens are valid for >1 year)
- π Use environment variables for all sensitive data
- π‘οΈ Implement proper CORS settings in production
- π Keep clientId and clientSecret secure - these are used to generate your access token
β οΈ Production requests must be routed through your backend server - never expose tokens in client-side code
src/
βββ components/ # React UI components
β βββ shared/ # Reusable UI components
β βββ VideoDisplay/ # Video rendering components
β βββ ChatInterface/ # Chat functionality
β βββ EnhancedVoiceSelector/ # Advanced voice selection
β βββ ... # Other specialized components
βββ contexts/ # React context providers
βββ hooks/ # Custom React hooks
βββ providers/ # Multi-provider streaming system
β βββ agora/ # Agora RTC implementation
β βββ livekit/ # LiveKit implementation
β βββ trtc/ # TRTC implementation
β βββ common/ # Shared provider components
βββ core/ # Core system utilities
βββ stores/ # State management (Zustand)
βββ types/ # TypeScript type definitions
βββ errors/ # Error handling
βββ __tests__/ # Comprehensive test suite
π View Detailed Project Structure β
The application features a modern, interactive UI with advanced components:
- Enhanced Voice Selector: Advanced voice preview and selection with real-time audio feedback
- JSON Configuration Editor: Visual configuration management with Monaco Editor
- Draggable Overlays: Resizable and repositionable interface elements
- Real-time Notifications: Toast notification system for user feedback
- Network Quality Display: Live performance metrics and connection status
- Chat Interface: Modern chat UI with message history and controls
- Video Display: Optimized video rendering with overlay controls
# Development
pnpm dev # Start development server
pnpm preview # Preview production build
# Building
pnpm build # Build for development
pnpm build:prod # Build for production
pnpm build:ci # Build for CI environment
# Code Quality
pnpm lint # Run ESLint
pnpm format # Run prettier
pnpm typecheck # Run TypeScript type checking
# Testing
pnpm test # Run tests once
pnpm test:ui # Run tests with UI
pnpm test:coverage # Run tests with coverage
pnpm test:watch # Run tests in watch mode
# Git Hooks
pnpm prepare # Setup Husky git hooks- Fork the repository
- Create a feature branch:
git checkout -b feat/amazing-feature - Make your changes and test thoroughly
- Run quality checks:
pnpm typecheck # Type checking pnpm lint # ESLint checks pnpm format # Code formatting pnpm test # Run tests
- Commit with descriptive messages:
git commit -m 'Add amazing feature' - Push to your branch:
git push origin feat/amazing-feature - Create a Pull Request
- TypeScript: Strict mode enabled, never use
any(useunknowninstead) - ESLint: Configured for React + TypeScript with strict rules
- Prettier: Consistent code formatting across the project
- Testing: Maintain 90%+ coverage for core modules, 75%+ for components
- Error Handling: Comprehensive try-catch blocks and error boundaries
- No TODOs: Never leave TODO comments or mock data in production code
This project uses Vitest as the primary testing framework with comprehensive coverage and modern testing utilities:
- Vitest - Fast unit testing with Vite integration
- React Testing Library - Component testing utilities
- Jest DOM - Custom matchers for DOM testing
- User Event - User interaction simulation
- Coverage Reports - Comprehensive code coverage tracking
src/__tests__/
βββ core/ # Core system tests
βββ fixtures/ # Test data and fixtures
βββ mocks/ # Mock implementations
β βββ streamingSdks/ # Provider SDK mocks
βββ setup/ # Test configuration
# Run all tests
pnpm test
# Run tests with UI
pnpm test:ui
# Run tests with coverage
pnpm test:coverage
# Run tests in watch mode
pnpm test:watchThe project maintains high code coverage with different thresholds:
- Core Modules (hooks, providers, core): 90% coverage
- UI Components: 75% coverage
- Global Threshold: 80% coverage
- Component Tests: UI component behavior and rendering
- Hook Tests: Custom React hooks functionality
- Provider Tests: Streaming provider implementations
- Core Tests: EventBus, Logger, ResourceManager
- Provider Switching: Multi-provider functionality
- Error Scenarios: Network failure and recovery
- Performance Tests: Load and stress testing
- Provider SDKs: Complete mock implementations for Agora, LiveKit, and TRTC
- Event System: Mock EventBus for isolated testing
- API Services: Mocked API responses and error scenarios
The application provides comprehensive real-time monitoring with provider-agnostic metrics:
- Video Statistics: Frame rate, resolution, bitrate, codec information
- Audio Statistics: Sample rate, bitrate, packet loss, volume levels
- Network Performance: Latency, jitter, packet loss rates, bandwidth
- Connection Quality: Overall network health score (0-100)
- AI Denoiser: Cross-provider noise reduction support
- Error Recovery: Automatic reconnection with exponential backoff
π View Performance Optimizations β
| Browser | Version | Status |
|---|---|---|
| Chrome | 90+ | β Full Support |
| Firefox | 88+ | β Full Support |
| Safari | 14+ | β Full Support |
| Edge | 90+ | β Full Support |
pnpm build:prod- Build the application:
pnpm build:prod - Upload the
distfolder to your hosting provider - Configure environment variables in your hosting platform
- Set up custom domain if needed
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install -g pnpm
RUN pnpm install
COPY . .
RUN pnpm build:prod
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Problem: "Invalid API token" or "Authentication failed"
Solution:
- Verify your API token is correct
- Check if the token has expired
- Ensure the token has proper permissions
Problem: Avatar not loading or voice not working
Solution:
- Check browser WebRTC support
- Verify microphone permissions
- Check firewall/network restrictions
- Try refreshing the page
Problem: Poor video/audio quality
Solution:
- Check internet connection speed
- Close other bandwidth-intensive applications
- Try different network (mobile hotspot)
- Check browser console for errors
Problem: pnpm dev fails to start
Solution:
# Clear cache and reinstall
rm -rf node_modules pnpm-lock.yaml
pnpm install
# Check Node.js version
node --version # Should be >= 22.11.0- π Documentation: Akool API Docs
- π Authentication Guide: Akool Authentication Usage
- π¬ Community: GitHub Discussions
- π Issues: GitHub Issues
- π§ Support: [email protected]
- Fork and clone the repository
- Install dependencies:
pnpm install - Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Use TypeScript for all new code
- Follow ESLint configuration
- Write meaningful commit messages
- Add tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Akool for providing the Streaming Avatar API
- Agora for real-time communication technology
- React community for the amazing framework
- All contributors who help improve this demo
Made with β€οΈ by the Akool Team