Show viewer count and reconnect to websocket

This commit is contained in:
Gabe Kangas
2020-06-02 17:35:49 -07:00
parent 380dad2b87
commit f83fccfa89
5 changed files with 50 additions and 8 deletions

17
main.go
View File

@@ -11,6 +11,8 @@ import (
var ipfs icore.CoreAPI
var configuration = getConfig()
var server *Server
var online = false
func main() {
@@ -46,7 +48,7 @@ func startChatServer() {
// log.SetFlags(log.Lshortfile)
// websocket server
server := NewServer("/entry")
server = NewServer("/entry")
go server.Listen()
// static files
@@ -60,15 +62,12 @@ func startChatServer() {
func getStatus(w http.ResponseWriter, r *http.Request) {
status := Status{
Online: online,
Online: online,
ViewerCount: server.ClientCount(),
}
json.NewEncoder(w).Encode(status)
}
type Status struct {
Online bool `json:"online"`
}
func streamConnected() {
online = true
}
@@ -76,3 +75,9 @@ func streamConnected() {
func streamDisconnected() {
online = false
}
func viewerAdded() {
}
func viewerRemoved() {
}