Documentation
¶
Overview ¶
Package push manages Web Push subscriptions and delivers VAPID-signed notifications.
Index ¶
- Constants
- type Service
- func (s *Service) Close()
- func (s *Service) HasSubscribers() bool
- func (s *Service) PublicKey() string
- func (s *Service) RegisterRoutes(mux *http.ServeMux)
- func (s *Service) ReloadPreferences(ctx context.Context)
- func (s *Service) Send(ctx context.Context, title, body string, notifyType api.PushKind)
- func (s *Service) SetPreferences(prefs map[api.PushKind]bool)
- func (s *Service) Subscribe(sub api.PushSubscription)
- func (s *Service) Unsubscribe(endpoint string)
Constants ¶
const DefaultTitle = "Vibekit"
DefaultTitle is the notification title used for all Web Push messages.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 (mailto: or https: URI identifying the sender).
func (*Service) Close ¶
func (s *Service) Close()
Close cancels any in-flight pushes and waits for the write loop to drain pending saves. Call from the hub's shutdown path so pending sends don't hold the shutdown up to 10s each.
func (*Service) HasSubscribers ¶
HasSubscribers reports whether any push subscriptions are currently registered.
func (*Service) PublicKey ¶
PublicKey returns the VAPID public key used for push subscription registration.
func (*Service) RegisterRoutes ¶
RegisterRoutes wires /api/push/vapid-key, /api/push/subscribe, and /api/push/unsubscribe onto mux.
func (*Service) ReloadPreferences ¶
ReloadPreferences deduplicates concurrent preference reloads via singleflight so N simultaneous SSE reconnects produce only one disk read.
func (*Service) Send ¶
Send delivers a push notification to all subscribers. notifyType is KindAgentFinished or KindPermission; the service checks per-type preferences and debounces rapid notifications on a per-type basis (so a permission push doesn't suppress the agent- finished push that follows within 5s). Oversize payloads are truncated with a Warn breadcrumb so an accidentally-chatty caller doesn't get silently rejected by the push vendor.
func (*Service) SetPreferences ¶
SetPreferences updates the per-kind notification enabled flags.
func (*Service) Subscribe ¶
func (s *Service) Subscribe(sub api.PushSubscription)
Subscribe registers a push subscription endpoint. Duplicate endpoints are silently overwritten.
func (*Service) Unsubscribe ¶
Unsubscribe removes the subscription for the given push endpoint.