feat(player): improve viewer counter
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
server: main.go
|
||||
go build -tags netgo -ldflags '-w -extldflags "-static"' -o server main.go
|
||||
upx server
|
||||
+1
-1
@@ -3,5 +3,5 @@
|
||||
A basic web player with automatic mirror selection and view counting.
|
||||
|
||||
```
|
||||
go build -tags netgo -ldflags '-w -extldflags "-static"' -o server main.go
|
||||
make
|
||||
```
|
||||
|
||||
@@ -21,6 +21,11 @@ func main() {
|
||||
// Get the remote address
|
||||
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
|
||||
viewers[ip] = now
|
||||
|
||||
|
||||
@@ -94,7 +94,8 @@
|
||||
timeout: 1000,
|
||||
mode: 'cors',
|
||||
});
|
||||
viewCount.innerText = await response.text();
|
||||
const count = Number(await response.text());
|
||||
viewCount.innerText = count;
|
||||
await sleep(5000);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user