Socket
Book a DemoInstallSign in
Socket

@notifi-network/notifi-web-push-service-worker

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@notifi-network/notifi-web-push-service-worker

A package for receiving notifications on your PWA via web push

latest
Source
npmnpm
Version
1.1.3-alpha.15
Version published
Maintainers
0
Created
Source

Notifi React SDK

@notifi-network/notifi-web-push-service-worker allows your PWA to subscribe to WebPush notifications

Take a look at our example implementation to see how to import and activate the worker React Example



Getting Started

Environment

  • Node version >= 18 (with corresponding npm version)
  • React version >= 17

If you haven't created a Notifi tenant account yet set up an account



Prerequisites

In order to enable WebPush notifications, your dapp must



Subscribing for WebPush notifications

All alerts created via the notifi-frontend-client or notifi-react packages will automatically get published here once successfully initialized below.

import { initWebPushServiceWorker } from '@notifi-network/notifi-web-push-service-worker';

  /* This is some class/object in your frontend app that is an appropriate place to start the notifications service.
     Ensure authorization via wallet-sign or OIDC flow has succeeded before calling this. Calling before will result
     in nothing happening */
export default function Home() {
  React.useEffect(() => {
    initWebPushServiceWorker()
  }, []);
}



Unsubscribing from WebPush notifications

This will disable notifications coming in for WebPush. To manage alerts and other destinations, please continue to use the full notifi-frontend-client or notifi-react packages.

function unsubscribePushManger() {
  navigator.serviceWorker.ready.then((reg) => {
    reg.pushManager.getSubscription().then((subscription) => {
      if (subscription) {
        subscription
          .unsubscribe()
          .then((successful) => {
            console.log("Successfully unsubscribe push manager")
          })
          .catch((e) => {
            console.error("Failed to unsusbcribe push manager")
          });
      }
    });
  });
}

return (
    <button
        onClick={() => {
          unsubscribePushManger();
        }}
      >
        Unsubscribe push subscription
    </button>
)

FAQs

Package last updated on 09 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts