feat(player): improve viewer counter

This commit is contained in:
2022-01-30 19:51:21 +08:00
parent b61f8b5b19
commit ac19787ee1
4 changed files with 11 additions and 2 deletions
+3
View File
@@ -0,0 +1,3 @@
server: main.go
go build -tags netgo -ldflags '-w -extldflags "-static"' -o server main.go
upx server
+1 -1
View File
@@ -3,5 +3,5 @@
A basic web player with automatic mirror selection and view counting. A basic web player with automatic mirror selection and view counting.
``` ```
go build -tags netgo -ldflags '-w -extldflags "-static"' -o server main.go make
``` ```
+5
View File
@@ -21,6 +21,11 @@ func main() {
// Get the remote address // Get the remote address
var ip = r.RemoteAddr var ip = r.RemoteAddr
// If behind a proxy, get the real IP
if fwd := r.Header.Get("X-Forwarded-For"); fwd != "" {
ip = fwd
}
// Update the last active time // Update the last active time
viewers[ip] = now viewers[ip] = now
+2 -1
View File
@@ -94,7 +94,8 @@
timeout: 1000, timeout: 1000,
mode: 'cors', mode: 'cors',
}); });
viewCount.innerText = await response.text(); const count = Number(await response.text());
viewCount.innerText = count;
await sleep(5000); await sleep(5000);
} }
}; };