feat: add tcp network type (to generate tcp type ice candidates)
parent
d7591684d7
commit
3fd41696a6
11
app.go
11
app.go
|
@ -23,7 +23,7 @@ type App struct {
|
||||||
src string
|
src string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, targetRoom string) {
|
func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, targetRoom string, iceTCPMUXListenPort uint) {
|
||||||
println("initializing ..")
|
println("initializing ..")
|
||||||
a.src = srcListenAddr
|
a.src = srcListenAddr
|
||||||
var iceServers []webrtc.ICEServer
|
var iceServers []webrtc.ICEServer
|
||||||
|
@ -37,10 +37,11 @@ func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a.conf = &models.ConfigModel{
|
a.conf = &models.ConfigModel{
|
||||||
LogjamBaseUrl: logjamBaseUrl + "/auxiliary-node",
|
LogjamBaseUrl: logjamBaseUrl + "/auxiliary-node",
|
||||||
TargetRoom: targetRoom,
|
TargetRoom: targetRoom,
|
||||||
ServiceAddress: svcAddr,
|
ServiceAddress: svcAddr,
|
||||||
ICEServers: iceServers,
|
ICEServers: iceServers,
|
||||||
|
ICETCPMUXListenPort: iceTCPMUXListenPort,
|
||||||
}
|
}
|
||||||
roomRepo := repositories.NewRoomRepository(a.conf)
|
roomRepo := repositories.NewRoomRepository(a.conf)
|
||||||
a.router = &routers.Router{}
|
a.router = &routers.Router{}
|
||||||
|
|
4
main.go
4
main.go
|
@ -10,7 +10,7 @@ func main() {
|
||||||
src := flag.String("src", ":8080", "listenHost:listenPort")
|
src := flag.String("src", ":8080", "listenHost:listenPort")
|
||||||
logjamBaseUrl := flag.String("logjam-base-url", "http://localhost:8090", "logjam base url( shouldn't end with / )")
|
logjamBaseUrl := flag.String("logjam-base-url", "http://localhost:8090", "logjam base url( shouldn't end with / )")
|
||||||
targetRoom := flag.String("targetRoom", "test", "target room")
|
targetRoom := flag.String("targetRoom", "test", "target room")
|
||||||
|
icetcpmuxListenPort := flag.Uint("ice-tcp-mux-listen-port", 4444, "listen port to use for tcp ice candidates")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if strings.HasSuffix(*logjamBaseUrl, "/") {
|
if strings.HasSuffix(*logjamBaseUrl, "/") {
|
||||||
|
@ -20,6 +20,6 @@ func main() {
|
||||||
panic("service address shouldn't end with /")
|
panic("service address shouldn't end with /")
|
||||||
}
|
}
|
||||||
app := App{}
|
app := App{}
|
||||||
app.Init(*src, *svcAddr, *logjamBaseUrl, *targetRoom)
|
app.Init(*src, *svcAddr, *logjamBaseUrl, *targetRoom, *icetcpmuxListenPort)
|
||||||
app.Run()
|
app.Run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ package models
|
||||||
import "github.com/pion/webrtc/v3"
|
import "github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
type ConfigModel struct {
|
type ConfigModel struct {
|
||||||
ServiceAddress string `json:"serviceAddress"`
|
ServiceAddress string `json:"serviceAddress"`
|
||||||
LogjamBaseUrl string `json:"logjamBaseUrl"`
|
LogjamBaseUrl string `json:"logjamBaseUrl"`
|
||||||
TargetRoom string `json:"targetRoom"`
|
TargetRoom string `json:"targetRoom"`
|
||||||
ICEServers []webrtc.ICEServer `json:"iceServers"`
|
ICETCPMUXListenPort uint `json:"ice_tcpmux_listenPort"`
|
||||||
|
ICEServers []webrtc.ICEServer `json:"iceServers"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pion/interceptor"
|
||||||
"github.com/pion/rtcp"
|
"github.com/pion/rtcp"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sourcecode.social/greatape/goldgorilla/models"
|
"sourcecode.social/greatape/goldgorilla/models"
|
||||||
"sourcecode.social/greatape/goldgorilla/models/dto"
|
"sourcecode.social/greatape/goldgorilla/models/dto"
|
||||||
|
@ -39,13 +41,47 @@ type Room struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoomRepository struct {
|
type RoomRepository struct {
|
||||||
|
api *webrtc.API
|
||||||
Rooms map[string]*Room
|
Rooms map[string]*Room
|
||||||
conf *models.ConfigModel
|
conf *models.ConfigModel
|
||||||
*sync.Mutex
|
*sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoomRepository(conf *models.ConfigModel) *RoomRepository {
|
func NewRoomRepository(conf *models.ConfigModel) *RoomRepository {
|
||||||
|
settingEngine := webrtc.SettingEngine{}
|
||||||
|
|
||||||
|
settingEngine.SetNetworkTypes([]webrtc.NetworkType{
|
||||||
|
webrtc.NetworkTypeTCP6,
|
||||||
|
webrtc.NetworkTypeUDP6,
|
||||||
|
webrtc.NetworkTypeTCP4,
|
||||||
|
webrtc.NetworkTypeUDP4,
|
||||||
|
})
|
||||||
|
tcpListener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||||
|
IP: net.IP{0, 0, 0, 0},
|
||||||
|
Port: int(conf.ICETCPMUXListenPort),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Listening for ICE TCP at %s\n", tcpListener.Addr())
|
||||||
|
|
||||||
|
tcpMux := webrtc.NewICETCPMux(nil, tcpListener, 64)
|
||||||
|
settingEngine.SetICETCPMux(tcpMux)
|
||||||
|
|
||||||
|
m := &webrtc.MediaEngine{}
|
||||||
|
if err := m.RegisterDefaultCodecs(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
i := &interceptor.Registry{}
|
||||||
|
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
api := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i), webrtc.WithSettingEngine(settingEngine))
|
||||||
|
|
||||||
return &RoomRepository{
|
return &RoomRepository{
|
||||||
|
api: api,
|
||||||
Mutex: &sync.Mutex{},
|
Mutex: &sync.Mutex{},
|
||||||
Rooms: make(map[string]*Room),
|
Rooms: make(map[string]*Room),
|
||||||
conf: conf,
|
conf: conf,
|
||||||
|
@ -118,7 +154,7 @@ func (r *RoomRepository) CreatePeer(roomId string, id uint64, canPublish bool, i
|
||||||
room := r.Rooms[roomId]
|
room := r.Rooms[roomId]
|
||||||
r.Unlock()
|
r.Unlock()
|
||||||
|
|
||||||
peerConn, err := webrtc.NewPeerConnection(webrtc.Configuration{
|
peerConn, err := r.api.NewPeerConnection(webrtc.Configuration{
|
||||||
ICEServers: r.conf.ICEServers,
|
ICEServers: r.conf.ICEServers,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -241,6 +277,7 @@ func (r *RoomRepository) onPeerConnectionStateChange(room *Room, peer *Peer, new
|
||||||
|
|
||||||
func (r *RoomRepository) onPeerTrack(roomId string, id uint64, remote *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
func (r *RoomRepository) onPeerTrack(roomId string, id uint64, remote *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
||||||
fmt.Println("got a track!", remote.ID(), remote.StreamID(), remote.Kind().String())
|
fmt.Println("got a track!", remote.ID(), remote.StreamID(), remote.Kind().String())
|
||||||
|
println("pc", id, "streamid", remote.StreamID())
|
||||||
r.Lock()
|
r.Lock()
|
||||||
if !r.doesRoomExists(roomId) {
|
if !r.doesRoomExists(roomId) {
|
||||||
r.Unlock()
|
r.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue