Make viewers counter period configurable
This commit is contained in:
parent
12009b5875
commit
06542590e1
|
@ -35,6 +35,7 @@ web:
|
||||||
hostname: localhost
|
hostname: localhost
|
||||||
favicon: https://www.crans.org/images/favicon.ico
|
favicon: https://www.crans.org/images/favicon.ico
|
||||||
widgetURL: https://example.com/
|
widgetURL: https://example.com/
|
||||||
|
viewersCounterRefreshPeriod: 20000
|
||||||
|
|
||||||
# Configure WebRTC server
|
# Configure WebRTC server
|
||||||
webrtc:
|
webrtc:
|
||||||
|
|
1
main.go
1
main.go
|
@ -53,6 +53,7 @@ func loadConfiguration() {
|
||||||
viper.SetDefault("Web.Name", "Ghostream")
|
viper.SetDefault("Web.Name", "Ghostream")
|
||||||
viper.SetDefault("Web.Hostname", "localhost")
|
viper.SetDefault("Web.Hostname", "localhost")
|
||||||
viper.SetDefault("Web.Favicon", "/favicon.ico")
|
viper.SetDefault("Web.Favicon", "/favicon.ico")
|
||||||
|
viper.SetDefault("Web.ViewersCounterRefreshPeriod", 20000)
|
||||||
viper.SetDefault("WebRTC.MinPortUDP", 10000)
|
viper.SetDefault("WebRTC.MinPortUDP", 10000)
|
||||||
viper.SetDefault("WebRTC.MaxPortUDP", 10005)
|
viper.SetDefault("WebRTC.MaxPortUDP", 10005)
|
||||||
viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"})
|
viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"})
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
function refreshViewersCounter() {
|
// Refresh viewer count by pulling metric from server
|
||||||
|
function refreshViewersCounter(period) {
|
||||||
let xhr = new XMLHttpRequest()
|
let xhr = new XMLHttpRequest()
|
||||||
xhr.open("GET", "/_stats/", true)
|
xhr.open("GET", "/_stats/", true)
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
|
@ -12,7 +13,7 @@ function refreshViewersCounter() {
|
||||||
}
|
}
|
||||||
xhr.send()
|
xhr.send()
|
||||||
|
|
||||||
setTimeout(refreshViewersCounter, 20000)
|
setTimeout(() => {
|
||||||
|
refreshViewersCounter(period)
|
||||||
|
}, period)
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshViewersCounter()
|
|
||||||
|
|
|
@ -50,5 +50,10 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
]
|
]
|
||||||
startPeerConnection()
|
startPeerConnection()
|
||||||
|
|
||||||
|
// Wait a bit before pulling viewers counter for the first time
|
||||||
|
setTimeout(() => {
|
||||||
|
refreshViewersCounter({{.Cfg.ViewersCounterRefreshPeriod}})
|
||||||
|
}, 1000)
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
|
@ -20,6 +20,7 @@ type Options struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
Favicon string
|
Favicon string
|
||||||
WidgetURL string
|
WidgetURL string
|
||||||
|
ViewersCounterRefreshPeriod int
|
||||||
|
|
||||||
// Copied from WebRTC configuration
|
// Copied from WebRTC configuration
|
||||||
STUNServers []string
|
STUNServers []string
|
||||||
|
|
Loading…
Reference in New Issue