1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-23 00:55:58 +01:00

Implement -udp command-line flag.

This commit is contained in:
Juliusz Chroboczek 2021-04-29 20:51:44 +02:00
parent 6c752b58bc
commit e02d100230
2 changed files with 36 additions and 0 deletions

View file

@ -44,6 +44,8 @@ func main() {
"store mutex profile in `file`") "store mutex profile in `file`")
flag.StringVar(&udpRange, "udp-range", "", flag.StringVar(&udpRange, "udp-range", "",
"UDP port `range`") "UDP port `range`")
flag.StringVar(&group.UDPAddr, "udp", "",
"UDP `address:port` (default dynamic)")
flag.BoolVar(&group.UseMDNS, "mdns", false, "gather mDNS addresses") flag.BoolVar(&group.UseMDNS, "mdns", false, "gather mDNS addresses")
flag.BoolVar(&ice.ICERelayOnly, "relay-only", false, flag.BoolVar(&ice.ICERelayOnly, "relay-only", false,
"require use of TURN relays for all media traffic") "require use of TURN relays for all media traffic")

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"log" "log"
"net"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -20,6 +21,10 @@ var Directory string
var UseMDNS bool var UseMDNS bool
var UDPMin, UDPMax uint16 var UDPMin, UDPMax uint16
var UDPAddr string
var udpListenerMu sync.Mutex
var udpListener *net.UDPConn
var ErrNotAuthorised = errors.New("not authorised") var ErrNotAuthorised = errors.New("not authorised")
type UserError string type UserError string
@ -199,6 +204,27 @@ func payloadType(codec webrtc.RTPCodecCapability) (webrtc.PayloadType, error) {
} }
} }
func getUDPListener() (*net.UDPConn, error) {
if UDPAddr == "" {
return nil, nil
}
udpListenerMu.Lock()
defer udpListenerMu.Unlock()
if udpListener == nil {
addr, err := net.ResolveUDPAddr("udp", UDPAddr)
if err != nil {
return nil, err
}
udpListener, err = net.ListenUDP("udp", addr)
if err != nil {
udpListener = nil
return nil, err
}
}
return udpListener, nil
}
func APIFromCodecs(codecs []webrtc.RTPCodecCapability) (*webrtc.API, error) { func APIFromCodecs(codecs []webrtc.RTPCodecCapability) (*webrtc.API, error) {
s := webrtc.SettingEngine{} s := webrtc.SettingEngine{}
s.SetSRTPReplayProtectionWindow(512) s.SetSRTPReplayProtectionWindow(512)
@ -253,6 +279,14 @@ func APIFromCodecs(codecs []webrtc.RTPCodecCapability) (*webrtc.API, error) {
s.SetEphemeralUDPPortRange(UDPMin, UDPMax) s.SetEphemeralUDPPortRange(UDPMin, UDPMax)
} }
listener, err := getUDPListener()
if err != nil {
return nil, err
}
if listener != nil {
s.SetICEUDPMux(webrtc.NewICEUDPMux(nil, listener))
}
return webrtc.NewAPI( return webrtc.NewAPI(
webrtc.WithSettingEngine(s), webrtc.WithSettingEngine(s),
webrtc.WithMediaEngine(&m), webrtc.WithMediaEngine(&m),