Changeset 0.11.0 (#62)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user