bartbutenaers / node-red-contrib-ui-web-push

A Node-RED widget node to send web push notifications via the dashboard
Apache License 2.0
16 stars 5 forks source link

Unsubscribe mechanism #4

Closed bartbutenaers closed 4 years ago

bartbutenaers commented 4 years ago

If possible find a more standard (without workarounds) way to solve a repetitive subscriptions and unsubscriptions ...

Use case:

  1. A user gets the popup and clicks the "Allow" button, so the service worker will be registered.
  2. Afterwards the user blocks the Node-RED dashboard from sending notifications (via the browser settings) or the service worker is disabled.
  3. And some time after that, the user allows the dashboard again sending notifications.

We cannot detect the unsubscription (2) easily, since not all browsers (e.g. Chrome) don't call the pushsubscriptionchange event.

But we really need to handle the unsubscriptions, because otherwise the subscription list (in Node-RED) will keep growing and the number of inactive subscriptions will keep increasing. Which means will keep sending notifications to inactive subscribers, which will fail anyway ...

It seems that we can only workaround it like this: when the Node-RED flow sends a notification, we will analyse the result. If it failed (http status 410) we will automatically remove the subscription from our list.

That works fine. But when the dashboard is granted again to send notifications (3), our service worker won't be informed (by the browser) about that! To workaround that the service worker will registers itself (every time the 'granted' widget is started) in Node-RED. Unfortunately this is pure overhead, but I don't see another way to let Node-RED flow know that the subscription is active.

bartbutenaers commented 4 years ago

Solved