Skip to content

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:

AspectP2PSFU
LatencyLowerSlightly higher
Scalability2-8 participants50+ participants
BandwidthN-1 uploads1 upload
Server loadMinimalModerate

Preparing Your Repository

Repository Structure

mirotalk-sfu-deploy/
├── Dockerfile
├── README.md
└── .dockerignore

Creating the Dockerfile

Create a Dockerfile:

FROM mirotalk/sfu:latest
# Server configuration
ENV HTTPS=false
ENV HOST=0.0.0.0
ENV PORT=3010
# API configuration
ENV API_KEY_SECRET=${API_KEY_SECRET}
# mediasoup configuration
ENV MEDIASOUP_LISTEN_IP=0.0.0.0
ENV MEDIASOUP_ANNOUNCED_IP=${MEDIASOUP_ANNOUNCED_IP}
ENV MEDIASOUP_MIN_PORT=40000
ENV MEDIASOUP_MAX_PORT=40100
# TURN configuration
ENV TURN_ENABLED=${TURN_ENABLED:-true}
ENV TURN_URLS=${TURN_URLS}
ENV TURN_USERNAME=${TURN_USERNAME}
ENV TURN_CREDENTIAL=${TURN_CREDENTIAL}
# Feature flags
ENV LOBBY_ENABLED=${LOBBY_ENABLED:-false}
ENV HOST_PROTECTED=${HOST_PROTECTED:-false}
# Expose ports
EXPOSE 3010
EXPOSE 40000-40100/udp
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:3010/ || exit 1

Environment Variables Reference

VariableRequiredDefaultDescription
API_KEY_SECRETRecommended-API authentication secret
MEDIASOUP_ANNOUNCED_IPYes-Public IP for WebRTC media
MEDIASOUP_MIN_PORTNo40000Start of RTP port range
MEDIASOUP_MAX_PORTNo40100End of RTP port range
TURN_ENABLEDNotrueEnable TURN support
TURN_URLSRecommended-TURN server URLs
TURN_USERNAMERecommended-TURN username
TURN_CREDENTIALRecommended-TURN password
LOBBY_ENABLEDNofalseEnable waiting room
HOST_PROTECTEDNofalseRequire host authentication

Deploying MiroTalk SFU on Klutch.sh

    Generate API Key Secret

    Create a secure API key:

    Terminal window
    openssl rand -hex 32

    Push Your Repository to GitHub

    Terminal window
    git init
    git add Dockerfile .dockerignore README.md
    git commit -m "Initial MiroTalk SFU deployment"
    git remote add origin https://github.com/yourusername/mirotalk-sfu-deploy.git
    git push -u origin main

    Create 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:

    • Select HTTP as the traffic type
    • Set the internal port to 3010

    Set Environment Variables

    Configure your environment:

    VariableValue
    API_KEY_SECRETYour generated API key
    MEDIASOUP_ANNOUNCED_IPYour app’s public IP
    TURN_ENABLEDtrue
    TURN_URLSYour TURN server URL
    TURN_USERNAMEYour TURN username
    TURN_CREDENTIALYour TURN password

    Allocate Resources

    For SFU workloads, allocate sufficient resources:

    • CPU: 2+ cores recommended
    • Memory: 2+ GB recommended

    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

  1. Navigate to your MiroTalk SFU URL
  2. Enter a room name or use the random generator
  3. Click Join Room
  4. 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:

  1. Start a meeting as host
  2. Click the Broadcast button
  3. Enter your RTMP URL (e.g., YouTube Live, Twitch)
  4. 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 SizeRecommended CPURecommended RAM
Up to 101 core1 GB
10-302 cores2 GB
30-504 cores4 GB
50+4+ cores4+ GB

Simulcast Settings

Enable simulcast for adaptive quality:

MEDIASOUP_SIMULCAST=true

This sends multiple quality layers, allowing the server to forward appropriate quality to each participant.

Troubleshooting

Media Connection Failures

  • Verify MEDIASOUP_ANNOUNCED_IP is 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

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.