add static html for stream page, m3u8 file sending

This commit is contained in:
Muaz Ahmad 2023-08-21 13:02:06 +05:00
parent d39763a2e0
commit 223bbf40f7
2 changed files with 25 additions and 7 deletions

View file

@ -2,7 +2,8 @@ package http
import ( import (
"net/http" "net/http"
"fmt" "strings"
"os"
) )
func NewServer(port string) (error) { func NewServer(port string) (error) {
@ -15,13 +16,21 @@ func NewServer(port string) (error) {
} }
func server_setup(server *http.ServeMux) { 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) { func serve_live_playlist(w http.ResponseWriter, r *http.Request) {
test_buf := make([]byte, 32) stream_id := strings.TrimPrefix(r.URL.Path, "/live/")
copy(test_buf, "test\ntest") base_dir, _ := os.UserHomeDir()
if _, err := w.Write(test_buf); err != nil { stream_playlist_path := base_dir + "/live/" + stream_id + "/stream.m3u8"
fmt.Println(err) 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
View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>
</body>
</html>