Deploying MiroTalk SFU
Introduction
MiroTalk SFU (Selective Forwarding Unit) is a powerful, open-source WebRTC video conferencing platform designed for scalable group meetings. Unlike peer-to-peer solutions where each participant connects to everyone else, SFU architecture routes all media through a central server that intelligently forwards streams to participants, enabling meetings with dozens or even hundreds of attendees.
Built on Node.js with the mediasoup WebRTC SFU library, MiroTalk SFU delivers broadcast-quality video conferencing with features rivaling commercial platforms. The architecture provides optimal bandwidth usage, consistent quality regardless of participant count, and advanced features like simulcast and selective subscription.
Key highlights of MiroTalk SFU:
- SFU Architecture: Scalable to large meetings without exponential bandwidth growth
- Simulcast Support: Multiple video quality layers for adaptive streaming
- No Downloads Required: Works entirely in modern web browsers
- HD Video: Support for up to 4K video resolution
- Screen Sharing: Share screen, windows, or tabs with audio
- Recording: Server-side and client-side recording options
- Whiteboard: Real-time collaborative drawing canvas
- File Transfer: Direct file sharing between participants
- Breakout Rooms: Split into smaller discussion groups
- Polls and Reactions: Interactive engagement features
- REST API: Full programmatic control and integration
- RTMP Streaming: Broadcast to YouTube, Twitch, and other platforms
- Lobby/Waiting Room: Control who enters your meetings
- Admin Controls: Mute all, remove participants, lock rooms
This guide covers deploying MiroTalk SFU on Klutch.sh, configuring for optimal performance, and integrating with your applications.
Why Deploy MiroTalk SFU on Klutch.sh
Deploying MiroTalk SFU on Klutch.sh provides significant advantages:
Simplified Deployment: Klutch.sh automatically builds and deploys MiroTalk SFU from your Dockerfile. Push to GitHub, and your conferencing platform updates automatically.
HTTPS by Default: WebRTC requires secure contexts. Klutch.sh provides automatic SSL certificates for browser compatibility.
Scalable Resources: Allocate CPU and memory based on expected meeting sizes. SFU servers benefit from additional resources for media processing.
GitHub Integration: Connect your configuration repository for automatic deployments on code changes.
Environment Variable Management: Securely configure API keys, TURN servers, and other sensitive settings.
Custom Domains: Use a professional domain for branded video conferencing.
Always-On Availability: Your conferencing platform stays accessible around the clock.
Prerequisites
Before deploying MiroTalk SFU on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your configuration
- Basic familiarity with Docker and containerization
- Understanding of WebRTC and media server concepts
- (Recommended) TURN server credentials
- (Optional) A custom domain
Understanding SFU Architecture
MiroTalk SFU uses selective forwarding, which differs from both P2P and MCU approaches:
Selective Forwarding Unit (SFU):
- Each participant sends media once to the server
- Server forwards streams to other participants without transcoding
- Scales well to large meetings
- Lower server CPU than MCU (no transcoding)
- Better quality than P2P for larger groups
Simulcast:
- Participants send multiple quality layers (high, medium, low)
- Server selects appropriate layer for each recipient
- Adaptive quality based on available bandwidth
Comparison with P2P:
| Aspect | P2P | SFU |
|---|---|---|
| Latency | Lower | Slightly higher |
| Scalability | 2-8 participants | 50+ participants |
| Bandwidth | N-1 uploads | 1 upload |
| Server load | Minimal | Moderate |
Preparing Your Repository
Repository Structure
mirotalk-sfu-deploy/├── Dockerfile├── README.md└── .dockerignoreCreating the Dockerfile
Create a Dockerfile:
FROM mirotalk/sfu:latest
# Server configurationENV HTTPS=falseENV HOST=0.0.0.0ENV PORT=3010
# API configurationENV API_KEY_SECRET=${API_KEY_SECRET}
# mediasoup configurationENV MEDIASOUP_LISTEN_IP=0.0.0.0ENV MEDIASOUP_ANNOUNCED_IP=${MEDIASOUP_ANNOUNCED_IP}ENV MEDIASOUP_MIN_PORT=40000ENV MEDIASOUP_MAX_PORT=40100
# TURN configurationENV TURN_ENABLED=${TURN_ENABLED:-true}ENV TURN_URLS=${TURN_URLS}ENV TURN_USERNAME=${TURN_USERNAME}ENV TURN_CREDENTIAL=${TURN_CREDENTIAL}
# Feature flagsENV LOBBY_ENABLED=${LOBBY_ENABLED:-false}ENV HOST_PROTECTED=${HOST_PROTECTED:-false}
# Expose portsEXPOSE 3010EXPOSE 40000-40100/udp
# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3010/ || exit 1Environment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
API_KEY_SECRET | Recommended | - | API authentication secret |
MEDIASOUP_ANNOUNCED_IP | Yes | - | Public IP for WebRTC media |
MEDIASOUP_MIN_PORT | No | 40000 | Start of RTP port range |
MEDIASOUP_MAX_PORT | No | 40100 | End of RTP port range |
TURN_ENABLED | No | true | Enable TURN support |
TURN_URLS | Recommended | - | TURN server URLs |
TURN_USERNAME | Recommended | - | TURN username |
TURN_CREDENTIAL | Recommended | - | TURN password |
LOBBY_ENABLED | No | false | Enable waiting room |
HOST_PROTECTED | No | false | Require host authentication |
Deploying MiroTalk SFU on Klutch.sh
- Select HTTP as the traffic type
- Set the internal port to 3010
- CPU: 2+ cores recommended
- Memory: 2+ GB recommended
Generate API Key Secret
Create a secure API key:
openssl rand -hex 32Push Your Repository to GitHub
git initgit add Dockerfile .dockerignore README.mdgit commit -m "Initial MiroTalk SFU deployment"git remote add origin https://github.com/yourusername/mirotalk-sfu-deploy.gitgit push -u origin mainCreate a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a project named “mirotalk-sfu” or “conference”.
Create a New App
Create a new app and connect your GitHub repository.
Configure HTTP Traffic
In deployment settings:
Set Environment Variables
Configure your environment:
| Variable | Value |
|---|---|
API_KEY_SECRET | Your generated API key |
MEDIASOUP_ANNOUNCED_IP | Your app’s public IP |
TURN_ENABLED | true |
TURN_URLS | Your TURN server URL |
TURN_USERNAME | Your TURN username |
TURN_CREDENTIAL | Your TURN password |
Allocate Resources
For SFU workloads, allocate sufficient resources:
Resource needs scale with concurrent meetings and participants.
Deploy Your Application
Click Deploy to build and launch.
Access MiroTalk SFU
Access your platform at https://your-app-name.klutch.sh.
Using MiroTalk SFU
Creating a Meeting
- Navigate to your MiroTalk SFU URL
- Enter a room name or use the random generator
- Click Join Room
- Share the URL with participants
Host Controls
As a meeting host, you have access to:
- Mute All: Silence all participant microphones
- Lock Room: Prevent new participants from joining
- Remove Participant: Eject users from the meeting
- Lobby Management: Approve or reject waiting participants
- Recording Control: Start/stop server-side recording
- Broadcast: Start RTMP streaming to external platforms
Participant Features
All participants can:
- Toggle audio/video
- Share screen with audio
- Use text chat
- Access whiteboard
- Share files
- Raise hand
- Send reactions
API Integration
Creating Meetings via API
const response = await fetch('https://your-sfu.klutch.sh/api/v1/meeting', { method: 'POST', headers: { 'Authorization': 'your-api-key-secret', 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Company All-Hands', lobby: true, hostProtected: true })});
const { meeting } = await response.json();console.log(meeting.roomUrl);Joining with Tokens
Generate secure join tokens for participants:
const token = jwt.sign( { room: 'meeting-id', name: 'John Doe', role: 'presenter' }, API_KEY_SECRET, { expiresIn: '1h' });
const joinUrl = `https://your-sfu.klutch.sh/join/${token}`;RTMP Broadcasting
Stream your meetings to external platforms:
- Start a meeting as host
- Click the Broadcast button
- Enter your RTMP URL (e.g., YouTube Live, Twitch)
- Click Start Broadcasting
Example RTMP URLs:
- YouTube:
rtmp://a.rtmp.youtube.com/live2/your-stream-key - Twitch:
rtmp://live.twitch.tv/app/your-stream-key
Performance Optimization
Resource Allocation
| Meeting Size | Recommended CPU | Recommended RAM |
|---|---|---|
| Up to 10 | 1 core | 1 GB |
| 10-30 | 2 cores | 2 GB |
| 30-50 | 4 cores | 4 GB |
| 50+ | 4+ cores | 4+ GB |
Simulcast Settings
Enable simulcast for adaptive quality:
MEDIASOUP_SIMULCAST=trueThis sends multiple quality layers, allowing the server to forward appropriate quality to each participant.
Troubleshooting
Media Connection Failures
- Verify
MEDIASOUP_ANNOUNCED_IPis correct - Configure TURN servers for NAT traversal
- Check UDP port range is accessible
High Latency
- Ensure adequate CPU resources
- Check network bandwidth
- Consider geographic proximity to users
Recording Issues
- Verify sufficient disk space
- Check recording directory permissions
- Review logs for codec compatibility issues
Scalability Limits
- Monitor CPU usage during large meetings
- Consider load balancing for high demand
- Use simulcast to reduce bandwidth
Additional Resources
- MiroTalk SFU GitHub Repository
- MiroTalk SFU Demo
- mediasoup Documentation
- MiroTalk P2P for Small Meetings
- Klutch.sh Deployments
Conclusion
MiroTalk SFU on Klutch.sh delivers enterprise-grade video conferencing with the scalability to support large meetings. The selective forwarding architecture optimizes bandwidth while maintaining quality, and features like RTMP broadcasting, lobby management, and comprehensive host controls make it suitable for professional deployments. Whether hosting company all-hands, webinars, or virtual events, MiroTalk SFU provides the tools needed for effective large-scale video collaboration.