mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-06 00:37:00 +08:00
Adds static www content to binary
This commit is contained in:
@@ -22,7 +22,6 @@ func Init() {
|
|||||||
|
|
||||||
// default config
|
// default config
|
||||||
cfg.Mod.Listen = ":1984"
|
cfg.Mod.Listen = ":1984"
|
||||||
cfg.Mod.StaticDir = "www"
|
|
||||||
|
|
||||||
// load config from YAML
|
// load config from YAML
|
||||||
app.LoadConfig(&cfg)
|
app.LoadConfig(&cfg)
|
||||||
@@ -34,10 +33,7 @@ func Init() {
|
|||||||
basePath = cfg.Mod.BasePath
|
basePath = cfg.Mod.BasePath
|
||||||
log = app.GetLogger("api")
|
log = app.GetLogger("api")
|
||||||
|
|
||||||
if cfg.Mod.StaticDir != "" {
|
initStatic(cfg.Mod.StaticDir)
|
||||||
fileServer = http.FileServer(http.Dir(cfg.Mod.StaticDir))
|
|
||||||
HandleFunc("/", fileServerHandlder)
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleFunc("/api/frame.mp4", frameHandler)
|
HandleFunc("/api/frame.mp4", frameHandler)
|
||||||
HandleFunc("/api/frame.raw", frameHandler)
|
HandleFunc("/api/frame.raw", frameHandler)
|
||||||
@@ -70,17 +66,9 @@ func HandleWS(msgType string, handler WSHandler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var basePath string
|
var basePath string
|
||||||
var fileServer http.Handler
|
|
||||||
var log zerolog.Logger
|
var log zerolog.Logger
|
||||||
var wsHandlers = make(map[string]WSHandler)
|
var wsHandlers = make(map[string]WSHandler)
|
||||||
|
|
||||||
func fileServerHandlder(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if basePath != "" {
|
|
||||||
r.URL.Path = r.URL.Path[len(basePath):]
|
|
||||||
}
|
|
||||||
fileServer.ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func statsHandler(w http.ResponseWriter, _ *http.Request) {
|
func statsHandler(w http.ResponseWriter, _ *http.Request) {
|
||||||
v := map[string]interface{}{
|
v := map[string]interface{}{
|
||||||
"streams": streams.All(),
|
"streams": streams.All(),
|
||||||
|
25
cmd/api/static.go
Normal file
25
cmd/api/static.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/AlexxIT/go2rtc/www"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initStatic(staticDir string) {
|
||||||
|
var root http.FileSystem
|
||||||
|
if staticDir != "" {
|
||||||
|
root = http.Dir(staticDir)
|
||||||
|
} else {
|
||||||
|
root = http.FS(www.Static)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileServer := http.FileServer(root)
|
||||||
|
|
||||||
|
HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if basePath != "" {
|
||||||
|
r.URL.Path = r.URL.Path[len(basePath):]
|
||||||
|
}
|
||||||
|
|
||||||
|
fileServer.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
@@ -15,8 +15,7 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
const header = document.getElementById('header');
|
const header = document.getElementById('header');
|
||||||
header.innerHTML = `<a href="api/stats">stats</a>` +
|
header.innerHTML = `<a href="api/stats">stats</a>`;
|
||||||
`<a href="webcam.html?url=webcam">webcam</a>`;
|
|
||||||
|
|
||||||
const links = [
|
const links = [
|
||||||
'<a href="webrtc-async.html?url={name}">webrtc-async</a>',
|
'<a href="webrtc-async.html?url={name}">webrtc-async</a>',
|
||||||
|
6
www/static.go
Normal file
6
www/static.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package www
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed *.html
|
||||||
|
var Static embed.FS
|
@@ -21,11 +21,8 @@
|
|||||||
background: black;
|
background: black;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<!-- Fix bugs for example with Safari... -->
|
|
||||||
<!-- <script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>-->
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- muted is important for autoplay -->
|
|
||||||
<video id="video" autoplay controls playsinline muted></video>
|
<video id="video" autoplay controls playsinline muted></video>
|
||||||
<script>
|
<script>
|
||||||
function init(stream) {
|
function init(stream) {
|
||||||
@@ -38,11 +35,7 @@
|
|||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
console.debug('ws.onopen');
|
console.debug('ws.onopen');
|
||||||
|
|
||||||
pc.createOffer({
|
pc.createOffer().then(offer => {
|
||||||
// this is adds two media to SDP with recvonly direction
|
|
||||||
// offerToReceiveAudio: true,
|
|
||||||
// offerToReceiveVideo: true,
|
|
||||||
}).then(offer => {
|
|
||||||
pc.setLocalDescription(offer).then(() => {
|
pc.setLocalDescription(offer).then(() => {
|
||||||
console.log(offer.sdp);
|
console.log(offer.sdp);
|
||||||
const msg = {type: 'webrtc/offer', value: pc.localDescription.sdp};
|
const msg = {type: 'webrtc/offer', value: pc.localDescription.sdp};
|
||||||
|
Reference in New Issue
Block a user