From ed862e997fcc9496a886a878d1e52c5c8791366e Mon Sep 17 00:00:00 2001 From: langhuihui <178529795@qq.com> Date: Sat, 14 Nov 2020 13:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AB=AF=E5=8F=A3=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index a12cf86..f162216 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,8 @@ import ( var config struct { ICEServers []string PublicIP []string + PortMin uint16 + PortMax uint16 } // }{[]string{ @@ -176,6 +178,9 @@ func (rtc *WebRTC) Publish(streamPath string) bool { if !strings.HasPrefix(rtc.RemoteAddr, "127.0.0.1") && !strings.HasPrefix(rtc.RemoteAddr, "[::1]") { rtc.s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost) } + if config.PortMin > 0 && config.PortMax > 0 { + rtc.s.SetEphemeralUDPPortRange(config.PortMin, config.PortMax) + } rtc.api = NewAPI(WithMediaEngine(rtc.m), WithSettingEngine(rtc.s)) peerConnection, err := rtc.api.NewPeerConnection(Configuration{ ICEServers: []ICEServer{ @@ -271,6 +276,7 @@ func run() { streamPath := r.URL.Query().Get("streamPath") var offer SessionDescription var rtc WebRTC + bytes, err := ioutil.ReadAll(r.Body) defer func() { if err != nil { @@ -305,6 +311,9 @@ func run() { if !strings.HasPrefix(r.RemoteAddr, "127.0.0.1") && !strings.HasPrefix(r.RemoteAddr, "[::1]") { rtc.s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost) } + if config.PortMin > 0 && config.PortMax > 0 { + rtc.s.SetEphemeralUDPPortRange(config.PortMin, config.PortMax) + } rtc.api = NewAPI(WithMediaEngine(rtc.m), WithSettingEngine(rtc.s)) peerConnection, err := rtc.api.NewPeerConnection(Configuration{ // ICEServers: []ICEServer{