Add WebRTC TURN configuration and related enhancements

- Introduce a new `.env.example` file for environment variable setup, including `PUBLIC_IP`, `TURN_SECRET`, and `TURN_URLS` for WebRTC TURN server configuration.
- Update `docker-compose.yaml` to support TURN server deployment with necessary environment variables and commands.
- Enhance backend configuration and routes to include WebRTC ICE server settings, allowing for STUN/TURN server integration.
- Implement a new service for managing WebRTC ICE server configurations, providing credentials for TURN when configured.
- Modify frontend API to fetch ICE server configurations dynamically, improving support for cross-network voice preview.
This commit is contained in:
Xin Wang
2026-07-06 17:45:53 +08:00
parent d6b04d71a0
commit e857828fe5
9 changed files with 121 additions and 16 deletions

View File

@@ -49,6 +49,9 @@ services:
DATABASE_URL: "postgresql+asyncpg://postgres:${POSTGRES_PASSWORD:-postgres}@postgres:5432/postgres"
# 3030 = docker ui 宿主端口;3000 = 宿主机裸跑 npm run dev 时的端口
CORS_ORIGINS: "http://localhost:3030,http://127.0.0.1:3030,http://localhost:3000,http://127.0.0.1:3000"
# WebRTC TURN(公网部署:设 PUBLIC_IP + TURN_SECRET,并 docker compose --profile remote up)
TURN_URLS: "${TURN_URLS:-}"
TURN_SECRET: "${TURN_SECRET:-}"
ports:
- "8000:8000"
depends_on:
@@ -112,17 +115,24 @@ services:
networks: [app-network]
# ---- 可选(profile: remote):WebRTC 公网穿透 ----
# 在项目根 .env 设置 PUBLIC_IP(云主机公网 IP)与 TURN_SECRET,与 backend TURN_SECRET 一致。
# 云安全组放行:UDP/TCP 3478,UDP 49152-49200。
coturn:
image: coturn/coturn:4.8.0
profiles: ["remote"]
network_mode: host # TURN 需直接占用 UDP 端口段
network_mode: host
command:
- -n
- --log-file=stdout
- --listening-port=3478
- --listening-ip=0.0.0.0
- --external-ip=${PUBLIC_IP:?set PUBLIC_IP in .env for coturn}
- --realm=ai-video
- --use-auth-secret
- --static-auth-secret=${TURN_SECRET:-changeme}
- --min-port=49152
- --max-port=49200
- --no-cli
# ---- 可选(profile: tls):nginx 反代统一 TLS,局域网 https 调试语音预览 ----
# 起前先生成证书:./deploy/setup-certs.sh(证书落在 deploy/certs/)