Documentation
¶
Index ¶
- type Channel
- type Client
- type Config
- type Event
- type Hub
- func (h *Hub) Broadcast(channel string, event Event)
- func (h *Hub) BroadcastExcept(channel string, event Event, exceptUserID string)
- func (h *Hub) Channels() []string
- func (h *Hub) GetChannel(name string) *Channel
- func (h *Hub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
- func (h *Hub) UserCount(channel string) int
- func (h *Hub) UsersIn(channel string) []User
- type PresencePlugin
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel represents a single presence channel.
func (*Channel) BroadcastExcept ¶
BroadcastExcept sends to all clients except one.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a single websocket connection.
type Config ¶
type Config struct {
// AuthFunc authenticates a user for a specific channel.
// Return nil user to reject the connection.
AuthFunc func(r *http.Request, channel string) (*User, error)
// PingInterval controls how often to send ping frames (default: 30s).
PingInterval time.Duration
// WriteTimeout for websocket writes (default: 10s).
WriteTimeout time.Duration
// MaxMessageSize in bytes (default: 4096).
MaxMessageSize int64
// Path for the websocket endpoint (default: "/_presence").
Path string
// AllowedOrigins controls accepted websocket Origin hosts.
// When empty, same-origin requests are allowed by default.
AllowedOrigins []string
}
Config configures the presence hub.
type Event ¶
type Event struct {
Type string `json:"type"`
Channel string `json:"channel,omitempty"`
User *User `json:"user,omitempty"`
Users []User `json:"users,omitempty"`
Data any `json:"data,omitempty"`
}
Event is a message sent over the presence channel.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages all presence channels and their connected clients.
func (*Hub) BroadcastExcept ¶
BroadcastExcept sends a message to all clients except the specified user.
func (*Hub) GetChannel ¶
GetChannel returns a channel if it exists, nil otherwise.
func (*Hub) HandleWebSocket ¶
func (h *Hub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket upgrades an HTTP connection and joins a presence channel.
type PresencePlugin ¶
type PresencePlugin struct {
nimbus.BasePlugin
Hub *Hub
}
PresencePlugin integrates presence channels with Nimbus.
func (*PresencePlugin) RegisterRoutes ¶
func (p *PresencePlugin) RegisterRoutes(r *router.Router)
RegisterRoutes mounts presence endpoints.
Click to show internal directories.
Click to hide internal directories.