Skip to content

Shadowsocks-NET/p2pvoice-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P2P Voice (Go)

一个基于 Go 的即时语音 MVP:

  • Go 信令服务(WebSocket)
  • WebRTC 点对点语音传输(浏览器采集/播放音频)
  • 房间 + 昵称 + 一对一呼叫

1. 启动

go mod tidy
go run ./cmd/server

默认监听:

  • HTTP: :9008
  • HTTPS: :9007(仅在提供证书参数时启用)

可用环境变量修改:

HTTP_ADDR=:9010 HTTPS_ADDR=:9443 go run ./cmd/server

1.1 HTTPS(跨设备必须)

跨设备通过局域网 IP 访问页面时,浏览器通常要求 HTTPS 才允许麦克风。启动方式:

go run ./cmd/server -http-addr :9008 -https-addr :9007 -tls-cert ./certs/cert.pem -tls-key ./certs/key.pem

也支持环境变量:

TLS_CERT=./certs/cert.pem TLS_KEY=./certs/key.pem go run ./cmd/server

启动后可同时访问:

  • http://<服务器IP>:9008
  • https://<服务器IP>:9007

2. 使用

  1. 同一台机器测试可访问 http://localhost:9008
  2. 跨设备测试建议访问 https://<服务器IP>:9007
  3. 输入相同房间,不同昵称,点击连接
  4. 选择在线用户并呼叫,另一端点击“接听”
  5. 通话建立后语音为 WebRTC P2P 直连(必要时可经 ICE 中继)

3. TURN(生产建议)

当前前端默认使用公开 STUN。跨 NAT/防火墙较复杂场景下请配置自建 TURN(如 coturn),并将 cmd/server/web/app.js 里的 iceServers 改为你的 TURN 地址和凭据。

4. 项目结构

cmd/server/main.go          # 启动入口(信令 + 静态资源)
cmd/server/web/index.html   # 页面
cmd/server/web/app.js       # WebRTC 呼叫逻辑
cmd/server/web/styles.css   # 样式
internal/signaling/hub.go   # 房间、用户、消息转发

5. 当前能力与限制

  • 支持:点对点语音、一对一呼叫、ICE candidate 交换、挂断
  • 限制:无鉴权、无离线消息、无通话录音、无多方会议

About

A Go + WebRTC peer-to-peer voice calling app with rooms, one-to-one calls, auto-reconnect, live network stats, audio controls, volume boost, and system-aware theme switching.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors