Class WebPush

java.lang.Object
com.vaadin.flow.server.webpush.WebPush

public class WebPush extends Object
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 Details

    • WebPush

      public WebPush(String publicKey, String privateKey, String subject)
      Create new WebPushRegistration for given publicKey.
      Parameters:
      publicKey - public key to use for web push
      privateKey - web push private key
      subject - 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 client
      message - notification message containing data to be shown, e.g. title and body
      Throws:
      WebPushException - if sending a notification fails
    • subscriptionExists

      public void subscriptionExists(UI ui, WebPushState receiver)
      Check if there is a web push subscription registered to the serviceWorker on the client.
      Parameters:
      ui - current ui
      receiver - the callback to which the details are provided
    • isNotificationDenied

      public void isNotificationDenied(UI ui, WebPushState receiver)
      Check if notifications are denied on the client.
      Parameters:
      ui - current ui
      receiver - the callback to which the details are provided
    • isNotificationGranted

      public void isNotificationGranted(UI ui, WebPushState receiver)
      Check if notifications are granted on the client.
      Parameters:
      ui - current ui
      receiver - the callback to which the details are provided
    • subscribe

      public void subscribe(UI ui, WebPushSubscriptionResponse receiver)
      Subscribe web push for client. Will open an acceptance window for allowing notifications.
      Parameters:
      ui - current ui
      receiver - the callback to which the details are provided
    • unsubscribe

      public void unsubscribe(UI ui, WebPushSubscriptionResponse receiver)
      Unsubscribe web push from client.
      Parameters:
      ui - current ui
      receiver - the callback to which the details are provided
    • fetchExistingSubscription

      public void fetchExistingSubscription(UI ui, WebPushSubscriptionResponse receiver)
      Get an existing subscription from the client.
      Parameters:
      ui - current ui
      receiver - the callback to which the details are provided