bpolaszek / webpush-bundle

Symfony Bundle: Send WebPush Notifications to your users.
MIT License
66 stars 40 forks source link

Different users same browser #7

Closed tillmon closed 5 years ago

tillmon commented 6 years ago

Is it possible to set up subscriptions for different users on the same browser (i.e. PC)?

bpolaszek commented 6 years ago

On the back-end side, sure. On the front end side, maybe some adjustments would be required in the JS to be sure of that. Have you tried it yet?

tillmon commented 6 years ago

Yes I tried it. I implemented a user change function which updates the active subscription.

https://github.com/tillmon/webpush-bundle

Another way would be to create a new subscription but then you need a separate service worker.

What do you think?

bpolaszek commented 6 years ago

Theorically you shouldn't need a separate service worker. The service worker is just here to show a notification and process actions like clicks, etc, it doesn't handle subscriptions on the domain side.

You don't need to do changes on the back-end side either: a single JS subscription object can be associated to 1 or more users in the persistence layer.

You just need to fire a POST request to /webpush (or call webpush.subscribe() if you use the JS example) as soon as the user logs in.

tillmon commented 6 years ago

But you also need to make sure that the subscription of the previous logged in users is unsubscribed otherwise the user gets notifications which ware not intended for him.

I could not find a simple solution to track user log in/out in JS and use webpush.subscribe() or webpush.unsubscribe().

bpolaszek commented 5 years ago

@tillmon the main advantage of Webpush Notifications is that they work even if the browser is closed / the device is offline, so, regardless of whether the user is logged in or not. If you need to display notifications to the current user logged in, I'm sorry that this library may not be the best option.