Skip to content

Instantly share code, notes, and snippets.

@sahajamit
Created November 16, 2019 05:05
Show Gist options
  • Save sahajamit/5cb376a5ae07aa7af5b491ce56060f12 to your computer and use it in GitHub Desktop.
Save sahajamit/5cb376a5ae07aa7af5b491ce56060f12 to your computer and use it in GitHub Desktop.
// To Start Listening to all Web Push Notifications
window.notificationsMap = Object.create(null);
async function getServiceWorkerRegistration(){
window.myServiceWorkerRegistration = await navigator.serviceWorker.getRegistration("https://framework.realtime.co/demo/web-push/");
return window.myServiceWorkerRegistration;
};
async function getNotifications() {
window.myNotifications = await window.myServiceWorkerRegistration.getNotifications();
};
window.notificationListener = setInterval(async function() {
console.log("checking for notifications...");
await getServiceWorkerRegistration();
await getNotifications();
for(var key in window.myNotifications){
window.notificationsMap[window.myNotifications[key].tag] = window.myNotifications[key];
};
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment