live users
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user