【问题标题】:how to send notification to android chrome browser using nodejs?如何使用nodejs向android chrome浏览器发送通知?
【发布时间】:2020-01-22 04:06:33
【问题描述】:

我想从节点 js 向我的 android 设备的 chrome 浏览器发送推送通知。这可能吗?如果是这样,如何实现?提前致谢。

【问题讨论】:

  • 您使用SNS服务发送通知

标签: node.js push-notification web-push


【解决方案1】:

看看漂亮的模块web-push 你需要有GCM API key和VAPID key,第一次生成哪个模块帮你搞定。

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');

祝你好运!

【讨论】:

  • 谢谢迪玛!我尝试了您的解决方案,它适用于我的桌面,但不适用于我的手机的 chrome 浏览器。有什么解决办法吗?
  • this 也是?
猜你喜欢
  • 2016-02-14
  • 2021-10-24
  • 1970-01-01
  • 2014-02-17
  • 2017-02-21
  • 1970-01-01
  • 2023-03-22
  • 2018-04-27
相关资源
最近更新 更多