Skip to content

Commit f038c4c

Browse files
author
shijiashuai
committed
docs: improve GitHub Pages, docs quality, and add golangci config
1 parent 7082406 commit f038c4c

File tree

16 files changed

+903
-247
lines changed

16 files changed

+903
-247
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Go CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.23'
23+
24+
- name: Run golangci-lint
25+
uses: golangci/golangci-lint-action@v6
26+
with:
27+
version: latest
28+
29+
test:
30+
name: Test (Go ${{ matrix.go-version }})
31+
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
go-version: ['1.22', '1.23']
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
39+
- name: Setup Go
40+
uses: actions/setup-go@v5
41+
with:
42+
go-version: ${{ matrix.go-version }}
43+
44+
- name: Verify dependencies
45+
run: go mod verify
46+
47+
- name: Build
48+
run: go build ./...
49+
50+
- name: Run tests
51+
run: go test -race -count=1 -coverprofile=coverage.out ./...
52+
53+
- name: Run vet
54+
run: go vet ./...

.github/workflows/go.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.golangci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
run:
2+
timeout: 3m
3+
modules-download-mode: readonly
4+
5+
linters:
6+
enable:
7+
- errcheck
8+
- govet
9+
- ineffassign
10+
- staticcheck
11+
- unused
12+
- gosimple
13+
- gocritic
14+
- revive
15+
- misspell
16+
- prealloc
17+
18+
linters-settings:
19+
gocritic:
20+
enabled-tags:
21+
- diagnostic
22+
- style
23+
disabled-checks:
24+
- hugeParam
25+
revive:
26+
rules:
27+
- name: blank-imports
28+
- name: context-as-argument
29+
- name: dot-imports
30+
- name: error-return
31+
- name: error-strings
32+
- name: exported
33+
disabled: true
34+
- name: increment-decrement
35+
- name: var-naming
36+
- name: package-comments
37+
disabled: true
38+
misspell:
39+
locale: US
40+
41+
issues:
42+
max-issues-per-linter: 50
43+
max-same-issues: 5

404.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
layout: default
3+
title: 404 — 页面未找到
4+
permalink: /404.html
5+
---
6+
7+
<div align="center" style="padding: 60px 20px;">
8+
9+
<h1>404</h1>
10+
11+
<p style="font-size: 1.2em; color: #6b7280;">抱歉,您访问的页面不存在。</p>
12+
13+
<p>
14+
<a href="{{ site.baseurl }}/">← 返回首页</a> ·
15+
<a href="https://github.com/LessUp/webrtc">GitHub 仓库</a>
16+
</p>
17+
18+
</div>

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
layout: default
3+
title: 变更日志 — WebRTC
4+
description: WebRTC 项目各版本变更记录
5+
---
6+
7+
[← 返回首页]({{ site.baseurl }}/)
8+
9+
# 变更日志
10+
11+
所有重要变更均记录在 [`changelog/`](changelog/) 目录中,按日期倒序排列。
12+
13+
| 日期 | 摘要 |
14+
|:-----|:-----|
15+
| [2026-03-09](changelog/2026-03-09_pages-and-quality.md) | GitHub Pages 全面优化、golangci-lint、测试覆盖率增强、文档同步 |
16+
| [2026-03-09](changelog/2026-03-09_stability-and-security.md) | writePump 协程泄露修复、房间/人数上限、WebSocket 自动重连 |
17+
| [2026-02-13](changelog/2026-02-13.md) | 全面优化与重构(后端提取 broadcastMembers、前端重构、CI 增强、Docker) |
18+
| [2025-12-18](changelog/2025-12-18.md) | DataChannel 聊天、成员列表、Mesh 多人通话、Origin 校验、心跳 |
19+
| [2025-02-13](changelog/2025-02-13_project-infrastructure.md) | README badges 添加 |

CONTRIBUTING.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
---
2+
layout: default
3+
title: 贡献指南 — WebRTC
4+
description: WebRTC 项目贡献流程、代码规范与提交信息格式
5+
---
6+
7+
[← 返回首页]({{ site.baseurl }}/)
8+
19
# Contributing
210

311
感谢你对本项目的关注!欢迎通过 Issue 和 Pull Request 参与贡献。
@@ -10,19 +18,49 @@
1018
4. 推送分支:`git push origin feature/your-feature`
1119
5. 创建 Pull Request
1220

13-
## 开发与测试
21+
## 开发环境
22+
23+
### 前置要求
24+
25+
- Go 1.22+
26+
- 浏览器(Chrome / Edge / Firefox 最新版)
27+
- (可选)[golangci-lint](https://golangci-lint.run/welcome/install/) 用于本地 lint
28+
29+
### 启动开发服务
1430

1531
```bash
1632
go mod tidy
1733
go run ./cmd/server
34+
# 浏览器访问 http://localhost:8080
35+
```
36+
37+
## 测试与质量检查
38+
39+
提交前请确保以下检查全部通过:
40+
41+
```bash
42+
# 构建
43+
go build ./...
44+
45+
# 单元测试(Linux/macOS 支持 -race)
46+
go test -race -count=1 ./...
47+
48+
# 静态分析
49+
go vet ./...
50+
51+
# Lint(需安装 golangci-lint)
52+
golangci-lint run
1853
```
1954

55+
CI 会自动运行 golangci-lint、多版本 Go 测试和 staticcheck。
56+
2057
## 代码规范
2158

2259
- Go 代码遵循 `gofmt``go vet` 规范
60+
- Lint 规则定义在 `.golangci.yml`
2361
- 使用 `.editorconfig` 中定义的缩进和格式规则
2462
- 前端代码保持简洁,避免引入重型框架
25-
- 确保构建无错误
63+
- 确保构建和测试无错误
2664

2765
## 提交信息格式
2866

@@ -32,4 +70,5 @@ go run ./cmd/server
3270
- `fix:` 修复 Bug
3371
- `docs:` 文档更新
3472
- `refactor:` 重构
73+
- `test:` 测试
3574
- `chore:` 构建/工具链

README.md

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,132 @@
11
# WebRTC
22

3+
[![Go CI](https://github.com/LessUp/webrtc/actions/workflows/go.yml/badge.svg)](https://github.com/LessUp/webrtc/actions/workflows/go.yml)
34
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
45
![Go](https://img.shields.io/badge/Go-1.22+-00ADD8?logo=go&logoColor=white)
56
![WebRTC](https://img.shields.io/badge/WebRTC-Enabled-333333?logo=webrtc&logoColor=white)
67
![Docker](https://img.shields.io/badge/Docker-Ready-2496ED?logo=docker&logoColor=white)
78

8-
English | [简体中文](README.zh-CN.md)
9+
English | [简体中文](README.zh-CN.md) | [📖 Online Docs](https://lessup.github.io/webrtc/)
910

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.
1112

1213
## Features
1314

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
1852

1953
## Quick Start
2054

2155
```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
2458
go mod tidy
2559
go run ./cmd/server
2660
```
2761

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+
```
2970

3071
## Configuration
3172

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` |
3477

3578
## Project Structure
3679

3780
```
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
45102
```
46103

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+
47114
## Documentation
48115

49116
- [Technical Guide](docs/guide.md) — Architecture, frontend, media, recording
50117
- [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
51120

52121
## Roadmap
53122

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
55127
- [ ] 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
59130

60131
## License
61132

0 commit comments

Comments
 (0)