Documentation
¶
Overview ¶
Package push manages Web Push subscriptions and delivers VAPID-signed notifications.
Index ¶
- func ResolvePreferences(d settings.Document) map[marotte.PushKind]bool
- type KindPref
- type Option
- type Presence
- type PresenceRow
- type Service
- func (s *Service) Close()
- func (s *Service) HasSubscribers() bool
- func (s *Service) Preferences() map[marotte.PushKind]bool
- func (s *Service) PresenceRows() []PresenceRow
- func (s *Service) PresenceTransitions() (alive, expired uint64)
- func (s *Service) RegisterRoutes(mux *http.ServeMux)
- func (s *Service) Retract(subject marotte.PushSubject, ask string)
- func (s *Service) Send(ctx context.Context, sent *marotte.NotificationPayload)
- func (s *Service) SetPreferences(prefs map[marotte.PushKind]bool)
- func (s *Service) Subscribe(sub marotte.PushSubscription)
- func (s *Service) Suppressed(kind marotte.PushKind) uint64
- func (s *Service) Wants(kind marotte.PushKind) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolvePreferences ¶ added in v0.12.16
ResolvePreferences resolves every registered kind's enabled flag from d: the per-kind toggles, then the master switch. A missing or undecodable value takes the kind's kindRegistry default.
Types ¶
type KindPref ¶
KindPref is one registered kind. Exported so the settings write path can derive its preference map from this registry instead of keeping a third hand-maintained copy beside marotte.pushKinds.
type Option ¶
type Option func(*Service)
Option configures a Service at construction.
func WithPresence ¶
WithPresence wires the presence table the send filter reads. Absent, nothing is filtered and every subscription is pushed.
type Presence ¶
type Presence struct {
// contains filtered or unexported fields
}
Presence folds the hub's connected/disconnected feed and the client's keepalive acknowledgements into one verdict per client tag; Gone is what the send filter reads. The acknowledgement is the input the socket cannot supply: a locked phone's kernel keeps acknowledging while its page does not run, and a half-open peer stays connected for the kernel's whole retransmission budget.
Safe for concurrent use.
func NewPresence ¶
func NewPresence() *Presence
NewPresence returns an empty table. Its windows are liveness.AliveWindow and liveness.ReconnectDelay, read at each verdict rather than copied in.
func (*Presence) AnyPresent ¶ added in v0.11.0
AnyPresent reports whether a page behind any tag is receiving the stream, by the verdict Gone reads.
func (*Presence) Gone ¶
Gone reports whether no page behind tag is receiving the stream: an unseen tag, a tag whose last connection departed more than one retry interval ago, or a connected tag silent for longer than the alive window.
func (*Presence) Observe ¶
func (p *Presence) Observe(ev *sse.PresenceEvent)
Observe folds one hub event. Every disconnected cause is one departure whatever ended the socket: closed, dead, evicted, shutdown and hook_failed each follow exactly one connected, so the count balances only if all of them decrement. An event with no tag belongs to a client that presented none and is dropped.
type PresenceRow ¶
PresenceRow is one tag's fold as the test-only probe reports it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages push subscriptions and sends notifications.
func New ¶
New creates a Service, loads persisted subscriptions and preferences, and starts the write loop. subject is the VAPID subject. ctx is the service's lifetime and is required.
func (*Service) Close ¶
func (s *Service) Close()
Close cancels in-flight pushes and waits for the write loop to drain pending saves.
func (*Service) HasSubscribers ¶
HasSubscribers reports whether any push subscriptions are currently registered.
func (*Service) Preferences ¶ added in v0.12.16
Preferences returns a copy of the per-kind enabled flags the service enforces now.
func (*Service) PresenceRows ¶
func (s *Service) PresenceRows() []PresenceRow
PresenceRows is the presence table as the test-only probe reports it; empty when no table is wired.
func (*Service) PresenceTransitions ¶
PresenceTransitions is the table's alive and expired counts; zero when no table is wired.
func (*Service) RegisterRoutes ¶
RegisterRoutes wires /api/push/vapid-key, /api/push/subscribe, and /api/push/unsubscribe onto mux.
func (*Service) Retract ¶
func (s *Service) Retract(subject marotte.PushSubject, ask string)
Retract drops the held ask push about subject that announces ask: the ask was answered on some surface, so a nudge about it has nothing left to say. A later ask's push and another kind's stay held. A no-op with the variant off, since nothing is ever held.
func (*Service) Send ¶
func (s *Service) Send(ctx context.Context, sent *marotte.NotificationPayload)
Send delivers n to all subscribers, debounced per kind AND subject. The payload is n itself, so the service worker shows what the page would. preflightSend's nil means do not send; a non-nil empty slice has stamped the debounce.
func (*Service) SetPreferences ¶
SetPreferences sets the enabled flag of each kind prefs names; a kind it omits keeps its flag.
func (*Service) Subscribe ¶
func (s *Service) Subscribe(sub marotte.PushSubscription)
Subscribe registers a push subscription endpoint. Duplicate endpoints are silently overwritten.
func (*Service) Suppressed ¶
Suppressed reports how many subscriptions the send filter skipped for kind since start.
func (*Service) Wants ¶ added in v0.11.0
Wants reports whether a send of kind would pass the service's own gates: the service is healthy, the kind is registered and enabled, and a subscription exists to receive it. The presence filter is not consulted, because a profile that reads present is a reader rather than a reason to withhold the event.