pwa/pwa.js
/**
         * Subscribe to Push and send to Server API
         * @param  {Function} callback Return callback with subscription object.
         * @return {Object}   subscription
         */
Subscribe to Push and send to Server API
@param  {Function} callback Return callback with subscription object.
@return {Object}   subscription
Subscribe to Push and send to Server API @param { Function } callback Return callback with subscription object . @return { Object } subscription
static subscribe(callback) {
            if (Navigator.isSupportedServiceWorker()) {
                ServiceWorker.getRegistration((registration) => {
                    if (registration) {
                        registration.pushManager.subscribe({
                            userVisibleOnly: true,
                            applicationServerKey: Helper.urlBase64ToUint8Array(PWA_CONFIG.push.server.public_key)
                        })
                            .then((subscription) => {
                                console.log('PWA: Subscribed to push service!');
                                Server.sendSubscription(subscription, 'POST');
                                callback(subscription);
                            })
                            .catch((error) => {
                                if (!Notification.isDenied()) {
                                    console.error('PWA: Unable to subscribe to Push', error);
                                }
                            })
                        ;
                    }
                });
            }
        }
static subscribe ( callback ) { if ( Navigator . isSupportedServiceWorker ( ) ) { ServiceWorker . getRegistration ( ( registration ) => { if ( registration ) { registration . pushManager . subscribe ( { userVisibleOnly : true , applicationServerKey : Helper . urlBase64ToUint8Array ( PWA_CONFIG . push . server . public_key ) } ) . then ( ( subscription ) => { console . log ( 'PWA: Subscribed to push service!' ) ; Server . sendSubscription ( subscription , 'POST' ) ; callback ( subscription ) ; } ) . catch ( ( error ) => { if ( ! Notification . isDenied ( ) ) { console . error ( 'PWA: Unable to subscribe to Push' , error ) ; } } ) ; } } ) ; } }
Subscribe to Push and send to Server API
 @param  {Function} callback Return callback with subscription object.
Subscribe to Push and send to Server API @param { Function } callback Return callback with subscription object .