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

Web Push support #199

Closed
remon-nashid opened this issue Apr 6, 2022 · 28 comments · Fixed by #751
Closed

Web Push support #199

remon-nashid opened this issue Apr 6, 2022 · 28 comments · Fixed by #751
Labels
enhancement New feature or request server Relates to the main binary (server or client)

Comments

@remon-nashid
Copy link

remon-nashid commented Apr 6, 2022

This is a very neat tool. It's however missing a single feature that would make it a complete alternative for AWS/Azure notification solutions, and that is Push API support https://developer.mozilla.org/en-US/docs/Web/API/Push_API.

Any plans on enabling the server to push events to web clients? The goal is to get around the current limitation of the UI client, that needs to remain open to receive events.

@binwiederhier binwiederhier added enhancement New feature or request server Relates to the main binary (server or client) labels Apr 6, 2022
@binwiederhier
Copy link
Owner

I like the idea, and I vaguely remember looking into this a while ago. I don't quite know why I didn't pursue it further. I'll investigate it eventually.

@binwiederhier
Copy link
Owner

current limitation of the UI client, that needs to remain open to receive events.

To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.

220406 15-50-42 Selection 001

@remon-nashid
Copy link
Author

To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.

With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing.

@binwiederhier would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow? Thanks!

@remon-nashid
Copy link
Author

remon-nashid commented Apr 6, 2022

Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams.

@binwiederhier
Copy link
Owner

With Gmail and Whatsapp, you can receive a desktop notification (think the upper-right corner Mac OS bubble), and once clicked, the website will open in a browser tab. At least that's the behavior I'm currently pursuing.

I am on Ubuntu, so I can't verify that. Can you maybe post a screenshot?

would you please provide some pointers on where such a feature could be plugged in the Ntfy codebase? is there any example I could follow?

This is tricky. I don't know anything about the server side implementation for the Push API. I don't know if it's based on HTTP/WebSockets/grpc/etc. I tried to look for libraries, but there are no popular libraries for Go, and the Push API seems like a more or less abandoned (or at least not widely used) standard, at least that's what it seemed in my 2min research.

As for where to plug it in: https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L185-L215 -- My assumption is that it's another server on a different port. I honestly don't know though, because I can't for the life of me find out what protocol it uses.

Basically what I'm aiming to accomplish, is sending notifications to browsers, even when the website is closed, and only to the browsers that have subscribed to a certain topic. ie pubsub + Notifications API (which ntfy excels at) + Push API instead of Web Sockets or HTTP Streams.

Yeah I understand :-D

@binwiederhier
Copy link
Owner

Okay I read parts of the Web Push API spec, and it looks like I was wrong. Apparently the browsers provide a push service, so Firefox/Mozilla would provide https://updates.push.services.mozilla.com/wpush for instance, and the ntfy server would just have to forward the push to that.

So there is no additional server running that the browser has to connect to. It's all through Mozilla or Google's servers basically. I think in that case it's more similar to Firebase, in that we simply forward messages to the push service (see https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L421). The crypto of the Web Push API is quite complex, which is why I really would want to use a library for it.

I think I may do this because it's fun. But I'm not guaranteeing any timelines.

@karmanyaahm
Copy link
Contributor

https://github.com/SherClockHolmes/webpush-go/ is a pretty good and popular library for this. I think the main obstacle (iirc the last time I looked at the firebase code for ntfy), would be that right now, Firebase keeps track of which device is subscribed to which topic, whereas with WebPush, ntfy would have to keep track of endpoint->topic mappings.

Another advantage of implementing this would be that in addition to ntfy-over-firebase, ntfy-over-unifiedpush would become possible (since WebPush and UnifiedPush are compatible). Self-hosted servers could also have push using some gateways.

@remon-nashid remon-nashid changed the title Push API support Web Push support Apr 8, 2022
@sfkpmr
Copy link

sfkpmr commented Apr 29, 2022

current limitation of the UI client, that needs to remain open to receive events.

To be fair though, I think that's perfectly reasonable, as you'll want to click on the notification anyway when it arrives. I just pin it like I do with Gmail and WhatsApp and such.

220406 15-50-42 Selection 001

Could you point me to how to do this? If I understand you correctly it'll keep me notified if something happens without needing a tab with ntfy open?

@binwiederhier
Copy link
Owner

Right click on the tab -> Pin tab

@binwiederhier
Copy link
Owner

This does need the tab open though, but the tab is pinned, so it's just the small icon. There is no way to receive notifications without an open tab, unless you use the ntfy CLI: https://ntfy.sh/docs/subscribe/cli/#subscribe-to-topics

@sfkpmr
Copy link

sfkpmr commented Apr 29, 2022

