Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

push-js

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

push-js

Push and Notifications API wrapper.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Push-JS

Table of Contents

Purpose

Wrapper around Push and Notifications API. Handles subscription and unsubscription. Provides some useful methods.

Needs service worker to be installed in any way. Provides an interface to perform service worker installation if needed.

Example

You can find a basic example application including manifest.json and fully commented service worker in the example folder.

To run the app use npm run local command and navigate to http://localhost:5001.

Usage

import Push from 'push-js';

const push = new Push(); // All arguments are optional
push.subscribe().then(subscription => {});
push.unsubscribe().then(() => {});

Service worker

There is a simple service worker provided with this package. It's needed to make notification events to work properly. You may use it as is, but the best way is to import it in your service worker, as shown in the example.

Constructor parameters

options (optional)

An options object that can contain some callbacks and a path to the service worker.

  • stateChangeCb: receives state and an Error object if an error occurred.
  • subscriptionUpdateCb: receives subscription object (PushSubscription).
  • logCb: receives anything that should be logged.

Instance methods

Push.prototype.subscribe()

Creates and returns new subscription if it does n't exist, returns old otherwise.

Push.prototype.unsubscribe()

Tries to unsubscribe. Returns resolved Promise anyway.

Static methods

Push.getPermissionState()

Returns permission state. See ./source/constants/states.js.

Push.requestPermission()

Requests user permission to show notifications. Returns resolved or rejected Promise depending on user decision.

Push.checkSupport()

Checks browser support and returns Boolean.

Push.getSubscription()

Same as PushManager.getSubscription().

Push.showNotification()

Accepts two parameters, same as new Notification constuctor does. See MDN for the description. Shows notification via service worker. Returns Promise resolved with corresponding Notification object.

Version 1.1.1

Keywords

FAQs

Package last updated on 21 Nov 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc