diff --git a/.gitignore b/.gitignore index c266524..5b17c64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ test/ scripts/nginx/nginx/ player/server +*.log diff --git a/player/main.go b/player/main.go index 6dccdd1..60d0d83 100644 --- a/player/main.go +++ b/player/main.go @@ -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"))) diff --git a/player/static/index.html b/player/static/index.html index f82ed91..7a45d68 100644 --- a/player/static/index.html +++ b/player/static/index.html @@ -39,7 +39,7 @@