mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-01 02:52:49 +08:00
342 lines
16 KiB
Markdown
342 lines
16 KiB
Markdown
# WebSpeak
|
||
|
||
WebSpeak 是一个自托管的 TeamSpeak 浏览器客户端与访客接入网关。每个浏览器 Session 都拥有独立的普通 TeamSpeak Client 连接;频道、成员和权限来自该用户自己的可见数据,不依赖 ServerQuery、WebQuery 或维护机器人。
|
||
|
||
[中文](#中文) · [English](#english) · [AGPL-3.0 License](LICENSE)
|
||
|
||
## 中文
|
||
|
||
### 当前能力
|
||
|
||
- TeamSpeak 3 / TeamSpeak 6 自动探测,无需选择协议。
|
||
- 每个浏览器 Session 独立连接,硬上限固定为 100。
|
||
- Session 生命周期统一管理:连接状态机、WebSocket 心跳、幂等清理和优雅关闭。
|
||
- TeamSpeak 临时断线自动重连,固定退避策略最长持续 5 分钟;认证失败不会无限重试,并尽量恢复原频道。
|
||
- 完整频道/成员树、频道切换、频道文字聊天和成员实时移动。
|
||
- PCM/Opus 语音桥接、自由麦、按键说话、麦克风与扬声器设备选择、输入/输出音量控制。
|
||
- 音频设置显示权限、实时麦克风音量和 VOX 阈值;VOX 带 attack/hold/release,设备热插拔时自动回退默认设备。
|
||
- 移动端提供不会因触控取消而卡住的“按住说话”;麦克风测试最多录制 5 秒并只在本地播放,不发送到 TeamSpeak。
|
||
- 支持连接、断开、Poke、私聊和重连失败提示音;浏览器不支持输出设备选择时明确降级到默认输出。
|
||
- 发言成员头像显示绿色动态边框。
|
||
- 频道、服务器和私聊独立标签;成员菜单支持私聊、Poke、复制昵称,频道密码按次输入且不持久化。
|
||
- Away、成员状态图标、Session 内服务器事件日志和人类可读的 TeamSpeak 权限错误。
|
||
- 中英文访客页面和中英文管理控制台。
|
||
- Web 管理闭环:默认账号首次登录强制改密、单管理员登录、概览、服务器设置和真实连接测试。
|
||
- 运维控制台:受控邀请创建/撤销/过期/限次、活动会话列表与单会话断开、审计事件、结构化日志查看、脱敏诊断报告和 SQLite 备份导出。
|
||
- `fixed` 与 `open` 两种访问模式。
|
||
- 可选的持久 TeamSpeak identity:身份私钥仅保存在浏览器 IndexedDB,可导入/导出;访客也可继续使用临时身份。
|
||
- 浏览器本地收藏、最近服务器、昵称、语言、音频设备/模式/音量和按 TeamSpeak UID 保存的成员音量。
|
||
- 可清除全部 WebSpeak 本地数据;不保存服务器密码。
|
||
- TeamSpeak 密码使用安装级主密钥加密保存,不向管理 API 返回明文。
|
||
- 旧 `config.json` 一次性导入,导入后不再作为实时配置源。
|
||
- `/demo` 提供不连接真实 TeamSpeak 的交互式模拟页面,可用于产品预览和录屏。
|
||
- 当前实现按 `webspeak-spec` 的 M000–M010 顺序推进;M010 的真实 TS3/TS6、Android 麦克风和 24 小时长稳测试必须在对应环境完成,不能用本地模拟替代。
|
||
|
||
### 环境要求
|
||
|
||
- Node.js `22.5.0` 或更高版本。
|
||
- Linux 推荐;Windows 也可用于开发和运行。
|
||
- `@discordjs/opus` 所需的原生编译工具。
|
||
- 可访问的 TeamSpeak 3 或 TeamSpeak 6 服务器。
|
||
- 较新的 Chrome 或 Edge;生产环境应使用 HTTPS。
|
||
|
||
### Docker 部署(推荐)
|
||
|
||
全新 Linux 主机只需要 Docker:
|
||
|
||
```bash
|
||
docker run -d \
|
||
--name webspeak \
|
||
--restart unless-stopped \
|
||
-p 3040:3040 \
|
||
-v webspeak-data:/data \
|
||
ghcr.io/EchoSixHIYA/webspeak:latest
|
||
```
|
||
|
||
容器内部端口固定为 `3040`,SQLite 数据库、主密钥和日志持久化在 `/data`。启动后打开 `http://你的地址:3040/admin`,使用 `admin/admin` 登录并按页面要求修改密码。生产环境请在前面配置 HTTPS 反向代理。
|
||
|
||
也可以使用仓库附带的 `docker-compose.yml`:
|
||
|
||
```bash
|
||
docker compose up -d
|
||
docker logs webspeak
|
||
```
|
||
|
||
Ubuntu / Debian:
|
||
|
||
```bash
|
||
sudo apt-get update
|
||
sudo apt-get install -y build-essential python3
|
||
```
|
||
|
||
Windows 请安装 Visual Studio Build Tools,并勾选“使用 C++ 的桌面开发”。
|
||
|
||
### 本地安装与启动
|
||
|
||
```bash
|
||
npm install
|
||
npm --prefix web install
|
||
npm --prefix web run build
|
||
npm run build
|
||
node dist/index.js
|
||
```
|
||
|
||
WebSpeak 内部端口固定为 `3040`。首次启动会自动创建默认管理员账号:
|
||
|
||
```text
|
||
账号:admin
|
||
密码:admin
|
||
```
|
||
|
||
然后打开管理入口:
|
||
|
||
```text
|
||
http://127.0.0.1:3040/admin
|
||
```
|
||
|
||
首次登录后必须设置一个至少 12 个字符的新密码。改密完成后,在“服务器设置”中填写 TeamSpeak 目标并执行连接测试,再保存访问模式和站点信息。
|
||
|
||
后续管理入口仍为 `/admin`。管理员账号名固定为 `admin`,当前版本不提供用户列表或角色系统。
|
||
|
||
### 访问模式
|
||
|
||
`fixed` 是默认模式。访客页只显示昵称和频道,TeamSpeak 目标与服务器密码由服务端管理。
|
||
|
||
欢迎页没有邀请链接目标参数时,地址和端口输入框会预填管理控制台中配置的“默认 TeamSpeak 目标”;邀请链接中的目标参数优先使用。
|
||
|
||
`open` 模式允许访客输入其他公网 TeamSpeak 地址和本次 Session 使用的密码。WebSpeak 会解析 DNS,并阻止 loopback、私网、链路本地、组播、广播及保留地址;实际连接使用已经验证过的 IP,避免 DNS rebinding。
|
||
|
||
访客密码只存在于一次性 Join Ticket 中,不写入 URL、本地存储或数据库。普通分享链接也不会包含密码。
|
||
|
||
### 持久化与安全
|
||
|
||
运行数据位于项目的 `data/` 目录:
|
||
|
||
```text
|
||
data/
|
||
webspeak.db SQLite 配置、管理员凭据和有限审计事件
|
||
master.key 32 字节安装级主密钥
|
||
logs/ 本地日志
|
||
```
|
||
|
||
日志文件单个最多 10 MiB,服务会保留 3 个轮转文件。管理控制台中的“导出数据库备份”只导出 SQLite 数据库,不导出 `master.key`;数据库内的 TeamSpeak 密码仍是加密密文,完整恢复需要同时保管数据目录和主密钥。
|
||
|
||
- 管理员密码使用 Node.js `crypto.scrypt`、随机 salt 和 constant-time compare。
|
||
- 新部署首次使用 `admin/admin` 登录后必须立即修改密码;修改完成后默认密码失效。
|
||
- TeamSpeak 服务器密码使用 AES-256-GCM 加密。
|
||
- 管理 Session 是随机服务端 Session;Cookie 为 `HttpOnly`、`SameSite=Strict`,直接 HTTPS 下同时启用 `Secure`。
|
||
- 管理 mutation 检查同源请求、JSON Content-Type、服务端 Session 与 CSRF token。
|
||
- 管理登录具有固定窗口限速和连续失败延迟。
|
||
- 日志、管理 API 和 Overview 不返回服务器密码、管理员密码或身份私钥。
|
||
- 普通用户 identity 只通过当前 Join Ticket/Session 在内存中使用,不写入 Gateway 数据库、日志或诊断信息。
|
||
|
||
浏览器身份导出文件包含可冒用该 TeamSpeak identity 的私密凭据,只应保存到可信位置;不要上传到 WebSpeak 或提交到 Git。
|
||
|
||
请备份整个 `data/` 目录。只有数据库而没有对应 `master.key` 时,已加密的 TeamSpeak 密码无法恢复。不要提交 `data/`、`config.json`、证书、私钥或日志。
|
||
|
||
### 从旧版本升级
|
||
|
||
首次使用新版启动时,如果项目根目录存在旧 `config.json`,WebSpeak 只导入:
|
||
|
||
- `tsHost`
|
||
- `tsPort`
|
||
- `tsServerPassword`
|
||
|
||
以下字段会被忽略并废弃:
|
||
|
||
- `port`
|
||
- `tsServerProtocol`
|
||
- `maxClients`
|
||
- `trustProxy`
|
||
|
||
原文件不会被删除或改写。导入成功后,`data/webspeak.db` 成为唯一实时配置源,管理控制台会显示一次迁移提示。`config.example.json` 仅用于说明旧版迁移格式,新部署不需要复制它。
|
||
|
||
### HTTPS 与反向代理
|
||
|
||
如果项目根目录存在 `certs/cert.pem` 与 `certs/key.pem`,WebSpeak 会直接提供 HTTPS。公网部署建议由 Caddy 或 Nginx 终止 TLS,再代理到固定的 `127.0.0.1:3040`。
|
||
|
||
Nginx 示例:
|
||
|
||
```nginx
|
||
server {
|
||
listen 443 ssl;
|
||
server_name ts.example.com;
|
||
|
||
ssl_certificate /etc/letsencrypt/live/ts.example.com/fullchain.pem;
|
||
ssl_certificate_key /etc/letsencrypt/live/ts.example.com/privkey.pem;
|
||
|
||
location / {
|
||
proxy_pass http://127.0.0.1:3040;
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
proxy_set_header Host $host;
|
||
}
|
||
}
|
||
```
|
||
|
||
WebSpeak 不使用 `X-Forwarded-*` 作为认证或授权边界。麦克风和 WebCodecs 在公网环境需要浏览器安全上下文。
|
||
|
||
### 健康检查与开发命令
|
||
|
||
无需认证的最小健康检查:
|
||
|
||
```text
|
||
GET /health
|
||
GET /api/health
|
||
```
|
||
|
||
开发命令:
|
||
|
||
```bash
|
||
# 后端开发服务(固定 3040)
|
||
npm run dev
|
||
|
||
# 前端开发服务;/api 和 /ws 代理到 3040
|
||
npm run web:dev
|
||
|
||
# 浏览器打开演示页(不会连接真实 TeamSpeak)
|
||
# http://localhost:5173/demo
|
||
|
||
# 自动测试(覆盖 M000–M010 已实现的后端协议与安全边界)
|
||
npm test
|
||
|
||
# 后端类型检查与构建
|
||
npm run build
|
||
|
||
# 前端类型检查与生产构建
|
||
npm --prefix web run build
|
||
|
||
# 依赖安全审计
|
||
npm audit
|
||
```
|
||
|
||
### 项目结构
|
||
|
||
```text
|
||
src/
|
||
admin/ 管理服务、API、Session、邀请与运维接口
|
||
persistence/database.ts SQLite schema、repository 和迁移边界
|
||
security/ 主密钥、秘密加密、scrypt 与网络策略
|
||
domain/teamspeak-target.ts host[:port] 规范化解析
|
||
server/teamspeak-adapter.ts TeamSpeak 协议边界与 endpoint 协议缓存
|
||
server/teamspeak-probe.ts 可清理的短连接测试
|
||
server/join-ticket.ts 一次性访客连接票据
|
||
server/join-rate-limit.ts 访客票据创建限速
|
||
server/voice-bridge.ts 每用户语音 WebSocket 桥接
|
||
web/src/views/
|
||
AdminView.vue 双语登录、设置、概览与运维控制台
|
||
WebClient.vue 双语访客与语音工作台
|
||
```
|
||
|
||
## English
|
||
|
||
WebSpeak is a self-hosted TeamSpeak web client and guest gateway. Every browser session owns an independent normal TeamSpeak client connection, so its channel/member view comes from that identity rather than a Query or maintenance account.
|
||
|
||
### Features
|
||
|
||
- Automatic TeamSpeak 3 / TeamSpeak 6 detection.
|
||
- Independent browser sessions with a fixed hard limit of 100.
|
||
- Managed session lifecycle with a connection state machine, WebSocket heartbeat, idempotent teardown, and graceful shutdown.
|
||
- Temporary TeamSpeak failures recover with bounded jittered backoff for up to five minutes; authentication failures are not retried forever, and the previous channel is restored when possible.
|
||
- Channel/member directory, channel switching, channel text chat, and live member movement.
|
||
- PCM/Opus voice bridge, VOX, push-to-talk, input/output device selection, and clamped volume controls.
|
||
- Audio diagnostics expose permission, live mic level, VOX threshold, and audio context state; device hotplug falls back to the default input/output.
|
||
- Mobile push-to-talk handles pointer cancellation and focus loss; local microphone tests record at most five seconds and never send to TeamSpeak.
|
||
- Built-in sounds cover connection, disconnection, poke, private messages, and failed reconnects, with a clear default-output fallback when the browser lacks output selection.
|
||
- Independent channel, server, and private chat tabs; member actions for private message, poke, and nickname copy; channel passwords are entered per session only.
|
||
- Away, member status icons, a session-local server event log, and readable TeamSpeak permission errors.
|
||
- Bilingual guest UI and bilingual admin console.
|
||
- Browser-based admin login, mandatory first-login password change, Overview, server settings, and a real short-lived connection test.
|
||
- Operations dashboard for managed invites, session termination, audit events, logs, sanitized diagnostic reports, and SQLite backup export.
|
||
- Fixed and open guest access modes.
|
||
- Optional persistent TeamSpeak identity stored only in browser IndexedDB, with local import/export; guests can still join ephemerally.
|
||
- Browser-local favorites, recent servers, nickname/language/audio preferences, and per-TeamSpeak-UID member volume.
|
||
- Clear all WebSpeak local data at any time; server passwords are never stored there.
|
||
- Encrypted TeamSpeak server password and one-time legacy config import.
|
||
- No ServerQuery, WebQuery, admin token, or maintenance bot.
|
||
- `/demo` is a clearly labeled interactive simulation and never opens a real TeamSpeak connection.
|
||
- Join-ticket creation is rate-limited per peer; runtime logs rotate at a bounded size.
|
||
|
||
### Requirements and startup
|
||
|
||
- Node.js `22.5.0` or newer.
|
||
- Native build tools for `@discordjs/opus`.
|
||
- A reachable TS3 or TS6 server.
|
||
- A recent Chrome or Edge browser; use HTTPS in production.
|
||
|
||
### Docker deployment (recommended)
|
||
|
||
On a fresh Linux host, Docker is the only requirement:
|
||
|
||
```bash
|
||
docker run -d \
|
||
--name webspeak \
|
||
--restart unless-stopped \
|
||
-p 3040:3040 \
|
||
-v webspeak-data:/data \
|
||
ghcr.io/EchoSixHIYA/webspeak:latest
|
||
```
|
||
|
||
The container always listens on `3040`. SQLite, the installation master key, and logs persist under `/data`. Open `http://your-host:3040/admin`, sign in with `admin/admin`, and change the password when prompted. Put an HTTPS reverse proxy in front of the container for production microphone access.
|
||
|
||
The repository also includes `docker-compose.yml`:
|
||
|
||
```bash
|
||
docker compose up -d
|
||
docker logs webspeak
|
||
```
|
||
|
||
```bash
|
||
npm install
|
||
npm --prefix web install
|
||
npm --prefix web run build
|
||
npm run build
|
||
node dist/index.js
|
||
```
|
||
|
||
WebSpeak always listens on internal port `3040`. On first boot it creates the default administrator `admin` with password `admin`. Open the admin console:
|
||
|
||
```text
|
||
http://127.0.0.1:3040/admin
|
||
```
|
||
|
||
The first login is forced to a password-change screen. Set a password of at least 12 characters, then configure and test the TeamSpeak target from Server settings. Future administration is performed at `/admin`; no JSON editing or restart is needed for normal setting changes.
|
||
|
||
### Security and persistence
|
||
|
||
Local state is stored under `data/` in SQLite plus a 32-byte `master.key`. Admin passwords use `crypto.scrypt`. A new instance starts with `admin/admin` and marks that credential for mandatory rotation on first login. TeamSpeak secrets use AES-256-GCM. Admin sessions are server-side with HttpOnly/SameSite Strict cookies, same-origin and CSRF checks, and fixed login throttling.
|
||
|
||
A normal user's identity is used only in memory for the current Join Ticket/Session and is never written to the Gateway database, logs, or diagnostics. An exported browser identity file contains private credentials that can impersonate the TeamSpeak identity. Keep it in a trusted location; never upload it to WebSpeak or commit it to Git.
|
||
|
||
In fixed mode, guests cannot override the configured target. In open mode, arbitrary public targets are validated after DNS resolution; private, loopback, link-local, multicast, broadcast, and reserved addresses are rejected. Session passwords travel through an opaque one-time Join Ticket and are never placed in share or WebSocket URLs.
|
||
|
||
When the welcome page has no target parameters from an invite link, its address and port field is prefilled from the admin-configured default TeamSpeak target. Invite-link target parameters take precedence.
|
||
|
||
Administrators can create managed invite links from `/admin/operations`. An invite stores only a token hash and encrypted connection secret, can expire or be limited to a number of uses, and can be revoked. The raw token is returned only at creation time and is passed as an `invite` URL parameter; no TeamSpeak password is placed in that URL. The database backup and diagnostic report are separate: the report is sanitized for issue sharing, while the database backup is for local recovery and must be protected.
|
||
|
||
If a legacy `config.json` exists on the first upgraded start, only `tsHost`, `tsPort`, and `tsServerPassword` are imported. The original file is preserved, and SQLite becomes the sole live settings source.
|
||
|
||
### Development
|
||
|
||
```bash
|
||
npm run dev
|
||
npm run web:dev
|
||
npm test
|
||
npm run build
|
||
npm --prefix web run build
|
||
npm audit
|
||
```
|
||
|
||
The Windows development environment may need the native build toolchain required by `@discordjs/opus`. The browser UI can still be verified locally with `npm run web:dev` and `/demo`; that route is deliberately simulated and does not prove a real TeamSpeak connection.
|
||
|
||
### License
|
||
|
||
WebSpeak is licensed under the [GNU Affero General Public License v3.0 only](LICENSE) (`AGPL-3.0-only`). If you run a modified version as a network service, you must offer its users the corresponding source code as required by the license.
|
||
|
||
### 社区 / Community
|
||
|
||
群号 / Group ID: `869500475`
|
||
|
||

|