feat(player): log viewer counter
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
test/
|
test/
|
||||||
scripts/nginx/nginx/
|
scripts/nginx/nginx/
|
||||||
player/server
|
player/server
|
||||||
|
*.log
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"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
|
// Handle static files
|
||||||
http.Handle("/", http.FileServer(http.Dir("./static")))
|
http.Handle("/", http.FileServer(http.Dir("./static")))
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1><strong>Restream</strong> | Loading</h1>
|
<h1><strong>Restream</strong> | Ahoy!</h1>
|
||||||
<select id="mirror-select">
|
<select id="mirror-select">
|
||||||
<option value="">Loading mirrors...</option>
|
<option value="">Loading mirrors...</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user