Changeset 0.11.0 (#62)

This commit is contained in:
2026-02-25 13:29:15 +00:00
parent d2ec55b16d
commit c9d8e9457e
56 changed files with 5664 additions and 91 deletions

View File

@@ -118,6 +118,42 @@ func (h *Hub) ConnsByUser(userID string) []*Conn {
return result
}
// IsConnected returns true if the user has at least one active WebSocket.
func (h *Hub) IsConnected(userID string) bool {
h.mu.RLock()
defer h.mu.RUnlock()
for _, c := range h.conns {
if c.userID == userID {
return true
}
}
return false
}
// SendToUser sends an event directly to all WebSocket connections for a user,
// bypassing room filtering. Used for targeted tool.call delivery.
func (h *Hub) SendToUser(userID string, event Event) {
data, err := json.Marshal(event)
if err != nil {
return
}
h.mu.RLock()
defer h.mu.RUnlock()
for _, c := range h.conns {
if c.userID == userID {
select {
case c.send <- data:
default:
}
}
}
}
// GetBus returns the underlying event bus.
func (h *Hub) GetBus() *Bus {
return h.bus
}
// removeConn cleans up a connection.
func (h *Hub) removeConn(conn *Conn) {
h.mu.Lock()