Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- generateVAPIDKeys :: MonadRandom m => m VAPIDKeysMinDetails
- readVAPIDKeys :: VAPIDKeysMinDetails -> VAPIDKeys
- vapidPublicKeyBytes :: VAPIDKeys -> [Word8]
- sendPushNotification :: (MonadIO m, ToJSON msg) => VAPIDKeys -> Manager -> PushNotification msg -> m (Either PushNotificationError ())
- pushEndpoint :: Lens' (PushNotification msg) PushEndpoint
- pushP256dh :: Lens' (PushNotification msg) PushP256dh
- pushAuth :: Lens' (PushNotification msg) PushAuth
- pushSenderEmail :: Lens' (PushNotification msg) Text
- pushExpireInSeconds :: Lens' (PushNotification msg) Int64
- pushMessage :: ToJSON msg => Lens (PushNotification a) (PushNotification msg) a msg
- mkPushNotification :: PushEndpoint -> PushP256dh -> PushAuth -> PushNotification ()
- type VAPIDKeys = KeyPair
- data VAPIDKeysMinDetails = VAPIDKeysMinDetails {}
- data PushNotification msg
- data PushNotificationMessage = PushNotificationMessage {}
- data PushNotificationError
- type PushEndpoint = Text
- type PushP256dh = Text
- type PushAuth = Text
Functions
generateVAPIDKeys :: MonadRandom m => m VAPIDKeysMinDetails Source #
Generate the 3 integers minimally representing a unique pair of public and private keys.
Store them securely 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 browser using:
applicationServerKey = new Uint8Array( #{toJSON vapidPublicKeyBytes} )
sendPushNotification :: (MonadIO m, ToJSON msg) => VAPIDKeys -> Manager -> PushNotification msg -> m (Either PushNotificationError ()) Source #
Send a Push Message. Read the message in Service Worker notification handler in browser:
self.addEventListener('push', function(event){ console.log(event.data.json()); });
pushEndpoint :: Lens' (PushNotification msg) PushEndpoint Source #
pushP256dh :: Lens' (PushNotification msg) PushP256dh Source #
pushSenderEmail :: Lens' (PushNotification msg) Text Source #
pushExpireInSeconds :: Lens' (PushNotification msg) Int64 Source #
pushMessage :: ToJSON msg => Lens (PushNotification a) (PushNotification msg) a msg Source #
mkPushNotification :: PushEndpoint -> PushP256dh -> PushAuth -> PushNotification () Source #
Constuct a push notification.
PushEndpoint
, PushP256dh
and PushAuth
should be obtained from push subscription in client's browser.
Push message can be set through pushMessage
; text and json messages are usually supported by browsers.
pushSenderEmail
and pushExpireInSeconds
can be used to set additional details.
Types
data VAPIDKeysMinDetails Source #
3 integers minimally representing a unique VAPID public-private key pair.
Instances
Show VAPIDKeysMinDetails Source # | |
Defined in Web.WebPush showsPrec :: Int -> VAPIDKeysMinDetails -> ShowS # show :: VAPIDKeysMinDetails -> String # showList :: [VAPIDKeysMinDetails] -> ShowS # |
data PushNotification msg Source #
Web push subscription and message details. Use mkPushNotification
to construct push notification.
data PushNotificationMessage Source #
Example payload structure for web-push.
Any datatype with JSON instance can also be used instead.
See mkPushNotification
.
Instances
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, or if EndpointParseFailed
.
EndpointParseFailed SomeException | |
MessageEncryptionFailed CryptoError | |
RecepientEndpointNotFound | |
PushRequestFailed SomeException |
Instances
Show PushNotificationError Source # | |
Defined in Web.WebPush showsPrec :: Int -> PushNotificationError -> ShowS # show :: PushNotificationError -> String # showList :: [PushNotificationError] -> ShowS # | |
Exception PushNotificationError Source # | |
Defined in Web.WebPush |
type PushEndpoint = Text Source #
type PushP256dh = Text Source #