UNPKG

pushkit

Version:

Everything you need to enable Web Push Notification in your Node.JS web application. Uses the browser's delivery channel to send push notification(Free of cost), which means no extra third-party service (except for the browser's own delivery channel). Wor

4 lines 3.47 kB
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"Focm":[function(require,module,exports) { "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PushKit=r;var n=function(n){return console.log(n)};function i(n){for(var i=(n+"=".repeat((4-n.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),t=window.atob(i),e=new Uint8Array(t.length),r=0;r<t.length;++r)e[r]=t.charCodeAt(r);return e}function t(n){return new Promise(function(i,t){try{n.pushManager.getSubscription().then(function(n){return null===n?t(null):i(n)}).catch(t)}catch(e){t(null)}})}function e(n,t){return new Promise(function(e,r){var o=i(t);try{n.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:o}).then(e).catch(r)}catch(s){r(s)}})}function r(i){var r=this,o=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!i||"string"!=typeof i)throw new Error("Public key must be a valid VAPT key");this.supported=!0,this.subscribed=!1,this.key=i,this.reg=null,this.sub=null,this.granted=!1,window.Notification&&"permission"in window.Notification&&(this.granted="granted"===window.Notification.permission),"serviceWorker"in navigator&&"PushManager"in window||(this.supported=!1),this._initRegistrationInternal=function(i){if(!i)throw new Error("Service worker registration object required as argument");return new Promise(function(s){if(!1===r.supported)return s(null);r.reg=i,t(r.reg).then(function(i){return r.sub=i,r.subscribed=!0,r.granted=!0,o&&n("Already Push Subscribed"),s(r.sub)}).catch(function(i){o&&n(i),e(r.reg,r.key).then(function(i){return r.sub=i,r.subscribed=!0,r.granted=!0,o&&n("Freshly Push Subscribed"),s(r.sub)}).catch(function(i){return o&&n(i),s(null)})})})},this.handleRegistration=function(n){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new Promise(function(t){if(!(window.Notification&&"requestPermission"in window.Notification))return r._initRegistrationInternal(n,i).then(t);if(i&&console.info("Using window.Notification API"),"granted"===window.Notification.permission)return r._initRegistrationInternal(n,i).then(t);var e=function(e){if("granted"===e)return r._initRegistrationInternal(n,i).then(t);i&&console.error("Notification permission denied"),t(null)};try{window.Notification.requestPermission().then(e).catch(function(n){return i&&console.error("Failed to request notification permission",n),reject(null)})}catch(o){return window.Notification.requestPermission(e)}})}} },{}]},{},["Focm"], "pushKit") //# sourceMappingURL=/index.js.map