mirror of
https://github.com/jech/galene.git
synced 2024-12-25 08:45:48 +01:00
Implement -udp command-line flag.
This commit is contained in:
parent
6c752b58bc
commit
e02d100230
2 changed files with 36 additions and 0 deletions
|
@ -44,6 +44,8 @@ func main() {
|
|||
"store mutex profile in `file`")
|
||||
flag.StringVar(&udpRange, "udp-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(&ice.ICERelayOnly, "relay-only", false,
|
||||
"require use of TURN relays for all media traffic")
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -20,6 +21,10 @@ var Directory string
|
|||
var UseMDNS bool
|
||||
var UDPMin, UDPMax uint16
|
||||
|
||||
var UDPAddr string
|
||||
var udpListenerMu sync.Mutex
|
||||
var udpListener *net.UDPConn
|
||||
|
||||
var ErrNotAuthorised = errors.New("not authorised")
|
||||
|
||||
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) {
|
||||
s := webrtc.SettingEngine{}
|
||||
s.SetSRTPReplayProtectionWindow(512)
|
||||
|
@ -253,6 +279,14 @@ func APIFromCodecs(codecs []webrtc.RTPCodecCapability) (*webrtc.API, error) {
|
|||
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(
|
||||
webrtc.WithSettingEngine(s),
|
||||
webrtc.WithMediaEngine(&m),
|
||||
|
|
Loading…
Reference in a new issue