Pushe.co's webpush javascript SDK
npm install pushe-webpushPushe.co's SDK for webpush
#### Installation
Using npm:
``javascript`
npm i -P pushe-webpush
#### Import
`javascript`
var Pushe = require("pushe-webpush");
or if you use ES6:
`javascript`
import Pushe from "pushe-webpush";
Note: If you want to use it with a script tag in your html you can do so like this:
``
#### Initialize Push Service
To initialize Pushe webpush service in your app/website use Pushe.init() with your appId that is provided to you when you created your app in Pushe console.
`javascript
var appId = "Your app id";
Pushe.init(appId);
`
#### Subscribe User
To subscribe users in your app or website use Pushe.subscribe().
`javascript`
Pushe.subscribe();
Note:
This will ask user for permission if it is the first time subscribing. You can use it in your app whenever you want the subscription to happen.
#### Unsubscribe User
Use Pushe.unsubscribe() to unsubscribe the user from push events.
`javascript`
Pushe.unsubscribe();
#### ServiceWorker
To use webpush functionality you also need to put our ServiceWorker in root directory of your app/site.
1. Create a file named pushe-sw.js and put it in root of your app/site
2. Put the below line in pushe-sw.js:
`javascript``
importScripts("https://static.pushe.co/pusheweb-sw.js");