【问题标题】:web Push notification using polymer and firebase with firebase functions使用具有 firebase 功能的聚合物和 firebase 的 web 推送通知
【发布时间】:2017-10-26 20:04:34
【问题描述】:

您好,我想从我用聚合物创建的 PWA 发送网络推送通知,我想使用带有 firebase 功能的 firebase 作为“后端”,但我迷路了,我一直在谷歌搜索,但我找不到一个很好的例子这样做 ¿您知道使用这些技术的完整示例吗?

非常感谢。

【问题讨论】:

    标签: javascript firebase polymer google-cloud-functions polymer-2.x


    【解决方案1】:

    您需要将 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

    设置web-push的详细教程here

    【讨论】:

      猜你喜欢
      • 2018-06-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 2020-09-13
      • 1970-01-01
      • 2021-04-12
      • 2021-03-08
      相关资源
      最近更新 更多