您好,我想从我用 polymer 创建的 PWA 发送网络推送通知,我想使用带有 firebase 功能的 firebase 作为“后端”,但我迷路了,我一直在谷歌中搜索,但我找不到一个很好的例子这样做吗?您知道使用这些技术的完整示例吗?
非常感谢。
最佳答案
您需要将 web-push 安装到您的 firebase 函数中:
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
设置网络推送的详细教程 here :
关于javascript - 使用具有 firebase 功能的 polymer 和 firebase 的网络推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46962871/