mirror of
https://github.com/pion/webrtc.git
synced 2025-10-18 13:10:47 +08:00
Add an engine for global webrtc settings
* hook up UDP limitation to it. This was Michiel De Backker's suggestion relates to #281
This commit is contained in:

committed by
Michiel De Backker

parent
a6df5427f7
commit
a2819a1b93
@@ -91,11 +91,15 @@ func (a *Agent) getErr() error {
|
||||
return ErrClosed
|
||||
}
|
||||
|
||||
// AgentConfig collects the arguements to ice.Agent construction into
|
||||
// a single structure, for future-proofness of the interface
|
||||
type AgentConfig struct {
|
||||
Urls []*URL
|
||||
Notifier func(ConnectionState)
|
||||
PortMin uint16
|
||||
PortMax uint16
|
||||
|
||||
// PortMin and PortMax are optional. Leave them 0 for the default UDP port allocation strategy.
|
||||
PortMin uint16
|
||||
PortMax uint16
|
||||
}
|
||||
|
||||
// NewAgent creates a new Agent
|
||||
|
@@ -44,11 +44,6 @@ type RTCConfiguration struct {
|
||||
|
||||
// IceCandidatePoolSize describes the size of the prefetched ICE pool.
|
||||
IceCandidatePoolSize uint8
|
||||
|
||||
// MinLocalPort and MaxLocalPort, if nonzero, set limits to local ephemeral
|
||||
// UDP ports that are allocated by the ICE agent.
|
||||
MinLocalPort uint16
|
||||
MaxLocalPort uint16
|
||||
}
|
||||
|
||||
func (c RTCConfiguration) getIceServers() (*[]*ice.URL, error) {
|
||||
|
@@ -158,7 +158,7 @@ func New(configuration RTCConfiguration) (*RTCPeerConnection, error) {
|
||||
}
|
||||
}
|
||||
|
||||
pc.networkManager, err = network.NewManager(urls, pc.generateChannel, pc.iceStateChange, configuration.MinLocalPort, configuration.MaxLocalPort)
|
||||
pc.networkManager, err = network.NewManager(urls, pc.generateChannel, pc.iceStateChange, defaultSettingEngine.EphemeralUDP.PortMin, defaultSettingEngine.EphemeralUDP.PortMax)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
28
settingengine.go
Normal file
28
settingengine.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package webrtc
|
||||
|
||||
import "github.com/pions/webrtc/pkg/ice"
|
||||
|
||||
var defaultSettingEngine = newSettingEngine()
|
||||
|
||||
type settingEngine struct {
|
||||
EphemeralUDP struct {
|
||||
PortMin uint16
|
||||
PortMax uint16
|
||||
}
|
||||
}
|
||||
|
||||
// SetEphemeralUDPPortRange limits the pool of ephemeral ports that
|
||||
// ICE UDP connections can allocate from
|
||||
func SetEphemeralUDPPortRange(portMin, portMax uint16) error {
|
||||
if portMax < portMin {
|
||||
return ice.ErrPort
|
||||
}
|
||||
|
||||
defaultSettingEngine.EphemeralUDP.PortMin = portMin
|
||||
defaultSettingEngine.EphemeralUDP.PortMax = portMax
|
||||
return nil
|
||||
}
|
||||
|
||||
func newSettingEngine() *settingEngine {
|
||||
return new(settingEngine)
|
||||
}
|
Reference in New Issue
Block a user