feat(player): log viewer counter

This commit is contained in:
2022-01-30 20:15:07 +08:00
parent ac19787ee1
commit 83125749d9
3 changed files with 29 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
test/
scripts/nginx/nginx/
player/server
*.log
+27
View File
@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"net/http"
"os"
"time"
)
@@ -50,6 +51,32 @@ func main() {
}
}()
// Periodically log the number of viewers
go func() {
// Prepare file to log to
var f, ferr = os.OpenFile("viewers.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if ferr != nil {
fmt.Println("Error opening file:", ferr)
fmt.Println("viewer count will not be logged")
return
}
// Loop forever
var last_count = 0
for {
var now = time.Now().Format(time.RFC3339)
var count = len(viewers)
// If the viewer count has changed, log it
if count != last_count {
fmt.Fprintf(f, "%s\t%d\n", now, count)
last_count = count
}
time.Sleep(time.Second)
}
}()
// Handle static files
http.Handle("/", http.FileServer(http.Dir("./static")))
+1 -1
View File
@@ -39,7 +39,7 @@
<body>
<header>
<h1><strong>Restream</strong> | Loading</h1>
<h1><strong>Restream</strong> | Ahoy!</h1>
<select id="mirror-select">
<option value="">Loading mirrors...</option>
</select>