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

Passive ICE TCP.

This commit is contained in:
Juliusz Chroboczek 2020-08-08 13:44:33 +02:00
parent 3083b89db9
commit 1ec0e7540a
2 changed files with 37 additions and 0 deletions

View file

@ -8,6 +8,7 @@ package group
import ( import (
"encoding/json" "encoding/json"
"log" "log"
"net"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -136,6 +137,18 @@ func (g *Group) API() *webrtc.API {
return groups.api return groups.api
} }
var tcpListener net.Listener
func StartTCPListener(addr *net.TCPAddr) error {
if tcpListener != nil {
tcpListener.Close()
tcpListener = nil
}
var err error
tcpListener, err = net.ListenTCP("tcp", addr)
return err
}
func Add(name string, desc *description) (*Group, error) { func Add(name string, desc *description) (*Group, error) {
groups.mu.Lock() groups.mu.Lock()
defer groups.mu.Unlock() defer groups.mu.Unlock()
@ -143,6 +156,16 @@ func Add(name string, desc *description) (*Group, error) {
if groups.groups == nil { if groups.groups == nil {
groups.groups = make(map[string]*Group) groups.groups = make(map[string]*Group)
s := webrtc.SettingEngine{} s := webrtc.SettingEngine{}
if tcpListener != nil {
mux := webrtc.NewICETCPMux(nil, tcpListener, 8)
s.SetICETCPMux(mux)
s.SetNetworkTypes([]webrtc.NetworkType{
webrtc.NetworkTypeUDP4,
webrtc.NetworkTypeUDP6,
webrtc.NetworkTypeTCP4,
webrtc.NetworkTypeTCP6,
})
}
m := webrtc.MediaEngine{} m := webrtc.MediaEngine{}
m.RegisterCodec(webrtc.NewRTPVP8CodecExt( m.RegisterCodec(webrtc.NewRTPVP8CodecExt(
webrtc.DefaultPayloadTypeVP8, 90000, webrtc.DefaultPayloadTypeVP8, 90000,

14
sfu.go
View file

@ -8,6 +8,7 @@ package main
import ( import (
"flag" "flag"
"log" "log"
"net"
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
@ -22,10 +23,14 @@ import (
func main() { func main() {
var cpuprofile, memprofile, mutexprofile, httpAddr, dataDir string var cpuprofile, memprofile, mutexprofile, httpAddr, dataDir string
var tcpPort int
flag.StringVar(&httpAddr, "http", ":8443", "web server `address`") flag.StringVar(&httpAddr, "http", ":8443", "web server `address`")
flag.StringVar(&webserver.StaticRoot, "static", "./static/", flag.StringVar(&webserver.StaticRoot, "static", "./static/",
"web server root `directory`") "web server root `directory`")
flag.IntVar(&tcpPort, "tcp-port", -1,
"TCP listener `port`. If 0, an ephemeral port is used.\n"+
"If -1, the TCP listerer is disabled")
flag.StringVar(&dataDir, "data", "./data/", flag.StringVar(&dataDir, "data", "./data/",
"data `directory`") "data `directory`")
flag.StringVar(&group.Directory, "groups", "./groups/", flag.StringVar(&group.Directory, "groups", "./groups/",
@ -80,6 +85,15 @@ func main() {
group.IceFilename = filepath.Join(dataDir, "ice-servers.json") group.IceFilename = filepath.Join(dataDir, "ice-servers.json")
if tcpPort >= 0 {
err := group.StartTCPListener(&net.TCPAddr{
Port: tcpPort,
})
if err != nil {
log.Fatalf("Couldn't start ICE TCP: %v", err)
}
}
go group.ReadPublicGroups() go group.ReadPublicGroups()
serverDone := make(chan struct{}) serverDone := make(chan struct{})