pushe-webpush
v1.3.1
Published
Pushe.co's webpush javascript SDK
Downloads
29
Keywords
Readme
Pushe Webpush SDK
Pushe.co's SDK for webpush
Installation
Using npm:
npm i -P pushe-webpush
Import
var Pushe = require("pushe-webpush");
or if you use ES6:
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:
<html>
<head>
<script src="https://static.pushe.co/pusheweb.js"></script>
</head>
<body>
</body>
</html>
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.
var appId = "Your app id";
Pushe.init(appId);
Subscribe User
To subscribe users in your app or website use Pushe.subscribe()
.
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.
Pushe.unsubscribe();
ServiceWorker
To use webpush functionality you also need to put our ServiceWorker in root directory of your app/site.
- Create a file named pushe-sw.js and put it in root of your app/site
- Put the below line in pushe-sw.js:
importScripts("https://static.pushe.co/pusheweb-sw.js");