zolty13
zolty13

Reputation: 2231

Push Manager - on change subscription event

Question

Is there any event I can listen to when new push subscription is added (after subscribe()) to browser or when the subscription is removed (after unsubscribe())?

Scenario

I have react component in which I need update state when push subscription is added or removed in my browser scope. This subscription is added in common script which can be executed before or after my component will be mounted.

Tries

I tried pushsubscriptionchange where sw is ServiceWorkerRegistration object

sw.addEventListener("pushsubscriptionchange", func);

but it does not work at all (func never is executed).

sw.pushManager does not have addEventListener at all.

Upvotes: 2

Views: 549

Answers (1)

waleed
waleed

Reputation: 441

pushsubscriptionchange doesn't seem to get called for me as well.. you just need to save the subscription to your api when they allow. For unsubscribes, the push api let's you know at the time you try to send, so just mark subscriptions as unsubscribed. I know it's not ideal not knowing exactly when they unsubscribed, but better than nothing

Upvotes: 2

Related Questions