-->

How to send a notification to multiple subscribers

2019-07-10 07:16发布

问题:

How we can send a notification to multiple subscribers using web-push package of Node.js?

We can loop through for list of subscribers but it won't be scalable for millions of subscribers.

Example:

for(var myKey in subData) {
    endp   =  subData[myKey]['ENDPOINT'];
    enckey =  subData[myKey]['ENCKEY'];
    webPush.sendNotification(endp, 200, enckey, JSON.stringify({
        title: 'Test Title',
        msg: 'Test Notification',
     }));
}

回答1:

Unfortunately, the Web Push standard currently doesn't support sending a notification to multiple subscribers.

Indeed, the key is related to a specific user. If all users shared the same key, the encrypted data would be readable by others. Read [1] for a more thorough explanation.

I'd suggest implementing a solution that sends notifications in batches, waiting a little between the batches. Usually the notifications don't have to be real-time, so this is usually feasible.