mirror of https://github.com/jetkvm/kvm.git
chore: remove local fallback ICE servers
This commit is contained in:
parent
92e0a06dee
commit
cef162ef7f
6
cloud.go
6
cloud.go
|
@ -188,7 +188,11 @@ func handleSessionRequest(ctx context.Context, c *websocket.Conn, req WebRTCSess
|
|||
return fmt.Errorf("google identity mismatch")
|
||||
}
|
||||
|
||||
session, err := newSession(req.ICEServers, req.IP)
|
||||
session, err := newSession(SessionConfig{
|
||||
ICEServers: req.ICEServers,
|
||||
LocalIP: req.IP,
|
||||
IsCloud: true,
|
||||
})
|
||||
if err != nil {
|
||||
_ = wsjson.Write(context.Background(), c, gin.H{"error": err})
|
||||
return err
|
||||
|
|
|
@ -22,7 +22,6 @@ type Config struct {
|
|||
LocalAuthToken string `json:"local_auth_token"`
|
||||
LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration
|
||||
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
|
||||
FallbackICEServers []string `json:"fallback_ice_servers"`
|
||||
}
|
||||
|
||||
const configPath = "/userdata/kvm_config.json"
|
||||
|
@ -30,11 +29,6 @@ const configPath = "/userdata/kvm_config.json"
|
|||
var defaultConfig = &Config{
|
||||
CloudURL: "https://api.jetkvm.com",
|
||||
AutoUpdateEnabled: true, // Set a default value
|
||||
FallbackICEServers: []string{
|
||||
"stun:stun.cloudflare.com:3478",
|
||||
"stun:stun.cloudflare.com:53",
|
||||
"stun:stun.l.google.com:19302",
|
||||
},
|
||||
}
|
||||
|
||||
var config *Config
|
||||
|
|
2
web.go
2
web.go
|
@ -118,7 +118,7 @@ func handleWebRTCSession(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
session, err := newSession(nil, "")
|
||||
session, err := newSession(SessionConfig{})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err})
|
||||
return
|
||||
|
|
34
webrtc.go
34
webrtc.go
|
@ -20,6 +20,12 @@ type Session struct {
|
|||
shouldUmountVirtualMedia bool
|
||||
}
|
||||
|
||||
type SessionConfig struct {
|
||||
ICEServers []string
|
||||
LocalIP string
|
||||
IsCloud bool
|
||||
}
|
||||
|
||||
func (s *Session) ExchangeOffer(offerStr string) (string, error) {
|
||||
b, err := base64.StdEncoding.DecodeString(offerStr)
|
||||
if err != nil {
|
||||
|
@ -62,23 +68,29 @@ func (s *Session) ExchangeOffer(offerStr string) (string, error) {
|
|||
return base64.StdEncoding.EncodeToString(localDescription), nil
|
||||
}
|
||||
|
||||
func newSession(iceServers []string, localIP string) (*Session, error) {
|
||||
if iceServers == nil {
|
||||
iceServers = config.FallbackICEServers
|
||||
fmt.Printf("ICE Servers not provided, using fallback %v\n", iceServers)
|
||||
}
|
||||
|
||||
func newSession(config SessionConfig) (*Session, error) {
|
||||
webrtcSettingEngine := webrtc.SettingEngine{}
|
||||
if localIP != "" || net.ParseIP(localIP) == nil {
|
||||
fmt.Printf("Local IP address not provided or invalid, won't set NAT1To1IPs\n")
|
||||
iceServer := webrtc.ICEServer{}
|
||||
|
||||
if config.IsCloud {
|
||||
if config.ICEServers == nil {
|
||||
fmt.Printf("ICE Servers not provided by cloud")
|
||||
} else {
|
||||
webrtcSettingEngine.SetNAT1To1IPs([]string{localIP}, webrtc.ICECandidateTypeSrflx)
|
||||
iceServer.URLs = config.ICEServers
|
||||
fmt.Printf("Using ICE Servers provided by cloud: %v\n", iceServer.URLs)
|
||||
}
|
||||
|
||||
if config.LocalIP == "" || net.ParseIP(config.LocalIP) == nil {
|
||||
fmt.Printf("Local IP address %v not provided or invalid, won't set NAT1To1IPs\n", config.LocalIP)
|
||||
} else {
|
||||
webrtcSettingEngine.SetNAT1To1IPs([]string{config.LocalIP}, webrtc.ICECandidateTypeSrflx)
|
||||
fmt.Printf("Setting NAT1To1IPs to %s\n", config.LocalIP)
|
||||
}
|
||||
}
|
||||
|
||||
// create
|
||||
api := webrtc.NewAPI(webrtc.WithSettingEngine(webrtcSettingEngine))
|
||||
peerConnection, err := api.NewPeerConnection(webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{{URLs: iceServers}},
|
||||
ICEServers: []webrtc.ICEServer{iceServer},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue