mirror of
https://github.com/Monibuca/plugin-webrtc.git
synced 2025-10-05 06:46:57 +08:00
增加端口范围配置
This commit is contained in:
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{
|
||||
|
Reference in New Issue
Block a user