Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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, opts ...Option) (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.
type NoopWebpusher ¶
type NoopWebpusher struct {
Msg string
}
NoopWebpusher is a Dispatcher that always fails, returning Msg as the error. It is used as a fallback when VAPID key setup fails. The underlying error is not included to avoid leaking internal details (e.g. database errors) in API responses; it is logged at the call site instead.
func (*NoopWebpusher) Dispatch ¶
func (n *NoopWebpusher) Dispatch(context.Context, uuid.UUID, codersdk.WebpushMessage) error
func (*NoopWebpusher) PublicKey ¶
func (*NoopWebpusher) PublicKey() string
func (*NoopWebpusher) Test ¶
func (n *NoopWebpusher) Test(context.Context, codersdk.WebpushSubscription) error
type Option ¶ added in v2.32.0
type Option func(*options)
Option configures optional behavior for a Webpusher.
func WithClock ¶ added in v2.32.0
WithClock sets the clock used by the subscription cache. Defaults to a real clock when not provided.
func WithHTTPClient ¶ added in v2.33.0
WithHTTPClient overrides the default SSRF-safe HTTP client used to deliver push notifications. This is intended for tests that need to deliver to localhost test servers.
func WithSubscriptionCacheTTL ¶ added in v2.32.0
WithSubscriptionCacheTTL sets the in-memory subscription cache TTL. Defaults to three minutes when not provided or when given a non-positive duration.
type SubscriptionCacheInvalidator ¶ added in v2.32.0
SubscriptionCacheInvalidator is an optional interface that lets local subscription mutation handlers invalidate cached subscriptions.
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) InvalidateUser ¶ added in v2.32.0
InvalidateUser clears the cached subscriptions for a user and advances its invalidation generation. Local subscribe and unsubscribe handlers call this after mutating subscriptions in the same process.