Gotcha, hopefully push can help with it.

@mmojadad
Copy link

mmojadad commented Feb 5, 2023

VAPID, which stands for Voluntary Application Server Identity, is a new way to send and receive website push notifications. Your VAPID keys allow you to send web push campaigns without having to send them through a service like Firebase Cloud Messaging (or FCM)

@pinpox
Copy link

pinpox commented May 26, 2023

Any news on this? I looked into how this would be implemened but wasn't able to find any simple tutorials of how to do this in go. i've seen more and more web pages sending these notifications, any hints on how you would add this?
If it's not a huge task I might consider preparing a PR

@nimbleghost
Copy link
Contributor

@pinpox I just started working on this in #751, there are still some open questions about the UX around subscribing to background notifications.

There's also some technical stuff left - handling syncing from accounts and handling re-subscribing if the subscription is broken for whatever reason, and more testing on iOS (notifications work, the PWA needs to be tested more).

@icxes
Copy link

icxes commented May 27, 2023

I've been testing the web push from #751 for a bit now, and it's been working great for me and the few other people that use my server. I was hoping this feature would be implemented soon, so big thanks to you for your work on it @nimbleghost!

@helmut72
Copy link

@nimbleghost
This would be fantastic if it works on iOS. How can I create a Docker image with your patch?

@nimbleghost
Copy link
Contributor

@helmut72 I also added #754, so you can simply checkout the branch run it from there.

e.g. locally: https://docs.ntfy.sh/develop/#build-a-docker-image-only-for-linux

or if using it in a compose file:

  ntfy:
    build:
      context: ../path-to-checked-out-ntfy/
      dockerfile: Dockerfile-build
    command:
      - serve

Please be aware that it's a WIP and I've already changed the db schema without migrations since it isn't released yet, so if you run it you may have to delete your web-push-subscriptions-file database when pulling in updates. Service workers / application caching is also being worked on, which may result in odd behaviour and need a manual unregistration if something breaks (though so far hasn't been a problem).

@helmut72
Copy link

@nimbleghost thanks, I have just used your repo:
https://github.com/nimbleghost/ntfy

But webpush doesn't work. Added my webapp to home screen, check if notifications are enabled for this webapp, but I see the message "notification won't be supported"

@nimbleghost
Copy link
Contributor

@helmut72 are you using the correct branch? It's this one: https://github.com/nimbleghost/ntfy/tree/pwa

but if you are you also need to be serving the web app over https, and have the right config values set (see https://github.com/nimbleghost/ntfy/blob/pwa/docs/config.md#config-options and look for the web push options)

@helmut72
Copy link

@nimbleghost Thanks, I've overseen that required config options. Great, now it works. I just miss that sound/beep and in the notification menu, ntfy is there twice. One entry with, other without sound.

@nimbleghost
Copy link
Contributor

@helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?

@mmojadad
Copy link

I am interest to have such features on web push

  • Segments so subscribers choose their interests
  • Enable GPS location to collect the subscribers GPS locations
  • Add dynamic fields to collect any user's information
  • Localize the subscription page and popup / Design and build your own subscription page ( short code, etc... )
  • Different popup designs, layouts and positions
  • Display offline messages
  • campaign builder

@binwiederhier
Copy link
Owner

@mmojadad you've got the wrong tool here. ntfy is a privacy focused push notification service. Not a marketing platform. We will not add features to collect gps data or any user data, or support for campaigns.

@mmojadad
Copy link

@ binwiederhier Thanks for your clearifications.

@helmut72
Copy link

@helmut72 Nice! Not sure which commit you have, but the latest changes should have both the sound and double notifications fixed. If the sound still doesn't work, can you check your browser console's error messages and tell me what browser you're testing with?

I have played with a commit from today lunch time. Now I've build it about 30min ago. Deleted everything and ntfy isn't there twice in the notification settings. In this single setting there is now no sound entry:

ntfy1

From the menu in the ntfy webapp, where I can choose the sound, sound now plays on my iPhone (and iPad):

ntfy2

But this feels more like a very small sound stream (like from Youtube) and not like a notification sound, because it's also there in the global player of iOS:

ntfy3

@nimbleghost
Copy link
Contributor

@helmut72 Ah you meant for the notification - as far as I can see iOS doesn't support sounds for web push whatsoever at the moment.

@helmut72
Copy link

@nimbleghost Ok, I was unaware of this. Thanks for the info. Then it looks good for me.

@binwiederhier
Copy link
Owner

I am closing this in favor of #346, which is (essentially) a duplicate. @nimbleghost is working on this right now.

@binwiederhier binwiederhier unpinned this issue Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server Relates to the main binary (server or client)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants