Javascript 使用聚合物和firebase以及firebase功能的web推送通知

Javascript 使用聚合物和firebase以及firebase功能的web推送通知,javascript,firebase,polymer,google-cloud-functions,polymer-2.x,Javascript,Firebase,Polymer,Google Cloud Functions,Polymer 2.x,嗨,我想从我用polymer创建的PWA发送网络推送通知,我想使用firebase和firebase函数作为“后端”,但我迷路了,我一直在谷歌搜索,但我找不到一个好的例子来做这件事?你知道使用这些技术的完整例子吗 非常感谢。您需要将web推送安装到firebase功能中: npm安装web推送--保存 下面是如何初始化库并发送通知 const webpush = require('web-push'); // VAPID keys should only be generated only o

嗨,我想从我用polymer创建的PWA发送网络推送通知,我想使用firebase和firebase函数作为“后端”,但我迷路了,我一直在谷歌搜索,但我找不到一个好的例子来做这件事?你知道使用这些技术的完整例子吗


非常感谢。

您需要将web推送安装到firebase功能中:
npm安装web推送--保存

下面是如何初始化库并发送通知

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');
const webpush=require('web-push');
//乏味的关键点只能生成一次。
const vapidKeys=webpush.generateVAPIDKeys();
webpush.setGCMAPIKey(“”);
webpush.setVapidDetails(
“邮寄至:example@yourdomain.org',
vapidKeys.publicKey,
私钥
);
//这与在PushSubscription上调用JSON.stringify的输出相同
常量订阅={
端点:“…”,
关键点:{
作者:“……”,
p256dh:“…”
}
};
sendNotification(pushSubscription,“您的推送负载文本”);
参考:

有关设置web推送的详细教程: