push

package
v0.2.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: GPL-2.0, GPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package push manages Web Push subscriptions and delivers VAPID-signed notifications.

Index

Constants

View Source
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

func New(ctx context.Context, configDir, subject string) *Service

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

func (s *Service) HasSubscribers() bool

HasSubscribers reports whether any push subscriptions are currently registered.

func (*Service) PublicKey

func (s *Service) PublicKey() string

PublicKey returns the VAPID public key used for push subscription registration.

func (*Service) RegisterRoutes

func (s *Service) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes wires /api/push/vapid-key, /api/push/subscribe, and /api/push/unsubscribe onto mux.

func (*Service) ReloadPreferences

func (s *Service) ReloadPreferences(ctx context.Context)

ReloadPreferences deduplicates concurrent preference reloads via singleflight so N simultaneous SSE reconnects produce only one disk read.

func (*Service) Send

func (s *Service) Send(ctx context.Context, title, body string, notifyType api.PushKind)

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

func (s *Service) SetPreferences(prefs map[api.PushKind]bool)

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

func (s *Service) Unsubscribe(endpoint string)

Unsubscribe removes the subscription for the given push endpoint.

Directories

Path Synopsis
Package crypto provides RFC 8291 encryption helpers and VAPID JWT construction for Web Push.
Package crypto provides RFC 8291 encryption helpers and VAPID JWT construction for Web Push.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL