直播:后台 JWT 推流、前台画中画;WebRTC 服务与 Nginx WebSocket 代理

Made-with: Cursor
This commit is contained in:
whm
2026-03-25 15:00:14 +08:00
parent b83ec91b1a
commit 7811adca66
1050 changed files with 146524 additions and 37 deletions

View File

@@ -0,0 +1,33 @@
package weblive
import (
"encoding/json"
"os"
"strings"
"github.com/pion/webrtc/v3"
)
// MediaEngine 与 API 构建(全局复用,避免重复注册编解码器)
func buildAPI() (*webrtc.API, error) {
m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
return nil, err
}
api := webrtc.NewAPI(webrtc.WithMediaEngine(m))
return api, nil
}
func iceServersFromEnv() []webrtc.ICEServer {
raw := strings.TrimSpace(os.Getenv("LIVE_ICE_SERVERS"))
if raw == "" {
return []webrtc.ICEServer{
{URLs: []string{"stun:stun.l.google.com:19302"}},
}
}
var servers []webrtc.ICEServer
if err := json.Unmarshal([]byte(raw), &servers); err != nil {
return []webrtc.ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}}
}
return servers
}