Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the optimal way of handling web push notifications with several devices per user?

I have developed a web app: It's a quiz where two users play against each other in turns. So during a match, it's either user A's or user B's turn. I want to use push notifications (using the Web Push API) to inform a user when their opponent has played and it's their turn.

I'm wondering if there is an optimal way to do this using the technologies at hand (service workers, Push API). And if there isn't an ideal solution, what would be a good compromise?

What I ideally want to achieve (probably impossible):

  • users should be notified on all their logged in devices when it's their turn
  • when they have played using one device, the other devices should not notify that it's their turn anymore.

The complications/limitations are:

  • Desktop browsers like Chrome and Firefox deliver the notification only when they are fully running. Dispatched notifications are queued until the browser is started.
  • Apart from setting an expiry time (time_to_live), there is no way to take back a notification once it is dispatched (is that right?)
  • This means that when a user has played several rounds with one device, there are quite a few obsolete notifications on the other devices still waiting to be shown (not good)
  • An additional limitation for Chrome is: You have to show a notification when you receive a push message.
like image 258
Sebastian Avatar asked Dec 05 '25 04:12

Sebastian


1 Answers

The easiest approach is to attach a user ID to each subscription and then reach all the devices that belong to a given user. An user tired of duplicated notifications can always block the notifications on some devices.

Also use the TTL (0 or a few minutes) to automatically drop the notifications on the devices that are not connected.

like image 64
collimarco Avatar answered Dec 08 '25 14:12

collimarco