added argument to set custom ICE Host Candidate IP

pull/1/head
Benyamin Azarkhazin 2023-09-21 18:07:05 +03:30
parent 3fd41696a6
commit e85a01b809
Signed by: benyamin
GPG Key ID: 3AE44F5623C70269
5 changed files with 19 additions and 15 deletions

13
app.go
View File

@ -23,7 +23,7 @@ type App struct {
src string src string
} }
func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, targetRoom string, iceTCPMUXListenPort uint) { func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, targetRoom string, iceTCPMUXListenPort uint, customICEHostCandidateIP string) {
println("initializing ..") println("initializing ..")
a.src = srcListenAddr a.src = srcListenAddr
var iceServers []webrtc.ICEServer var iceServers []webrtc.ICEServer
@ -37,11 +37,12 @@ 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, ICETCPMUXListenPort: iceTCPMUXListenPort,
CustomICEHostCandidateIP: customICEHostCandidateIP,
} }
roomRepo := repositories.NewRoomRepository(a.conf) roomRepo := repositories.NewRoomRepository(a.conf)
a.router = &routers.Router{} a.router = &routers.Router{}

2
go.mod
View File

@ -4,6 +4,7 @@ go 1.20
require ( require (
github.com/gin-gonic/gin v1.9.1 github.com/gin-gonic/gin v1.9.1
github.com/pion/interceptor v0.1.17
github.com/pion/rtcp v1.2.10 github.com/pion/rtcp v1.2.10
github.com/pion/webrtc/v3 v3.2.12 github.com/pion/webrtc/v3 v3.2.12
) )
@ -29,7 +30,6 @@ require (
github.com/pion/datachannel v1.5.5 // indirect github.com/pion/datachannel v1.5.5 // indirect
github.com/pion/dtls/v2 v2.2.7 // indirect github.com/pion/dtls/v2 v2.2.7 // indirect
github.com/pion/ice/v2 v2.3.9 // indirect github.com/pion/ice/v2 v2.3.9 // indirect
github.com/pion/interceptor v0.1.17 // indirect
github.com/pion/logging v0.2.2 // indirect github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.7 // indirect github.com/pion/mdns v0.0.7 // indirect
github.com/pion/randutil v0.1.0 // indirect github.com/pion/randutil v0.1.0 // indirect

View File

@ -11,6 +11,7 @@ func main() {
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") icetcpmuxListenPort := flag.Uint("ice-tcp-mux-listen-port", 4444, "listen port to use for tcp ice candidates")
customICEHostCandidateIP := flag.String("custom-ice-host-candidate-ip", "", "set to override host ice candidates address")
flag.Parse() flag.Parse()
if strings.HasSuffix(*logjamBaseUrl, "/") { if strings.HasSuffix(*logjamBaseUrl, "/") {
@ -20,6 +21,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, *icetcpmuxListenPort) app.Init(*src, *svcAddr, *logjamBaseUrl, *targetRoom, *icetcpmuxListenPort, *customICEHostCandidateIP)
app.Run() app.Run()
} }

View File

@ -3,9 +3,10 @@ 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"`
ICETCPMUXListenPort uint `json:"ice_tcpmux_listenPort"` ICETCPMUXListenPort uint `json:"ice_tcpmux_listenPort"`
ICEServers []webrtc.ICEServer `json:"iceServers"` CustomICEHostCandidateIP string `json:"customICEHostCandidateIP"`
ICEServers []webrtc.ICEServer `json:"iceServers"`
} }

View File

@ -49,7 +49,9 @@ type RoomRepository struct {
func NewRoomRepository(conf *models.ConfigModel) *RoomRepository { func NewRoomRepository(conf *models.ConfigModel) *RoomRepository {
settingEngine := webrtc.SettingEngine{} settingEngine := webrtc.SettingEngine{}
if len(conf.CustomICEHostCandidateIP) > 0 {
settingEngine.SetNAT1To1IPs([]string{conf.CustomICEHostCandidateIP}, webrtc.ICECandidateTypeHost)
}
settingEngine.SetNetworkTypes([]webrtc.NetworkType{ settingEngine.SetNetworkTypes([]webrtc.NetworkType{
webrtc.NetworkTypeTCP6, webrtc.NetworkTypeTCP6,
webrtc.NetworkTypeUDP6, webrtc.NetworkTypeUDP6,
@ -277,7 +279,6 @@ 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()