webpush

package
v2.21.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegenerateVAPIDKeys

func RegenerateVAPIDKeys(ctx context.Context, db database.Store) (newPrivateKey string, newPublicKey string, err error)

RegenerateVAPIDKeys regenerates the VAPID keys and deletes all existing push subscriptions as part of the transaction, as they are no longer valid.

Types

type Dispatcher

type Dispatcher interface {
	// Dispatch sends a web push notification to all subscriptions
	// for a user. Any notifications that fail to send are silently dropped.
	Dispatch(ctx context.Context, userID uuid.UUID, notification codersdk.WebpushMessage) error
	// Test sends a test web push notificatoin to a subscription to ensure it is valid.
	Test(ctx context.Context, req codersdk.WebpushSubscription) error
	// PublicKey returns the VAPID public key for the webpush dispatcher.
	PublicKey() string
}

Dispatcher is an interface that can be used to dispatch web push notifications to clients such as browsers.

func New

func New(ctx context.Context, log *slog.Logger, db database.Store, vapidSub string) (Dispatcher, error)

New creates a new Dispatcher to dispatch web push notifications.

This is *not* integrated into the enqueue system unfortunately. That's because the notifications system has a enqueue system, and push notifications at time of implementation are being used for updates inside of a workspace, which we want to be immediate.

See: https://github.com/coder/internal/issues/528

type NoopWebpusher

type NoopWebpusher struct {
	Msg string
}

NoopWebpusher is a Dispatcher that does nothing except return an error. This is returned when web push notifications are disabled, or if there was an error generating the VAPID keys.

func (*NoopWebpusher) Dispatch

func (*NoopWebpusher) PublicKey

func (*NoopWebpusher) PublicKey() string

func (*NoopWebpusher) Test

type Webpusher

type Webpusher struct {

	// public and private keys for VAPID. These are used to sign and encrypt
	// the message payload.
	VAPIDPublicKey  string
	VAPIDPrivateKey string
	// contains filtered or unexported fields
}

func (*Webpusher) Dispatch

func (n *Webpusher) Dispatch(ctx context.Context, userID uuid.UUID, msg codersdk.WebpushMessage) error

func (*Webpusher) PublicKey

func (n *Webpusher) PublicKey() string

PublicKey returns the VAPID public key for the webpush dispatcher. Clients need this, so it's exposed via the BuildInfo endpoint.

func (*Webpusher) Test

Jump to

Keyboard shortcuts

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