From 5758c9f01e481db232466719e9d15049f3dec969 Mon Sep 17 00:00:00 2001 From: zhongyuan Date: Thu, 23 Dec 2021 19:03:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E7=A0=81=E7=8E=87=E8=BF=87=E4=BD=8E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 5b29841..152c41a 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package webrtc import ( "encoding/json" "fmt" + "github.com/pion/interceptor" "io/ioutil" "net/http" "regexp" @@ -196,15 +197,25 @@ func (rtc *WebRTC) GetAnswer() ([]byte, error) { func run() { var m MediaEngine var s SettingEngine + //m.RegisterDefaultCodecs() + webrtc.RegisterCodecs(&m) + + i := &interceptor.Registry{} if len(config.PublicIP) > 0 { s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost) } if config.PortMin > 0 && config.PortMax > 0 { s.SetEphemeralUDPPortRange(config.PortMin, config.PortMax) } - // m.RegisterDefaultCodecs() - webrtc.RegisterCodecs(&m) - api = NewAPI(WithMediaEngine(&m), WithSettingEngine(s)) + if len(config.PublicIP) > 0 { + s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost) + } + s.SetNetworkTypes([]NetworkType{NetworkTypeUDP4, NetworkTypeUDP6}) + if err := RegisterDefaultInterceptors(&m, i); err != nil { + panic(err) + } + api := NewAPI(WithMediaEngine(&m), + WithInterceptorRegistry(i), WithSettingEngine(s)) http.HandleFunc("/api/webrtc/play", func(w http.ResponseWriter, r *http.Request) { utils.CORS(w, r) w.Header().Set("Content-Type", "application/json")