Zenc Server is the core media server for the Zenc livestreaming ecosystem. Built in Go for high performance and concurrency, it handles real-time media routing using WebRTC SFU (Selective Forwarding Unit) architecture.
- WebRTC SFU Implementation - Selective forwarding for efficient media routing
- Multi-Host Support - Distributed architecture with automatic failover
- Redis Integration - State management and pub/sub for cross-server communication
- Stream Zones - Geographic/logical grouping for better performance
- REST & WebSocket APIs - Flexible integration options
- Real-time Metrics - Prometheus-compatible metrics endpoint
- Docker Ready - Easy deployment with Docker and Docker Compose
- Go 1.22 or higher
- Redis 7.0 or higher
- Docker & Docker Compose (optional)
# Clone the repository
git clone https://github.com/aminofox/zenc-server.git
cd zenc-server
# Start the server with Redis
docker-compose up -d
# View logs
docker-compose logs -f zenc-server# Install dependencies
make deps
# Build the server
make build
# Run the server
./zenc-servergo run ./cmd/serverConfiguration is managed via config.yaml. Here's a basic example:
server:
host: 0.0.0.0
port: 8080
name: zenc-server-1
webrtc:
ice_servers:
- urls:
- stun:stun.l.google.com:19302
port_range:
min: 10000
max: 20000
redis:
mode: single
addresses:
- localhost:6379
password: ""
db: 0
zones:
- id: default
region: local
primary: true
logging:
level: info
format: json
metrics:
enabled: true
port: 9090
path: /metrics| Option | Description | Default |
|---|---|---|
server.port |
HTTP server port | 8080 |
webrtc.port_range |
UDP port range for WebRTC | 10000-20000 |
redis.mode |
Redis mode (single, cluster, sentinel) | single |
logging.level |
Log level (debug, info, warn, error) | info |
metrics.enabled |
Enable Prometheus metrics | true |
GET /healthResponse:
{
"status": "healthy",
"server": "zenc-server-1",
"time": 1706140800
}POST /api/v1/rooms
Content-Type: application/json
{
"name": "My Livestream",
"max_users": 100,
"zone": "default"
}GET /api/v1/rooms/:idGET /api/v1/roomsDELETE /api/v1/rooms/:idPOST /api/v1/rooms/:id/join
Content-Type: application/json
{
"user_id": "user123",
"role": "publisher"
}POST /api/v1/rooms/:id/leave
Content-Type: application/json
{
"participant_id": "participant-uuid"
}GET /api/v1/rooms/:id/participantsPOST /api/v1/tracks/publish
Content-Type: application/json
{
"participant_id": "participant-uuid",
"kind": "video",
"source": "camera",
"sdp_offer": "v=0..."
}POST /api/v1/tracks/subscribe
Content-Type: application/json
{
"participant_id": "participant-uuid",
"track_id": "track-uuid"
}POST /api/v1/tracks/hold
Content-Type: application/json
{
"track_id": "track-uuid"
}POST /api/v1/tracks/resume
Content-Type: application/json
{
"track_id": "track-uuid"
}Connect to ws://localhost:8080/ws for real-time signaling.
{
"type": "message_type",
"payload": {
"key": "value"
}
}join- Join a roomleave- Leave a roomoffer- WebRTC offeranswer- WebRTC answerice_candidate- ICE candidate
Prometheus metrics are available at http://localhost:9090/metrics (if enabled).
zenc-server/
βββ cmd/
β βββ server/ # Main application entry point
βββ internal/
β βββ api/
β β βββ httpapi/ # REST API handlers
β β βββ websocket/ # WebSocket handlers
β βββ room/ # Room management
β βββ participant/ # Participant logic
β βββ media/ # Media routing (SFU core)
β βββ store/ # Redis storage layer
βββ pkg/
β βββ config/ # Configuration management
β βββ logger/ # Logging utilities
β βββ protocol/ # Protocol definitions
βββ config.yaml # Configuration file
βββ Dockerfile # Docker image
βββ docker-compose.yml # Docker Compose setup
make testmake test-coveragemake fmtmake lintmake docker-build| Command | Description |
|---|---|
make build |
Build the server binary |
make run |
Run the server locally |
make test |
Run tests |
make clean |
Clean build artifacts |
make docker-build |
Build Docker image |
make docker-run |
Run with Docker Compose |
make docker-stop |
Stop Docker Compose |
# Build the image
docker build -t aminofox/zenc-server:latest .
# Run the container
docker run -d \
--name zenc-server \
-p 8080:8080 \
-p 9090:9090 \
-p 10000-20000:10000-20000/udp \
-v $(pwd)/config.yaml:/root/config.yaml:ro \
aminofox/zenc-server:latestYou can override configuration via environment variables:
export SERVER_PORT=8080
export REDIS_ADDR=redis:6379
export LOG_LEVEL=infoContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Basic room management
- REST API
- WebSocket signaling
- Redis integration
- Full WebRTC implementation with Pion
- Multi-server support
- Cross-server communication
- Load balancing
- Automatic failover
- Stream composition engine
- Quality adaptation
- Recording support
- RTMP ingestion/egress
-
Check if Redis is running:
redis-cli ping # Should return: PONG -
Verify configuration file exists:
ls -la config.yaml
-
Check logs for errors:
docker-compose logs zenc-server
- Ensure UDP ports 10000-20000 are open
- Check firewall settings
- Verify STUN server is accessible
This project is licensed under the MIT License - see the LICENSE file for details.
aminofox
- GitHub: @aminofox
- Repository: zenc-server
- zenc-sdk - Client SDK
- zenc-protocol - Protocol definitions
- zenc-admin - Admin dashboard
If you find this project helpful, please give it a star! β
For questions or support, please open an issue on GitHub.
Built with β€οΈ by aminofox
Part of the Zenc Livestreaming Ecosystem