web-push-0.1.2.0: Send messages using Web Push protocol.

Safe HaskellNone
LanguageHaskell2010

Web.WebPush

Contents

Synopsis

Functions

generateVAPIDKeys :: MonadRandom m => m VAPIDKeysMinDetails Source #

Generate the 3 integers minimally representing a unique pair of public and private keys.

Store them in configuration and use them across multiple push notification requests.

readVAPIDKeys :: VAPIDKeysMinDetails -> VAPIDKeys Source #

Read VAPID key pair from the 3 integers minimally representing a unique key pair.

vapidPublicKeyBytes :: VAPIDKeys -> [Word8] Source #

Pass the VAPID public key bytes to browser when subscribing to push notifications. Generate application server key using applicationServerKey = new Uint8Array(vapidPublicKeyBytes) in Javascript.

sendPushNotification :: MonadIO m => VAPIDKeys -> Manager -> PushNotificationDetails -> m (Either PushNotificationError ()) Source #

Send a Push Message. The message sent is Base64 URL encoded. Decode the message in Service Worker notification handler in browser before trying to read the JSON.

Types

data VAPIDKeysMinDetails Source #

3 integers minimally representing a unique VAPID key pair.

data PushNotificationDetails Source #

Web push subscription and message details.

Get subscription details from front end using subscription.endpoint, subscription.toJSON().keys.p256dh and subscription.toJSON().keys.auth. Save subscription details to send messages to the endpoint in future.

data PushNotificationError Source #

RecepientEndpointNotFound comes up when the endpoint is no longer recognized by the push service. This may happen if the user has cancelled the push subscription, and hence deleted the endpoint. You may want to delete the endpoint from database in this case.