# LiveKit

> Real-time video, audio and data SDK.

- Category: Message Queues & Brokers
- Difficulty: intermediate
- Components: livekit
- Tags: livekit, webrtc, video, audio
- Source: https://docker.recipes/messaging/livekit

## Overview

LiveKit is an open-source, production-grade platform that provides real-time video, audio, and data communication capabilities through WebRTC technology. Originally developed to democratize access to video conferencing infrastructure, LiveKit serves as a compelling alternative to proprietary solutions like Twilio Video, Zoom SDK, or Agora, offering developers complete control over their real-time communication stack without vendor lock-in or per-minute pricing models.

This Docker deployment creates a self-hosted LiveKit server that handles WebRTC signaling, media routing, and room management through a single containerized service. The LiveKit server acts as a Selective Forwarding Unit (SFU) that efficiently distributes media streams between participants while providing APIs for room creation, participant management, and real-time data channels, making it possible to build sophisticated video applications with minimal infrastructure overhead.

This configuration is ideal for startups building video-first applications, enterprises requiring on-premises communication solutions, or developers creating custom conferencing tools who need predictable costs and full data sovereignty. The setup provides production-ready video infrastructure that can scale from small team meetings to large-scale broadcast scenarios with thousands of concurrent participants.

## Features

- WebRTC-based Selective Forwarding Unit (SFU) for efficient multi-participant video distribution
- Real-time room management with dynamic participant joining and track subscription controls
- Adaptive bitrate streaming with automatic quality adjustment based on network conditions
- Server-side recording and egress capabilities for archiving sessions or streaming to external platforms
- Built-in data channels for real-time messaging and custom signaling alongside media streams
- Multi-track audio and video support with screen sharing and device switching capabilities
- JWT-based authentication with granular permissions for room access and publishing rights
- Load balancing support for horizontal scaling across multiple server instances

## Use cases

- Building custom video conferencing applications for remote teams and distributed organizations
- Creating online education platforms with interactive classrooms and student engagement tools
- Developing telehealth solutions requiring HIPAA-compliant video consultations
- Implementing live streaming platforms with audience interaction and real-time chat
- Building collaborative design tools with screen sharing and real-time communication
- Creating gaming platforms that require voice chat and real-time coordination features
- Developing customer support systems with video calling and screen sharing capabilities

## Prerequisites

- Minimum 2GB RAM and 2 CPU cores for handling moderate concurrent sessions
- Network environment with properly configured firewall allowing UDP traffic on ports 7881-7882
- Valid SSL certificate and domain name for production WebRTC connectivity
- Basic understanding of WebRTC concepts and JWT token generation for authentication
- Client-side SDK integration knowledge for your target platforms (React, Swift, Android, etc.)
- Understanding of media server scaling concepts for high-availability deployments

## docker-compose.yml

```yaml
services:
  livekit:
    image: livekit/livekit-server:latest
    container_name: livekit
    restart: unless-stopped
    command: --config /etc/livekit.yaml
    environment:
      LIVEKIT_KEYS: "${API_KEY}: ${API_SECRET}"
    volumes:
      - ./livekit.yaml:/etc/livekit.yaml
    ports:
      - "7880:7880"
      - "7881:7881/udp"
      - "7882:7882/udp"
```

## .env

```bash
API_KEY=devkey
API_SECRET=secret
```

## Usage notes

- Docs: https://docs.livekit.io/
- API/WebSocket on port 7880, UDP media on 7881-7882
- Create livekit.yaml: port: 7880, keys: {api-key: secret}
- SDKs for React, JS, Swift, Android, Flutter, Unity
- Features: rooms, tracks, data channels, recording, egress
- Open-source Zoom/Twilio alternative for video conferencing

## Troubleshooting

- WebRTC connection failures in production: Ensure proper TURN server configuration and SSL certificates are properly configured for secure contexts
- Participants cannot see or hear each other: Verify UDP ports 7881-7882 are open and accessible, check firewall rules blocking media traffic
- High CPU usage during video calls: Implement proper video resolution limits and enable hardware acceleration if available on the host system
- JWT authentication errors when joining rooms: Verify API_KEY and API_SECRET environment variables match your token generation code
- Audio echo or feedback issues: Configure proper echo cancellation settings in client SDKs and ensure participants use headphones
- Container fails to start with config errors: Ensure livekit.yaml file exists with proper port and keys configuration matching environment variables

