Documentation
¶
Overview ¶
Package events fans server events out to connected clients (the server-sent event stream). Every event says who may see it, so each user's stream only carries their own and shared events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Audience ¶
type Audience struct {
// All users.
All bool
// Admins (always included when All).
Admins bool
// Users by ID.
Users []uuid.UUID
}
Audience says who may receive an event.
type Event ¶
type Event struct {
// ID increases across the server's life.
ID int64
Type string
Data any
To Audience
}
Event is one server event.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub fans events out. Publishing never blocks: a subscriber that falls behind is dropped (its stream ends, and the client reconnects and refetches).
func (*Hub) Publish ¶
Publish sends an event to every subscriber allowed to see it. Safe on a nil hub.
func (*Hub) Subscribe ¶
func (h *Hub) Subscribe(v Viewer) *Subscription
Subscribe starts receiving events for v. Call Close when done.
type Subscription ¶
type Subscription struct {
C chan Event
// contains filtered or unexported fields
}
Subscription receives the events its viewer may see.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close stops the subscription and closes C.