mirror of
https://github.com/krishpranav/remote-desktop.git
synced 2025-10-05 08:06:52 +08:00
frontend + main functionalities
This commit is contained in:
74
cmd/main.go
Normal file
74
cmd/main.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/krishpranav/remote-desktop/api"
|
||||
"github.com/krishpranav/remote-desktop/encoders"
|
||||
"github.com/krishpranav/remote-desktop/rdisplay"
|
||||
"github.com/krishpranav/remote-desktop/rtc"
|
||||
)
|
||||
|
||||
const (
|
||||
httpDefaultPort = "8080"
|
||||
defaultStunServer = "stun:stun.l.google.com:19302"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
httpPort := flag.String("http.port", httpDefaultPort, "HTTP listen port")
|
||||
stunServer := flag.String("stun.server", defaultStunServer, "STUN server URL (stun:)")
|
||||
flag.Parse()
|
||||
|
||||
var video rdisplay.Service
|
||||
video, err := rdisplay.NewVideoProvider()
|
||||
if err != nil {
|
||||
log.Fatalf("Can't init video: %v", err)
|
||||
}
|
||||
_, err = video.Screens()
|
||||
if err != nil {
|
||||
log.Fatalf("Can't get screens: %v", err)
|
||||
}
|
||||
|
||||
var enc encoders.Service = &encoders.EncoderService{}
|
||||
if err != nil {
|
||||
log.Fatalf("Can't create encoder service: %v", err)
|
||||
}
|
||||
|
||||
var webrtc rtc.Service
|
||||
webrtc = rtc.NewRemoteScreenService(*stunServer, video, enc)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/api/", http.StripPrefix("/api", api.MakeHandler(webrtc, video)))
|
||||
|
||||
mux.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("./frontend"))))
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, "./frontend/index.html")
|
||||
})
|
||||
|
||||
errors := make(chan error, 2)
|
||||
go func() {
|
||||
log.Printf("Starting signaling server on port %s", *httpPort)
|
||||
errors <- http.ListenAndServe(fmt.Sprintf(":%s", *httpPort), mux)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
interrupt := make(chan os.Signal)
|
||||
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
||||
errors <- fmt.Errorf("Received %v signal", <-interrupt)
|
||||
}()
|
||||
|
||||
err = <-errors
|
||||
log.Printf("%s, exiting.", err)
|
||||
}
|
Reference in New Issue
Block a user