Is your feature request related to a problem? Please describe.
There are many users who ends up launching our app with the need to search for the same district/state again for the updated numbers. create a web push notifications through service workers that keeps notifying the users on a specified interval?
We could get the preferred state/ district and the interval after which he wants to be notified.
When the user clicks on the notification, based on the preference we open the right data on page.
Describe the solution you'd like
Create a web push notifications through service workers that keeps notifying the users on a specified interval. We could get the preferred state/ district and the interval after which he wants to be notified.
When the user clicks on the notification, based on the preference we open the right data on page.
Hi, I would like to pick this feature. I have good amount of experience in service workers.
I can see that there is no server involved, all data coming from static JSON hosted in GitHub. So the point is without server, push notification is not possible.
But I have a workaround for this. We will use pull strategy here instead of server push strategy. In data.json file which is coming from GitHub server, there is a last-modified header value. We can use service worker to fetch only header of that file in background and once there is any change in last-modified value then fetch the actual content and show user a notification with latest statistics. Once user click on that notification open the page or focus on that page with refreshed data.
For a quick start I can show notification of high level statics like (confirmed/active/recovered/deceased) cases. Later we can ask user to subscribe for particular state level statistics.
I have clear idea, how and what to do for this feature. Please assigned it me, I want to contribute for this noble cause.
Okay the explanation is just too good, all yours @omui :)
@jeremyphilemon Thank you for giving me this opportunity. I have implemented notification feature. Whenever there is any change in data.json, user will see notification with updated stats and clicking on notification will navigate to page with refreshed data. You can check code here.
https://github.com/omui/covid19india-react/commit/5aede169e729bfba94e23160dfad02afb12a4e3c
Everything was good until I tested with closed browser. So the problem is the lifespan of service worker. Service worker will be destroyed after some time when tab is closed. Service worker can only be alive with events like (install, fetch, message, push). As I mentioned earlier that I am going to use pull strategy, I was right about it and it worked but service worker thread get destroyed after a certain time when tab is closed. Check below link for better clarification.
https://stackoverflow.com/questions/29741922/prevent-service-worker-from-automatically-stopping
So my workaround/hack did not work here. We need real server to send push messages then only service worker can be alive. Let me know, if in future we are targeting for real server, I can pick this item again.
Oh well. Thanks for trying though, and thanks for explaining the workaround you tried, I might need it for future reference. Cheers :)
Most helpful comment
Hi, I would like to pick this feature. I have good amount of experience in service workers.
I can see that there is no server involved, all data coming from static JSON hosted in GitHub. So the point is without server, push notification is not possible.
But I have a workaround for this. We will use pull strategy here instead of server push strategy. In data.json file which is coming from GitHub server, there is a last-modified header value. We can use service worker to fetch only header of that file in background and once there is any change in last-modified value then fetch the actual content and show user a notification with latest statistics. Once user click on that notification open the page or focus on that page with refreshed data.
For a quick start I can show notification of high level statics like (confirmed/active/recovered/deceased) cases. Later we can ask user to subscribe for particular state level statistics.
I have clear idea, how and what to do for this feature. Please assigned it me, I want to contribute for this noble cause.