|
1 | 1 | # WebRTC |
2 | 2 |
|
| 3 | +[](https://github.com/LessUp/webrtc/actions/workflows/go.yml) |
3 | 4 | [](LICENSE) |
4 | 5 |  |
5 | 6 |  |
6 | 7 |  |
7 | 8 |
|
8 | | -English | [简体中文](README.zh-CN.md) |
| 9 | +English | [简体中文](README.zh-CN.md) | [📖 Online Docs](https://lessup.github.io/webrtc/) |
9 | 10 |
|
10 | | -A minimal WebRTC demo project built with Go, providing a WebSocket signaling server and browser-based demo for peer-to-peer audio/video communication. |
| 11 | +A minimal WebRTC demo project built with Go, providing a WebSocket signaling server and browser-based demo for peer-to-peer audio/video communication. From 1-on-1 calls to multi-party Mesh rooms, covering core WebRTC capabilities for learning and practice. |
11 | 12 |
|
12 | 13 | ## Features |
13 | 14 |
|
14 | | -- **WebSocket Signaling** — Gorilla WebSocket for Offer/Answer/ICE Candidate relay within rooms |
15 | | -- **Browser Frontend** — One-click audio/video capture and peer-to-peer calling |
16 | | -- **Go Modules** — Easy dependency management and deployment |
17 | | -- **Extensible** — Ready for TURN/SFU/recording integration |
| 15 | +| Feature | Description | |
| 16 | +|:--------|:------------| |
| 17 | +| **WebSocket Signaling** | Gorilla WebSocket for Offer/Answer/ICE Candidate relay within rooms, with heartbeat keep-alive | |
| 18 | +| **Media Controls** | Mute/unmute, camera on/off, screen sharing (`getDisplayMedia`) | |
| 19 | +| **DataChannel** | Peer-to-peer text chat without server relay | |
| 20 | +| **Local Recording** | MediaRecorder captures audio/video streams, exports `.webm` for download | |
| 21 | +| **Multi-party Mesh** | Room member list broadcast, multi-PeerConnection management, grid video layout | |
| 22 | +| **Security** | Origin validation whitelist, room/client limits, auto-reconnection | |
| 23 | +| **Docker** | Multi-stage Dockerfile, Go compilation + static frontend packaging | |
| 24 | + |
| 25 | +## Architecture |
| 26 | + |
| 27 | +``` |
| 28 | +┌──────────────────────────────────────────────────────┐ |
| 29 | +│ Browser A │ |
| 30 | +│ ┌──────────┐ ┌──────────┐ ┌────────────────┐ │ |
| 31 | +│ │ HTML UI │──→│ app.js │──→│ getUserMedia │ │ |
| 32 | +│ └──────────┘ └────┬─────┘ └──────┬─────────┘ │ |
| 33 | +└───────────────────────┼─────────────────┼────────────┘ |
| 34 | + │ WebSocket │ WebRTC P2P |
| 35 | + ┌──────▼──────┐ │ |
| 36 | + │ Go Server │ │ |
| 37 | + │ ┌──────────┐│ │ |
| 38 | + │ │Signal Hub││ │ |
| 39 | + │ └──────────┘│ │ |
| 40 | + └──────┬──────┘ │ |
| 41 | + │ WebSocket │ |
| 42 | +┌───────────────────────┼─────────────────┼────────────┐ |
| 43 | +│ Browser B │ │ │ |
| 44 | +│ ┌──────────┐ ┌────▼─────┐ ┌──────▼─────────┐ │ |
| 45 | +│ │ HTML UI │──→│ app.js │──→│ getUserMedia │ │ |
| 46 | +│ └──────────┘ └──────────┘ └────────────────┘ │ |
| 47 | +└──────────────────────────────────────────────────────┘ |
| 48 | +``` |
| 49 | + |
| 50 | +- **Signaling**: Browser → WebSocket `/ws` → Signal Hub (Offer/Answer/ICE relay) → Browser |
| 51 | +- **Media**: Browser ←→ WebRTC P2P audio/video / DataChannel ←→ Browser |
18 | 52 |
|
19 | 53 | ## Quick Start |
20 | 54 |
|
21 | 55 | ```bash |
22 | | -git clone https://github.com/LessUp/WebRTC.git |
23 | | -cd WebRTC |
| 56 | +git clone https://github.com/LessUp/webrtc.git |
| 57 | +cd webrtc |
24 | 58 | go mod tidy |
25 | 59 | go run ./cmd/server |
26 | 60 | ``` |
27 | 61 |
|
28 | | -Visit http://localhost:8080, open two tabs, enter the same room name, copy one's ID to the other, and click Call. |
| 62 | +Open two browser tabs at http://localhost:8080, enter the same room name, click a member's ID, then click **Call**. |
| 63 | + |
| 64 | +### Docker |
| 65 | + |
| 66 | +```bash |
| 67 | +docker build -t webrtc . |
| 68 | +docker run --rm -p 8080:8080 webrtc |
| 69 | +``` |
29 | 70 |
|
30 | 71 | ## Configuration |
31 | 72 |
|
32 | | -- `ADDR`: Listen address (default `:8080`) |
33 | | -- `WS_ALLOWED_ORIGINS`: Comma-separated allowed origins (default: localhost only) |
| 73 | +| Variable | Description | Default | |
| 74 | +|:---------|:------------|:--------| |
| 75 | +| `ADDR` | HTTP listen address | `:8080` | |
| 76 | +| `WS_ALLOWED_ORIGINS` | Comma-separated allowed origins; set to `*` for all | `localhost` | |
34 | 77 |
|
35 | 78 | ## Project Structure |
36 | 79 |
|
37 | 80 | ``` |
38 | | -WebRTC/ |
39 | | -├── cmd/server/ # HTTP + WebSocket entry |
40 | | -├── internal/signal/ # Signaling (room management, message relay) |
41 | | -├── web/ # Browser UI (HTML + JS + CSS) |
42 | | -├── docs/ # Technical guides |
43 | | -├── Dockerfile # Multi-stage Docker build |
44 | | -└── go.mod |
| 81 | +webrtc/ |
| 82 | +├── cmd/server/ # HTTP + WebSocket entry point |
| 83 | +│ └── main.go # Server startup, graceful shutdown, origin config |
| 84 | +├── internal/signal/ # Signaling logic |
| 85 | +│ ├── hub.go # Room management, message relay, client lifecycle |
| 86 | +│ ├── hub_test.go # Unit tests |
| 87 | +│ └── message.go # Message type definitions |
| 88 | +├── web/ # Browser frontend |
| 89 | +│ ├── index.html # UI |
| 90 | +│ ├── app.js # WebRTC & signaling logic (Mesh multi-party) |
| 91 | +│ └── styles.css # Responsive styles (light/dark theme) |
| 92 | +├── docs/ # Technical documentation |
| 93 | +│ ├── guide.md # Architecture, frontend, media, recording |
| 94 | +│ └── signaling.md # Signaling protocol deep dive |
| 95 | +├── .github/workflows/ # CI/CD |
| 96 | +│ ├── go.yml # Go build + test + lint |
| 97 | +│ └── pages.yml # GitHub Pages deployment |
| 98 | +├── changelog/ # Change logs |
| 99 | +├── Dockerfile # Multi-stage build |
| 100 | +├── .golangci.yml # Linter configuration |
| 101 | +└── go.mod # Go module definition |
45 | 102 | ``` |
46 | 103 |
|
| 104 | +## Tech Stack |
| 105 | + |
| 106 | +| Category | Technology | |
| 107 | +|:---------|:-----------| |
| 108 | +| **Backend** | Go 1.22+, net/http, Gorilla WebSocket | |
| 109 | +| **Frontend** | HTML5 + Vanilla JavaScript + CSS3 | |
| 110 | +| **Media** | WebRTC (getUserMedia, RTCPeerConnection, DataChannel, MediaRecorder) | |
| 111 | +| **Container** | Docker (multi-stage build) | |
| 112 | +| **CI/CD** | GitHub Actions (golangci-lint + multi-version test + GitHub Pages) | |
| 113 | + |
47 | 114 | ## Documentation |
48 | 115 |
|
49 | 116 | - [Technical Guide](docs/guide.md) — Architecture, frontend, media, recording |
50 | 117 | - [Signaling Deep Dive](docs/signaling.md) — Signaling & room management details |
| 118 | +- [Roadmap](ROADMAP.md) — Development plan & progress tracking |
| 119 | +- [Contributing](CONTRIBUTING.md) — Development workflow & code standards |
51 | 120 |
|
52 | 121 | ## Roadmap |
53 | 122 |
|
54 | | -- [x] Room member list & auto-call prompt |
| 123 | +- [x] 1-on-1 call with status display, error handling, heartbeat |
| 124 | +- [x] Mute/camera/screen sharing, DataChannel chat, local recording |
| 125 | +- [x] Room member list, auto-call prompt, multi-party Mesh |
| 126 | +- [x] Docker multi-stage build & deployment |
55 | 127 | - [ ] TURN support (coturn) |
56 | | -- [ ] Multi-party calls (Mesh / SFU) |
57 | | -- [ ] Recording & RTMP relay |
58 | | -- [x] Docker image & cloud deployment |
| 128 | +- [ ] HTTPS/WSS reverse proxy |
| 129 | +- [ ] Multi-party calls via SFU |
59 | 130 |
|
60 | 131 | ## License |
61 | 132 |
|
|
0 commit comments