Browse Source

增加端口范围配置

v4
langhuihui 4 years ago
parent
commit
ed862e997f
  1. 9
      main.go

9
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{

Loading…
Cancel
Save