🔊 Verbose websocket connection logging

This commit is contained in:
2024-11-17 21:01:20 +08:00
parent ab9bc5d127
commit 90741379d6
2 changed files with 24 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package ws
import (
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"github.com/rs/zerolog/log"
"math/rand"
"sync"
@ -23,7 +24,12 @@ func ClientRegister(user sec.UserInfo, conn *websocket.Conn) uint64 {
wsConn[user.ID][clientId] = conn
wsMutex.Unlock()
directory.BroadcastEvent("ws.client.register", map[string]any{
log.Debug().
Uint64("client_id", clientId).
Uint("user_id", user.ID).
Msg("An client connected to stream endpoint...")
_ = directory.BroadcastEvent("ws.client.register", map[string]any{
"user": user.ID,
"id": clientId,
})
@ -39,6 +45,11 @@ func ClientUnregister(user sec.UserInfo, id uint64) {
delete(wsConn[user.ID], id)
wsMutex.Unlock()
log.Debug().
Uint64("client_id", id).
Uint("user_id", user.ID).
Msg("An client disconnected from stream endpoint...")
_ = directory.BroadcastEvent("ws.client.unregister", map[string]any{
"user": user.ID,
"id": id,