live users

This commit is contained in:
JurajKubrican
2025-08-04 20:05:08 +02:00
parent 70b0b70f65
commit c350501f29
5 changed files with 50 additions and 51 deletions

View File

@@ -12,7 +12,7 @@ import (
)
var (
wsConnections = make(map[*websocket.Conn]bool)
wsConnections = make(map[*websocket.Conn]string)
wsMutex sync.Mutex
)
@@ -161,11 +161,16 @@ func handleMessage(msg string, ws *websocket.Conn) error {
func InitWs(c echo.Context) error {
websocket.Handler(func(ws *websocket.Conn) {
wsMutex.Lock()
wsConnections[ws] = true
wsConnections[ws] = c.RealIP()
wsMutex.Unlock()
boxes := GetBoxes()
msg := ""
msg := "u:" + strconv.Itoa(len(wsConnections)) + ":"
for _, addr := range wsConnections {
msg += addr + ","
}
msg += "\n"
for _, box := range boxes {
msg += box.serialize()
}