google cloud messaging - GCM registration id in Service Worker in Push Notification for chrome -


i able send push notification , in service worker making service call want send gcm registration id service call. how registration id or subscription id in service worker

here code

self.addeventlistener('push', function(event) {   console.log('received push message local', event);    var title = 'my title file. testing on';   var body = 'new push message.';   var icon = 'refresh_blueicon.png';   var tag = 'my-push-tag';    event.waituntil( // here need wind gcm registration id / subscription id external service call     fetch('http://localhost/pushmsg/push_notification/msg.php').then(function(response){       if (response.status !== 200) {         console.log('looks there problem. status code: ' +         response.status);         throw new error();       }        // examine text in response       return response.json().then(function(data) {         self.registration.shownotification(data.title, {           body: data.msg,           icon: icon,           tag: tag         })   })   })     ); });   self.addeventlistener('notificationclick', function(event) {   console.log('on notification click: ', event.notification.tag);   // android doesn’t close notification when click on   // see: http://crbug.com/463146   event.notification.close();    // looks see if current open ,   // focuses if   event.waituntil(clients.matchall({     type: "window"   }).then(function(clientlist) {     (var = 0; < clientlist.length; i++) {       var client = clientlist[i];       if (client.url == '/' && 'focus' in client)         return client.focus();     }     if (clients.openwindow)       return clients.openwindow('/');   }));  }); 

you should have subscription available on pushmanager object if have subscribed user. should work:

registration.pushmanager.getsubscription().then(function(subscription) {   console.log("got subscription id: ", subscription.endpoint) }); 

that's whole endpoint, if want id this:

subscription.endpoint.split("/").slice(-1)) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -