I am nww to GAE and push API/service workers, I am trying to subscribe the pushManager but, pushManager getSubscription method handler returns the null reference
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration)
{ console.log('in side ready ' );
// Do we already have a push message subscription?
serviceWorkerRegistration.pushManager.getSubscription()
.then(function(subscription) {
// Enable any UI which subscribes / unsubscribes from
// push messages.
var pushButton = document.querySelector('.js-push-button');
pushButton.disabled = false;
if (!subscription) {
// We aren't subscribed to push, so set UI
// to allow the user to enable push console.log('subscription error ' );
return;
} console.log('subscriptioned ' );
// Keep your server in sync with the latest subscriptionId
sendSubscriptionToServer(subscription);
// Set your UI to show they have subscribed for
// push messages
pushButton.textContent = 'Disable Push Messages';
isPushEnabled = true;
})
.catch(function(err) {
console.warn('Error during getSubscription()', err);
}); });
In able code getSubscription()
then returns subscription value as null, so that, control comes to if block and function is existing
if i am trying to call the
serviceWorkerRegistration.pushManager.subscribe()
then I am getting the below error
registration failed - no sender id provided
Please find the working progress url below https://dtatable-date-filter.googleplex.com/home
Assuming this is in chrome you need to include a sender id in the manifest file.
You obtain such sender id by creating a project in google's developer console.
You can get a detailed set of steps in:
https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=en
Read from section: "Make a Project on the Google Developer Console" onwards.
You can see an example of a manifest file with its own sender id here: https://johnme-gcm.appspot.com/manifest.json
Note the two relevant keys needed to make push work: "gcm_user_visible_only": true, "gcm_sender_id": "..." <- Create your own and replace ... with it.