Package com.vaadin.flow.server.webpush
Class WebPush
java.lang.Object
com.vaadin.flow.server.webpush.WebPush
Base class for handling Web Push notifications.
Enables developers to register clients to the Push Server, return subscription data to be stored on a server, unregister clients and sending notifications to the clients.
- Since:
- 24.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfetchExistingSubscription(UI ui, WebPushSubscriptionResponse receiver) Get an existing subscription from the client.voidisNotificationDenied(UI ui, WebPushState receiver) Check if notifications are denied on the client.voidisNotificationGranted(UI ui, WebPushState receiver) Check if notifications are granted on the client.voidsendNotification(WebPushSubscription subscription, WebPushMessage message) Sends Web Push Notification to a client/browser having a given subscription.voidsubscribe(UI ui, WebPushSubscriptionResponse receiver) Subscribe web push for client.voidsubscriptionExists(UI ui, WebPushState receiver) Check if there is a web push subscription registered to the serviceWorker on the client.voidunsubscribe(UI ui, WebPushSubscriptionResponse receiver) Unsubscribe web push from client.
-
Constructor Details
-
WebPush
Create new WebPushRegistration for given publicKey.- Parameters:
publicKey- public key to use for web pushprivateKey- web push private keysubject- Subject used in the JWT payload (for VAPID).
-
-
Method Details
-
sendNotification
public void sendNotification(WebPushSubscription subscription, WebPushMessage message) throws WebPushException Sends Web Push Notification to a client/browser having a given subscription.- Parameters:
subscription- web push subscription of the clientmessage- notification message containing data to be shown, e.g.titleandbody- Throws:
WebPushException- if sending a notification fails
-
subscriptionExists
Check if there is a web push subscription registered to the serviceWorker on the client.- Parameters:
ui- current uireceiver- the callback to which the details are provided
-
isNotificationDenied
Check if notifications are denied on the client.- Parameters:
ui- current uireceiver- the callback to which the details are provided
-
isNotificationGranted
Check if notifications are granted on the client.- Parameters:
ui- current uireceiver- the callback to which the details are provided
-
subscribe
Subscribe web push for client. Will open an acceptance window for allowing notifications.- Parameters:
ui- current uireceiver- the callback to which the details are provided
-
unsubscribe
Unsubscribe web push from client.- Parameters:
ui- current uireceiver- the callback to which the details are provided
-
fetchExistingSubscription
Get an existing subscription from the client.- Parameters:
ui- current uireceiver- the callback to which the details are provided
-