嗨,我想从我用聚合物创建的PWA发送网络推送通知,我想使用firebase作为“后端”,但我迷路了,我一直在谷歌搜索,但我找不到一个好的例子来做到这一点…你知道使用这些技术的完整例子吗?
非常感谢。
发布于 2017-11-13 10:51:39
你需要在你的firebase函数中安装web-push:npm install web-push --save
下面是如何初始化库并发送通知的方法。
const webpush = require('web-push');
// VAPID keys should only be generated only once.
const vapidKeys = webpush.generateVAPIDKeys();
webpush.setGCMAPIKey('<Your GCM API Key Here>');
webpush.setVapidDetails(
'mailto:example@yourdomain.org',
vapidKeys.publicKey,
vapidKeys.privateKey
);
// This is the same output of calling JSON.stringify on a PushSubscription
const pushSubscription = {
endpoint: '.....',
keys: {
auth: '.....',
p256dh: '.....'
}
};
webpush.sendNotification(pushSubscription, 'Your Push Payload Text');参考:https://github.com/web-push-libs/web-push
设置web推送here的详细教程
https://stackoverflow.com/questions/46962871
复制相似问题