-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (58 loc) · 1.5 KB
/
Copy pathmain.go
File metadata and controls
69 lines (58 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"embed"
"fmt"
"github.com/gin-gonic/gin"
"github.com/polynds/RemoteControl/device"
"github.com/polynds/RemoteControl/ip"
"github.com/polynds/RemoteControl/qrcode"
"github.com/polynds/RemoteControl/ws"
"html/template"
"io/fs"
"net/http"
)
// 使用 go:embed 注解,将文件内容嵌入到程序中
//
//go:embed templates/*
var templates embed.FS
func main() {
r := gin.Default()
temp := template.Must(template.New("").ParseFS(templates, "templates/*.html"))
r.SetHTMLTemplate(temp)
fe, _ := fs.Sub(templates, "templates")
r.StaticFS("/templates", http.FS(fe))
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "home.html", nil)
})
startCapture := make(chan bool)
hub := ws.NewHub()
go hub.Run()
r.GET("/ws", func(c *gin.Context) {
ws.WsClient(hub, c.Writer, c.Request, startCapture)
})
r.GET("/stream", func(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "image/png")
// 设置刷新响应的间隔时间
flusher, ok := c.Writer.(http.Flusher)
if !ok {
http.Error(c.Writer, "Streaming not supported", http.StatusInternalServerError)
return
}
flusher.Flush()
go device.PushFlow(c.Writer, startCapture)
})
//sp := device.NewScreenshot(startCapture)
//go sp.StartCapture()
port := ":9021"
fmt.Println("http://127.0.0.1" + port)
if ip, err := ip.ClientIp(); err == nil {
url := "http://" + ip + port
fmt.Println(url)
qr := qrcode.NewQRCode2ConsoleWithUrl(url, true)
qr.Output()
}
err := r.Run(port)
if err != nil {
return
}
}