diff --git a/handler.go b/handler.go index 0b2572034..6aad7f0ef 100644 --- a/handler.go +++ b/handler.go @@ -38,7 +38,6 @@ func (h *Handler) OnCreateStream(timestamp uint32, cmd *rtmpmsg.NetConnectionCre func (h *Handler) OnPublish(timestamp uint32, cmd *rtmpmsg.NetStreamPublish) error { // log.Printf("OnPublish: %#v", cmd) - log.Println("Incoming stream connected.") if cmd.PublishingName != configuration.VideoSettings.StreamingKey { @@ -68,6 +67,8 @@ func (h *Handler) OnPublish(timestamp uint32, cmd *rtmpmsg.NetStreamPublish) err go startFfmpeg(configuration) + streamConnected() + return nil } @@ -164,4 +165,6 @@ func (h *Handler) OnClose() { if h.flvFile != nil { _ = h.flvFile.Close() } + + streamDisconnected() } diff --git a/main.go b/main.go index bc2b5a93e..b6deef331 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" "strconv" @@ -10,6 +11,7 @@ import ( var ipfs icore.CoreAPI var configuration = getConfig() +var online = false func main() { checkConfig(configuration) @@ -49,8 +51,28 @@ func startChatServer() { // static files http.Handle("/", http.FileServer(http.Dir("webroot"))) + http.HandleFunc("/status", getStatus) log.Printf("Starting public web server on port %d", configuration.WebServerPort) log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil)) } + +func getStatus(w http.ResponseWriter, r *http.Request) { + status := Status{ + Online: online, + } + json.NewEncoder(w).Encode(status) +} + +type Status struct { + Online bool `json:"online"` +} + +func streamConnected() { + online = true +} + +func streamDisconnected() { + online = false +} diff --git a/webroot/index.html b/webroot/index.html index 6f479e7fb..a6710cfb8 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -6,6 +6,7 @@ href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" /> + @@ -15,73 +16,78 @@ -