|
1 | 1 | # WebRTC |
2 | 2 |
|
3 | | -简体中文 | [English](README.en.md) |
4 | | - |
5 | 3 | [](LICENSE) |
6 | 4 |  |
7 | 5 |  |
8 | 6 |  |
9 | 7 |
|
10 | | -WebRTC 是一个基于 Go 的最小可用 WebRTC 示例项目,提供 WebSocket 信令服务器与浏览器端 Demo,适合作为实时音视频应用的入门模板。 |
11 | | - |
12 | | -## 特性 |
13 | | - |
14 | | -- 🌐 WebSocket 信令服务:使用 Gorilla WebSocket 实现房间内的 Offer/Answer/ICE Candidate 转发。 |
15 | | -- 🎥 浏览器前端 Demo:一键采集音视频并发起点对点呼叫。 |
16 | | -- ⚙️ Go Modules 管理依赖,便于扩展与部署。 |
17 | | -- 🔄 可扩展架构:可进一步接入 TURN/SFU/录制等能力。 |
18 | | - |
19 | | -## 架构总览 |
20 | | - |
21 | | -```mermaid |
22 | | -graph TD |
23 | | - subgraph Browser[浏览器] |
24 | | - UI["HTML UI"] |
25 | | - JS["app.js"] |
26 | | - end |
27 | | -
|
28 | | - subgraph Server[Go 后端] |
29 | | - HTTP["HTTP 静态文件"] |
30 | | - WS["/ws WebSocket"] |
31 | | - HUB["Signal Hub"] |
32 | | - end |
33 | | -
|
34 | | - UI --> JS |
35 | | - JS -- "HTTP GET /" --> HTTP |
36 | | - JS -- "WebSocket /ws" --> WS |
37 | | - WS --> HUB |
38 | | - JS -- "WebRTC 媒体/数据通道" --> JS2["远端浏览器"] |
39 | | -``` |
40 | | - |
41 | | -## 快速开始 |
| 8 | +English | [简体中文](README.zh-CN.md) |
42 | 9 |
|
43 | | -### 前置要求 |
| 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. |
44 | 11 |
|
45 | | -- Windows 10/11、macOS 或主流 Linux 发行版 |
46 | | -- Go 1.22+ (推荐使用 `winget install -e --id GoLang.Go` 安装) |
47 | | -- 浏览器:Chrome / Edge / Firefox 最新版 |
| 12 | +## Features |
48 | 13 |
|
49 | | -> 下方命令示例使用 PowerShell,其他平台可使用等价的 shell 命令。 |
| 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 |
50 | 18 |
|
51 | | -### 克隆项目 |
| 19 | +## Quick Start |
52 | 20 |
|
53 | | -```powershell |
54 | | -git clone https://github.com/<your-org>/WebRTC.git |
| 21 | +```bash |
| 22 | +git clone https://github.com/LessUp/WebRTC.git |
55 | 23 | cd WebRTC |
56 | | -``` |
57 | | - |
58 | | -### 配置代理(可选,建议国内开发者设置) |
59 | | -```powershell |
60 | | -go env -w GOPROXY=https://goproxy.cn,direct |
61 | | -go env -w GOSUMDB=sum.golang.google.cn |
62 | | -``` |
63 | | - |
64 | | -### 拉取依赖 |
65 | | - |
66 | | -```powershell |
67 | 24 | go mod tidy |
68 | | -``` |
69 | | - |
70 | | -### 启动服务 |
71 | | - |
72 | | -```powershell |
73 | 25 | go run ./cmd/server |
74 | 26 | ``` |
75 | 27 |
|
76 | | -服务默认监听 `http://localhost:8080`。 |
| 28 | +Visit http://localhost:8080, open two tabs, enter the same room name, copy one's ID to the other, and click Call. |
77 | 29 |
|
78 | | -### 本地测试 |
| 30 | +## Configuration |
79 | 31 |
|
80 | | -1. 浏览器访问 http://localhost:8080 |
81 | | -2. 在两个页面输入相同的房间名并 Join。 |
82 | | -3. 复制其中一个页面的 `Your ID` 到另一个页面的 Remote ID,点击 `Call`。 |
83 | | -4. 允许浏览器访问摄像头/麦克风,即可看到远端视频。 |
| 32 | +- `ADDR`: Listen address (default `:8080`) |
| 33 | +- `WS_ALLOWED_ORIGINS`: Comma-separated allowed origins (default: localhost only) |
84 | 34 |
|
85 | | -> 提示:若在同一台机器打开两个窗口但无法互通,请先关闭 `HTTPS-Only` 模式或在隐身窗口测试。 |
86 | | -
|
87 | | -## 配置 |
88 | | - |
89 | | -可以通过环境变量调整服务监听地址: |
90 | | - |
91 | | -- `ADDR`:HTTP 服务监听地址(默认 `:8080`)。 |
92 | | - |
93 | | -默认情况下,信令服务只允许本地开发来源(`localhost` / `127.0.0.1`)。 |
94 | | -如需在其他域名下访问,可以设置环境变量 `WS_ALLOWED_ORIGINS`,例如: |
95 | | - |
96 | | -```powershell |
97 | | -$env:WS_ALLOWED_ORIGINS="https://example.com,https://foo.bar" |
98 | | -go run ./cmd/server |
99 | | -``` |
100 | | - |
101 | | -如需临时允许所有来源(不推荐用于生产环境),可设置: |
102 | | - |
103 | | -```powershell |
104 | | -$env:WS_ALLOWED_ORIGINS="*" |
105 | | -go run ./cmd/server |
106 | | -``` |
107 | | - |
108 | | -在生产环境中请根据实际域名进行配置。 |
109 | | - |
110 | | -## 文档 |
111 | | - |
112 | | -- [docs/guide.md](docs/guide.md):项目整体技术说明(架构、前端、媒体、录制等)。 |
113 | | -- [docs/signaling.md](docs/signaling.md):信令与房间管理的深入讲解。 |
114 | | - |
115 | | -## 项目结构 |
| 35 | +## Project Structure |
116 | 36 |
|
117 | 37 | ``` |
118 | 38 | WebRTC/ |
119 | | -├── cmd/ |
120 | | -│ └── server/ # HTTP + WebSocket 服务入口 |
121 | | -├── internal/ |
122 | | -│ └── signal/ # 信令逻辑(房间管理、消息转发) |
123 | | -├── web/ |
124 | | -│ ├── index.html # 浏览器端 UI |
125 | | -│ ├── app.js # WebRTC & WS 信令逻辑 |
126 | | -│ └── styles.css # 样式表 |
127 | | -├── docs/ |
128 | | -│ ├── guide.md # 项目技术说明(学习向) |
129 | | -│ └── signaling.md # 信令与房间管理详解 |
130 | | -├── changelog/ # 变更日志 |
131 | | -├── Dockerfile # 多阶段 Docker 构建 |
132 | | -├── .editorconfig # 编辑器格式统一 |
133 | | -├── go.mod |
134 | | -├── .gitignore |
135 | | -├── .gitattributes |
136 | | -└── README.md |
| 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 |
137 | 45 | ``` |
138 | 46 |
|
139 | | -## 路线图 |
| 47 | +## Documentation |
| 48 | + |
| 49 | +- [Technical Guide](docs/guide.md) — Architecture, frontend, media, recording |
| 50 | +- [Signaling Deep Dive](docs/signaling.md) — Signaling & room management details |
140 | 51 |
|
141 | | -- [x] 房间成员列表与自动呼叫提示 |
142 | | -- [ ] TURN 支持(coturn) |
143 | | -- [ ] 多人通话(Mesh / 引入 SFU 框架) |
144 | | -- [ ] 录制与旁路推流(RTMP/RTC) |
145 | | -- [x] Docker 镜像与云端部署示例 |
| 52 | +## Roadmap |
146 | 53 |
|
147 | | -欢迎提交 Issue 与 PR 参与共建。 |
| 54 | +- [x] Room member list & auto-call prompt |
| 55 | +- [ ] TURN support (coturn) |
| 56 | +- [ ] Multi-party calls (Mesh / SFU) |
| 57 | +- [ ] Recording & RTMP relay |
| 58 | +- [x] Docker image & cloud deployment |
148 | 59 |
|
149 | 60 | ## License |
150 | 61 |
|
|
0 commit comments