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")
|
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 {
|
if err != nil {
|
||||||
_ = wsjson.Write(context.Background(), c, gin.H{"error": err})
|
_ = wsjson.Write(context.Background(), c, gin.H{"error": err})
|
||||||
return err
|
return err
|
||||||
|
|
26
config.go
26
config.go
|
@ -12,17 +12,16 @@ type WakeOnLanDevice struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CloudURL string `json:"cloud_url"`
|
CloudURL string `json:"cloud_url"`
|
||||||
CloudToken string `json:"cloud_token"`
|
CloudToken string `json:"cloud_token"`
|
||||||
GoogleIdentity string `json:"google_identity"`
|
GoogleIdentity string `json:"google_identity"`
|
||||||
JigglerEnabled bool `json:"jiggler_enabled"`
|
JigglerEnabled bool `json:"jiggler_enabled"`
|
||||||
AutoUpdateEnabled bool `json:"auto_update_enabled"`
|
AutoUpdateEnabled bool `json:"auto_update_enabled"`
|
||||||
IncludePreRelease bool `json:"include_pre_release"`
|
IncludePreRelease bool `json:"include_pre_release"`
|
||||||
HashedPassword string `json:"hashed_password"`
|
HashedPassword string `json:"hashed_password"`
|
||||||
LocalAuthToken string `json:"local_auth_token"`
|
LocalAuthToken string `json:"local_auth_token"`
|
||||||
LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration
|
LocalAuthMode string `json:"localAuthMode"` //TODO: fix it with migration
|
||||||
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
|
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
|
||||||
FallbackICEServers []string `json:"fallback_ice_servers"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const configPath = "/userdata/kvm_config.json"
|
const configPath = "/userdata/kvm_config.json"
|
||||||
|
@ -30,11 +29,6 @@ const configPath = "/userdata/kvm_config.json"
|
||||||
var defaultConfig = &Config{
|
var defaultConfig = &Config{
|
||||||
CloudURL: "https://api.jetkvm.com",
|
CloudURL: "https://api.jetkvm.com",
|
||||||
AutoUpdateEnabled: true, // Set a default value
|
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
|
var config *Config
|
||||||
|
|
2
web.go
2
web.go
|
@ -118,7 +118,7 @@ func handleWebRTCSession(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := newSession(nil, "")
|
session, err := newSession(SessionConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err})
|
||||||
return
|
return
|
||||||
|
|
36
webrtc.go
36
webrtc.go
|
@ -20,6 +20,12 @@ type Session struct {
|
||||||
shouldUmountVirtualMedia bool
|
shouldUmountVirtualMedia bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SessionConfig struct {
|
||||||
|
ICEServers []string
|
||||||
|
LocalIP string
|
||||||
|
IsCloud bool
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) ExchangeOffer(offerStr string) (string, error) {
|
func (s *Session) ExchangeOffer(offerStr string) (string, error) {
|
||||||
b, err := base64.StdEncoding.DecodeString(offerStr)
|
b, err := base64.StdEncoding.DecodeString(offerStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -62,23 +68,29 @@ func (s *Session) ExchangeOffer(offerStr string) (string, error) {
|
||||||
return base64.StdEncoding.EncodeToString(localDescription), nil
|
return base64.StdEncoding.EncodeToString(localDescription), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSession(iceServers []string, localIP string) (*Session, error) {
|
func newSession(config SessionConfig) (*Session, error) {
|
||||||
if iceServers == nil {
|
|
||||||
iceServers = config.FallbackICEServers
|
|
||||||
fmt.Printf("ICE Servers not provided, using fallback %v\n", iceServers)
|
|
||||||
}
|
|
||||||
|
|
||||||
webrtcSettingEngine := webrtc.SettingEngine{}
|
webrtcSettingEngine := webrtc.SettingEngine{}
|
||||||
if localIP != "" || net.ParseIP(localIP) == nil {
|
iceServer := webrtc.ICEServer{}
|
||||||
fmt.Printf("Local IP address not provided or invalid, won't set NAT1To1IPs\n")
|
|
||||||
} else {
|
if config.IsCloud {
|
||||||
webrtcSettingEngine.SetNAT1To1IPs([]string{localIP}, webrtc.ICECandidateTypeSrflx)
|
if config.ICEServers == nil {
|
||||||
|
fmt.Printf("ICE Servers not provided by cloud")
|
||||||
|
} else {
|
||||||
|
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))
|
api := webrtc.NewAPI(webrtc.WithSettingEngine(webrtcSettingEngine))
|
||||||
peerConnection, err := api.NewPeerConnection(webrtc.Configuration{
|
peerConnection, err := api.NewPeerConnection(webrtc.Configuration{
|
||||||
ICEServers: []webrtc.ICEServer{{URLs: iceServers}},
|
ICEServers: []webrtc.ICEServer{iceServer},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue