如何使用 Node.js 的 web-push 包向多个订阅者发送通知? [英] How to send a notification to multiple subscribers using web-push package of Node.js?
问题描述
我们如何使用 Node.js 的 web-push 包向多个订阅者发送通知?
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.
示例:
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',
}));
}
推荐答案
遗憾的是,Web Push 标准目前不支持向多个订阅者发送通知.
Unfortunately, the Web Push standard currently doesn't support sending a notification to multiple subscribers.
确实,密钥与特定用户有关.如果所有用户共享相同的密钥,则其他人可以读取加密的数据.阅读 [1] 以获得更详尽的解释.
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.
这篇关于如何使用 Node.js 的 web-push 包向多个订阅者发送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!