mirror of https://github.com/jetkvm/kvm.git
Compare commits
1 Commits
4194c468d7
...
c54b931567
Author | SHA1 | Date |
---|---|---|
|
c54b931567 |
16
cloud.go
16
cloud.go
|
@ -7,14 +7,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/coder/websocket/wsjson"
|
"github.com/coder/websocket/wsjson"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
|
|
||||||
"github.com/coder/websocket"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/coder/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CloudRegisterRequest struct {
|
type CloudRegisterRequest struct {
|
||||||
|
@ -69,11 +68,6 @@ func handleCloudRegister(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.CloudToken == "" {
|
|
||||||
logger.Info("Starting websocket client due to adoption")
|
|
||||||
go RunWebsocketClient()
|
|
||||||
}
|
|
||||||
|
|
||||||
config.CloudToken = tokenResp.SecretToken
|
config.CloudToken = tokenResp.SecretToken
|
||||||
config.CloudURL = req.CloudAPI
|
config.CloudURL = req.CloudAPI
|
||||||
|
|
||||||
|
@ -193,11 +187,7 @@ 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(SessionConfig{
|
session, err := newSession()
|
||||||
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
|
||||||
|
|
4
main.go
4
main.go
|
@ -66,11 +66,7 @@ func Main() {
|
||||||
}()
|
}()
|
||||||
//go RunFuseServer()
|
//go RunFuseServer()
|
||||||
go RunWebServer()
|
go RunWebServer()
|
||||||
// If the cloud token isn't set, the client won't be started by default.
|
|
||||||
// However, if the user adopts the device via the web interface, handleCloudRegister will start the client.
|
|
||||||
if config.CloudToken != "" {
|
|
||||||
go RunWebsocketClient()
|
go RunWebsocketClient()
|
||||||
}
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-sigs
|
<-sigs
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/webrtc/v4/pkg/media"
|
"github.com/pion/webrtc/v4/pkg/media"
|
||||||
|
@ -225,12 +224,6 @@ func ExtractAndRunNativeBin() error {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
// Set the process group ID so we can kill the process and its children when this process exits
|
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
||||||
Setpgid: true,
|
|
||||||
Pdeathsig: syscall.SIGKILL,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the command
|
// Start the command
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return fmt.Errorf("failed to start binary: %w", err)
|
return fmt.Errorf("failed to start binary: %w", err)
|
||||||
|
|
|
@ -534,17 +534,17 @@ function UrlView({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Debian 12",
|
name: "Debian 12",
|
||||||
url: "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.9.0-amd64-netinst.iso",
|
url: "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.7.0-amd64-netinst.iso",
|
||||||
icon: DebianIcon,
|
icon: DebianIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Fedora 41",
|
name: "Fedora 38",
|
||||||
url: "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-41-1.4.iso",
|
url: "https://mirror.ihost.md/fedora/releases/38/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-38-1.6.iso",
|
||||||
icon: FedoraIcon,
|
icon: FedoraIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Arch Linux",
|
name: "Arch Linux",
|
||||||
url: "https://archlinux.doridian.net/iso/2025.02.01/archlinux-2025.02.01-x86_64.iso",
|
url: "https://archlinux.doridian.net/iso/2024.10.01/archlinux-2024.10.01-x86_64.iso",
|
||||||
icon: ArchIcon,
|
icon: ArchIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -425,7 +425,7 @@ export default function WebRTCVideo() {
|
||||||
disablePictureInPicture
|
disablePictureInPicture
|
||||||
controlsList="nofullscreen"
|
controlsList="nofullscreen"
|
||||||
className={cx(
|
className={cx(
|
||||||
"outline-50 max-h-full max-w-full object-contain transition-all duration-1000",
|
"outline-50 max-h-full max-w-full rounded-md object-contain transition-all duration-1000",
|
||||||
{
|
{
|
||||||
"cursor-none": settings.isCursorHidden,
|
"cursor-none": settings.isCursorHidden,
|
||||||
"opacity-0": isLoading || isConnectionError || hdmiError,
|
"opacity-0": isLoading || isConnectionError || hdmiError,
|
||||||
|
|
4
web.go
4
web.go
|
@ -19,8 +19,6 @@ var staticFiles embed.FS
|
||||||
type WebRTCSessionRequest struct {
|
type WebRTCSessionRequest struct {
|
||||||
Sd string `json:"sd"`
|
Sd string `json:"sd"`
|
||||||
OidcGoogle string `json:"OidcGoogle,omitempty"`
|
OidcGoogle string `json:"OidcGoogle,omitempty"`
|
||||||
IP string `json:"ip,omitempty"`
|
|
||||||
ICEServers []string `json:"iceServers,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetPasswordRequest struct {
|
type SetPasswordRequest struct {
|
||||||
|
@ -118,7 +116,7 @@ func handleWebRTCSession(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := newSession(SessionConfig{})
|
session, err := newSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err})
|
||||||
return
|
return
|
||||||
|
|
33
webrtc.go
33
webrtc.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pion/webrtc/v4"
|
"github.com/pion/webrtc/v4"
|
||||||
|
@ -20,12 +19,6 @@ 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 {
|
||||||
|
@ -68,29 +61,9 @@ func (s *Session) ExchangeOffer(offerStr string) (string, error) {
|
||||||
return base64.StdEncoding.EncodeToString(localDescription), nil
|
return base64.StdEncoding.EncodeToString(localDescription), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSession(config SessionConfig) (*Session, error) {
|
func newSession() (*Session, error) {
|
||||||
webrtcSettingEngine := webrtc.SettingEngine{}
|
peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{
|
||||||
iceServer := webrtc.ICEServer{}
|
ICEServers: []webrtc.ICEServer{{}},
|
||||||
|
|
||||||
if config.IsCloud {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
api := webrtc.NewAPI(webrtc.WithSettingEngine(webrtcSettingEngine))
|
|
||||||
peerConnection, err := api.NewPeerConnection(webrtc.Configuration{
|
|
||||||
ICEServers: []webrtc.ICEServer{iceServer},
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue