Documentation
¶
Index ¶
- func NewConnection(id, userID, tenantID, orgID string, parentCtx context.Context) *conn
- type Connection
- type Manager
- func (m *Manager) Deregister(id string)
- func (m *Manager) Get(id string) Connection
- func (m *Manager) GetAll() []Connection
- func (m *Manager) GetByTenant(tenantID string) []Connection
- func (m *Manager) GetByUser(userID string) []Connection
- func (m *Manager) Register(c *conn) bool
- func (m *Manager) SetPresenceListener(l PresenceListener)
- func (m *Manager) TenantConnectionCount(tenantID string) int
- func (m *Manager) Total() int64
- func (m *Manager) UserConnectionCount(userID string) int
- type Pool
- type PresenceListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConnection ¶
NewConnection creates a new connection. The caller must set WriteFn and then call StartWriter before using Send.
Types ¶
type Connection ¶
type Connection interface {
ID() string
UserID() string
TenantID() string
OrgID() string
Send(msg *protocol.ServerMessage) bool
Close()
Context() context.Context
}
Connection represents an active WebSocket connection.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager tracks all active WebSocket connections using a sharded map for high-concurrency access.
func NewManager ¶
NewManager creates a connection manager with the given max connections limit.
func (*Manager) Deregister ¶
Deregister removes a connection.
func (*Manager) Get ¶
func (m *Manager) Get(id string) Connection
Get returns a connection by ID, or nil.
func (*Manager) GetAll ¶
func (m *Manager) GetAll() []Connection
GetAll returns all active connections. Use sparingly — iterates all shards.
func (*Manager) GetByTenant ¶
func (m *Manager) GetByTenant(tenantID string) []Connection
GetByTenant returns all connections for a given tenant ID.
func (*Manager) GetByUser ¶
func (m *Manager) GetByUser(userID string) []Connection
GetByUser returns all connections for a given user ID.
func (*Manager) Register ¶
Register adds a connection. Returns false if the max connections limit has been reached.
func (*Manager) SetPresenceListener ¶
func (m *Manager) SetPresenceListener(l PresenceListener)
SetPresenceListener registers a listener notified on user presence transitions (0->1 and 1->0 live-connection edges). Not safe to call concurrently with Register/Deregister — set once during setup.
func (*Manager) TenantConnectionCount ¶
TenantConnectionCount returns the number of connections for a given tenant.
func (*Manager) UserConnectionCount ¶
UserConnectionCount returns the number of connections for a given user.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool provides limit enforcement for per-user and per-tenant connections, and a bytes.Buffer pool for reducing GC pressure during encoding.
func (*Pool) CheckLimits ¶
CheckLimits returns an error if the user or tenant has reached their connection limit.
type PresenceListener ¶
PresenceListener is notified when a user transitions between having zero and having at least one live connection. It is invoked exactly on the 0->1 ("came online") and 1->0 ("went offline") edges, never on every individual connect/disconnect — a user with several simultaneous connections (e.g. multiple browser tabs plus mobile) only fires this once per edge.