From basic peer-to-peer calls to advanced multi-party Mesh architecture.
A learning-oriented, security-first WebRTC implementation in Go.
📋 Product Spec · 🏗️ RFCs · 📡 API Spec · 📝 Changelog · 🗺️ Roadmap
- ✨ Features
- 🚀 Quick Start
- 🏗️ Architecture
- 📚 Documentation
- ⚙️ Configuration
- 🚀 Deployment
- 🤝 Contributing
- 📄 License
|
|
# Clone and run
git clone https://github.com/LessUp/webrtc.git
cd webrtc
go mod tidy
go run ./cmd/server
# Open http://localhost:8080docker build -t webrtc .
docker run --rm -p 8080:8080 webrtcexport DOMAIN=your-domain.com
docker compose up -dVisit https://your-domain.com with automatic HTTPS via Caddy.
- Open two browser windows to
http://localhost:8080 - Enter the same room name and click Join
- Select a peer from the member list and click Call
- Allow camera/microphone permissions ✅
- Enjoy video calls, screen sharing, and text chat!
💡 Need help with NAT traversal?
For connections across different networks, configure a TURN server:
export RTC_CONFIG_JSON='{
"iceServers": [
{ "urls": ["stun:stun.l.google.com:19302"] },
{ "urls": ["turn:your-turn.com:3478"], "username": "user", "credential": "pass" }
]
}'See Deployment Guide for TURN setup.
This project follows Spec-Driven Development (SDD) — all implementation is driven by specifications.
┌────────────────────────────────────────────────────────────┐
│ Browser A │
│ ┌────────┐ ┌──────────┐ ┌────────────────────┐ │
│ │HTML UI │──→ │ app.js │──→ │ getUserMedia │ │
│ └────────┘ └────┬─────┘ └─────────┬──────────┘ │
└─────────────────────┼────────────────────┼────────────────┘
│ WebSocket │ WebRTC P2P
┌──────▼──────┐ │
│ Go Server │ │
│ ┌─────────┐ │ │
│ │Hub/Room │ │ │
│ │Manager │ │ │
│ └─────────┘ │ │
└──────┬──────┘ │
│ WebSocket │
┌─────────────────────┼────────────────────┼────────────────┐
│ Browser B │ │ │
│ ┌────────┐ ┌────▼──────┐ ┌───────▼────────────┐ │
│ │HTML UI │──→ │ app.js │──→ │ getUserMedia │ │
│ └────────┘ └───────────┘ └────────────────────┘ │
└────────────────────────────────────────────────────────────┘
| Flow | Technology | Description |
|---|---|---|
| Signaling | WebSocket /ws |
Offer/Answer/ICE relay via Go Hub |
| Media | WebRTC P2P | Audio/video streams (direct browser-to-browser) |
| DataChannel | WebRTC P2P | Text chat (direct browser-to-browser) |
webrtc/
├── cmd/server/ # HTTP + WebSocket entry point
├── internal/signal/ # Signaling logic
│ ├── hub.go # Room management, message relay
│ ├── hub_test.go # Unit tests
│ └── message.go # Message types
├── web/ # Frontend (vanilla JS)
│ ├── src/
│ │ ├── core/ # App initialization
│ │ └── controllers/ # UI, media, signaling, peers
│ ├── index.html
│ └── styles.css
├── docs/ # Documentation (EN/ZH)
├── specs/ # Specifications (SDD)
│ ├── product/ # Feature specs
│ ├── rfc/ # Architecture RFCs
│ ├── api/ # OpenAPI specs
│ ├── db/ # Schema definitions
│ └── testing/ # BDD test specs
└── deploy/ # Deployment configs
| Document | Purpose |
|---|---|
| Product Spec | Feature definitions, user stories, acceptance criteria |
| RFC-0001 | Signaling server architecture decisions |
| RFC-0002 | Frontend module design and state management |
| API Spec | OpenAPI 3.0 signaling protocol specification |
| DB Schema | In-memory data structure definitions |
| Testing Spec | BDD acceptance criteria |
| Document | Description |
|---|---|
| Guide | Architecture deep-dive, implementation walkthrough |
| Signaling Protocol | WebSocket message formats and flow |
| Deployment | Docker, HTTPS, TURN server setup |
| API Reference | Environment variables and configuration |
| Troubleshooting | Common issues and solutions |
https://lessup.github.io/webrtc/
Complete documentation with search, navigation, and bilingual support.
| Variable | Default | Description |
|---|---|---|
ADDR |
:8080 |
HTTP listen address |
WS_ALLOWED_ORIGINS |
* |
Allowed origins (comma-separated, * for all) |
RTC_CONFIG_JSON |
Public STUN | ICE/TURN config (JSON) passed to browser |
export RTC_CONFIG_JSON='{
"iceServers": [
{ "urls": ["stun:stun.l.google.com:19302"] },
{
"urls": ["turn:turn.yourdomain.com:3478"],
"username": "your_username",
"credential": "your_password"
}
]
}'- Set
WS_ALLOWED_ORIGINSto your domain (security) - Configure TURN server for NAT traversal
- Enable HTTPS (Caddy auto-handles this)
- Set up monitoring and log rotation
# docker-compose.yml
services:
webrtc:
build: .
environment:
- WS_ALLOWED_ORIGINS=yourdomain.com
- RTC_CONFIG_JSON={"iceServers":[...]}
caddy:
image: caddy:2-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./deploy/web/Caddyfile:/etc/caddy/Caddyfile
coturn:
image: coturn/coturn:latest
network_mode: hostSee Deployment Guide for detailed instructions.
We welcome contributions! This project follows Spec-Driven Development (SDD):
- 📝 Read the relevant specs in
/specsfirst - 💡 Propose spec changes if needed
- 💻 Implement according to specs
- ✅ Test against acceptance criteria
- AGENTS.md — AI agent workflow guidelines
- Contributing Guide — Setup, coding standards, PR process
- Roadmap — Future plans and features
- Changelog — Version history
# Setup
go mod tidy
# Run tests
go test -race ./...
# Run linter
golangci-lint run
# Start with hot reload
air- ✅ Origin whitelist validation
- ✅ Server-verified client identities
- ✅ Connection limits (50/room, 1000 rooms max)
- ✅ Input validation and sanitization
See Security Policy for reporting vulnerabilities.
| Metric | Value |
|---|---|
| Language | Go / JavaScript |
| Lines of Code | ~3,000 Go + ~2,000 JS |
| Test Coverage | Core modules tested |
| License | MIT |