Created
November 16, 2019 05:05
-
-
Save sahajamit/5cb376a5ae07aa7af5b491ce56060f12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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