Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send useful notifications to a user based on location #3

Open
marcveens opened this issue Aug 21, 2018 · 4 comments
Open

Send useful notifications to a user based on location #3

marcveens opened this issue Aug 21, 2018 · 4 comments
Labels
research Do some research

Comments

@marcveens
Copy link
Member

marcveens commented Aug 21, 2018

Still needs some research to do:

  • What are the push/notification possibilities in a PWA? What can be done, what cannot?
  • Can we send a push based on location?
  • Who is in charge of sending a push? Who can send it?
  • How can we send a user to a certain PWA page after clicking the notification?
@marcveens marcveens added the research Do some research label Aug 21, 2018
@marcveens
Copy link
Member Author

When to send a notification
For now, let's say:

  • If a user moved 100km within 4 hours

What we have to do after fetching a new location:

  • Find out how many records were saved within 4 hours (or 240 minutes or 14400 seconds)
  • Sum the distance of all these records
  • If a user moved more than 100km (or 100000 meters) send a push notification containing a message like "Take some rest, here are some hotels nearby"

@marcveens
Copy link
Member Author

Currently we make use of the web-push library: https://github.com/web-push-libs/web-push.

We created an Azure site to which we deployed the NodeJS server part of our push service. This service contains a /service endpoint which will be used to store the client subscriptions in memory (Later on we have to save the subscription keys in a DB or FS). We also have a /notify/all endpoint which is used to push messages to all subscribed clients.

Clientside we added some event listeners to the service-worker.js file which handle the push message and create a notification out of it.

@marcveens
Copy link
Member Author

Notifications work, but it seems that a custom badge doesn't work. The only thing that shows is the default bell icon:

screenshot_20180828-152411__01

@marcveens
Copy link
Member Author

In order to open an external website after clicking on a notification, use:

event.waitUntil(clients.openWindow('https://www.nu.nl'));

In order to open the app again, use:

event.waitUntil(clients.openWindow('/'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
research Do some research
Projects
None yet
Development

No branches or pull requests

1 participant