add static html for stream page, m3u8 file sending
This commit is contained in:
parent
d39763a2e0
commit
223bbf40f7
2 changed files with 25 additions and 7 deletions
|
@ -2,7 +2,8 @@ package http
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"fmt"
|
||||
"strings"
|
||||
"os"
|
||||
)
|
||||
|
||||
func NewServer(port string) (error) {
|
||||
|
@ -15,13 +16,21 @@ func NewServer(port string) (error) {
|
|||
}
|
||||
|
||||
func server_setup(server *http.ServeMux) {
|
||||
server.HandleFunc("/", test)
|
||||
server.HandleFunc("/", serve_main_page)
|
||||
server.HandleFunc("/live/", serve_live_playlist)
|
||||
}
|
||||
|
||||
func test(w http.ResponseWriter, r *http.Request) {
|
||||
test_buf := make([]byte, 32)
|
||||
copy(test_buf, "test\ntest")
|
||||
if _, err := w.Write(test_buf); err != nil {
|
||||
fmt.Println(err)
|
||||
func serve_live_playlist(w http.ResponseWriter, r *http.Request) {
|
||||
stream_id := strings.TrimPrefix(r.URL.Path, "/live/")
|
||||
base_dir, _ := os.UserHomeDir()
|
||||
stream_playlist_path := base_dir + "/live/" + stream_id + "/stream.m3u8"
|
||||
if _, err := os.Stat(stream_playlist_path); err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
http.ServeFile(w, r, stream_playlist_path)
|
||||
}
|
||||
}
|
||||
|
||||
func serve_main_page(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "static/index.html")
|
||||
}
|
||||
|
|
9
static/index.html
Normal file
9
static/index.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue