Show Menu
Cheatography

Push-Nachrichten Cheat Sheet by

Web-Server

Initialize State

Set the initial subscr­iption value:
swRegi­str­ati­on.p­us­hMa­nag­er.g­et­Sub­scr­ipt­ion() .then(­fun­cti­on(­sub­scr­iption)

Handle a Push Event

Triggering a push message:
self.a­ddE­ven­tLi­ste­ner­('p­ush', functi­on(­event)

Unsubs­cribe User

Unsubs­cribe Function:
swRegi­str­ati­on.p­us­hMa­nag­er.g­et­Sub­scr­ipt­ion() .then(­fun­cti­on(­sub­scr­iption) { if (subsc­rip­tion) { return subscr­ipt­ion.un­sub­scr­ibe(); }
 

Register a service worker

Register a service worker:
naviga­tor.se­rvi­ceW­ork­er.r­eg­ist­er(­'sw.js­').t­he­n(f­unc­tio­n(s­wReg)

Handle Permission Denied

Handling permission denied:
if (Notif­ica­tio­n.p­erm­ission === 'denied')

Notifi­cation Click

Add click event to notifi­cation:
self.a­ddE­ven­tLi­ste­ner­('n­oti­fic­ati­onc­lick', functi­on(­event)

Applic­ation Server key

Set applic­ation server key:
const applic­ati­onS­erv­erP­ubl­icKey = '<Your Public Key>';

Subscribe User

Handle user subscr­iption:
pushBu­tto­n.a­ddE­ven­tLi­ste­ner­('c­lick', function() { pushBu­tto­n.d­isabled = true; if (isSub­scr­ibed) { // TODO: Unsubs­cribe user } else { subscr­ibe­User(); }
Update Subscr­iption:
update­Sub­scr­ipt­ion­OnS­erv­er(­sub­scr­ipt­ion);
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Single-Area OSPF Cheat Sheet
          Mobile Application Cheat Sheet

          More Cheat Sheets by Dominik Mihalic