我过去几个小时一直在阅读关于Push Notification API和Web Notification API的内容.我还发现Google和Apple分别通过GCM和APNS免费提供推送通知服务.
我试图了解我们是否可以使用桌面通知向浏览器实施推送通知,我相信这是Web Notification API所做的.我在这里和这里看到了关于如何为Chrome做这件事的谷歌文档.
现在仍然无法理解的是:
我相信在一个答案中回答的所有问题都可以帮助很多有类似困惑的人.
javascript web-notifications google-cloud-messaging web-push push-api
我有一个简单的场景,只要从服务器生成,就可以在移动设备上接收通知.
我知道这个工具可以在原生iOS应用程序和Android中使用,但我试图避免本机路径.我想要的是:
我知道有可能存在服务器端事件/ Web套接字,但是Web应用程序可以模拟推送通知功能吗?
谢谢
在实施chrome推送通知时,我们从服务器获取最新的更改.在这样做时,服务工作者正在显示带有该消息的额外通知
此网站已在后台更新
已经尝试过这里发布的建议
https://disqus.com/home/discussion/html5rocks/push_notifications_on_the_open_web/
但到现在为止找不到任何有用的东西.有什么建议吗?
主要目标是增加站点发送Web通知的能力,以弹出系统通知,以使用Html5 Push API和服务工作人员提醒用户.不使用SignalR,它只能在打开网站时运行客户端脚本.也应该是,如果网站被关闭,如提及发布通知的能力在这里 -这是可能的.
这是关于Push API的好文章并提供了很好的示例 但是它使用NodeJS作为服务器和web-push组件来向通知服务发送请求.
找不到任何.NET示例.我想到了两个解决方法.
首先,是基于关于服务器的Push API文章说明从头开始编写所有内容:
当您发送没有数据的推送消息时,您只需使用HTTP POST请求将其发送到端点URL.但是,当推送消息包含数据时,您需要对其进行加密,这是一个非常复杂的过程.
其次,是使用AspNetCore.NodeServices(关于它的文章)来执行node.js脚本文件
还有更多解决方案吗?也许存在现成的解决方案?
经过学科研究
3例:
new Notification('Message')
它变得复杂了.怎么了?
可能的解决方案:
对于1和2个案例找到了此存储库.认为这是一个很好的前端解决方案,具有良好的后备支持.对于3个案例仍然不知道该怎么做.
当前解决方案 补充:2017-11-22
从文档中我可以看出Push API和Server Sent Events 都是半双工但为什么两种不同的技术具有相同的功能?Push API中有更重要的东西吗?
html5 push-notification server-sent-events web-push push-api
我目前正致力于服务工作者在浏览器中处理推送通知.目前我有这个"SW注册失败错误".有人可以帮忙解决这个问题吗?检查client1.html
并service-worker.js
归档如下:
错误:
SW注册失败,出现错误SecurityError:无法注册ServiceWorker:不支持当前源的URL协议('null').
服务worker.js
console.log('Started', self);
self.addEventListener('install', function(event) {
self.skipWaiting();
console.log('Installed', event);
});
self.addEventListener('activate', function(event) {
console.log('Activated', event);
});
self.addEventListener('push', function(event) {
console.log('Push message received', event);
});
Run Code Online (Sandbox Code Playgroud)
client1.html
<!doctype html>
<html>
<head>
<title>Client 1</title>
</head>
<body>
<script>
if('serviceWorker' in navigator){
// Register service worker
navigator.serviceWorker.register('service-worker.js').then(function(reg){
console.log("SW registration succeeded. Scope is "+reg.scope);
}).catch(function(err){
console.error("SW registration failed with error "+err);
});
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有一个Web应用程序.我想使用HTML 5内置通知API在用户位于特定页面时从服务器执行推送通知.可能吗?
我正在实现Webpush ruby gem以向我网站的用户发送推送通知.
服务器代码:
Webpush.payload_send({
message: notification.message,
url: notification.url, # I can't figure out how to access this key
id: notification.id, # or this key from the service worker
endpoint: endpoint,
p256dh: p256dh_key,
vapid: vapid_keys,
ttl: 24 * 60 * 60,
auth: auth_key,
})
Run Code Online (Sandbox Code Playgroud)
我在客户端设置了一个服务工作者来显示通知并使其可单击.
self.addEventListener("push", function (event) {
var title = (event.data && event.data.text()) || "New Message";
event.waitUntil(
self.registration.showNotification(title, {
body: "New push notification",
icon: "/images/logo@2x.png",
tag: "push-notification-tag",
data: {
url: event.data.url, // This is returning null …
Run Code Online (Sandbox Code Playgroud) 我一直在做一个关于如何使用web-push节点模块在Chrome上发送网络推送通知的谷歌教程.
问题是,本教程还提供了一个配套服务器应用程序,您应该使用它来测试从服务器向客户端发送推送通知.
但是,在配套应用程序中,甚至在我的本地计算机上使用web-push cli时,在尝试发送通知时,我收到" 未经授权的注册 "错误.在网上找不到任何关于这个错误的信息 - 我做错了什么/缺少什么?
$ web-push send-notification --endpoint=https://fcm.googleapis.com/fcm/send/<<endpoint-key>>
Error sending push message:
{ [WebPushError: Received unexpected response code]
name: 'WebPushError',
message: 'Received unexpected response code',
statusCode: 400,
headers:
{ 'content-type': 'text/html; charset=UTF-8',
date: 'Fri, 25 Nov 2016 08:54:08 GMT',
expires: 'Fri, 25 Nov 2016 08:54:08 GMT',
'cache-control': 'private, max-age=0',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block',
server: 'GSE',
'alt-svc': 'quic=":443"; ma=2592000; v="36,35,34"',
'accept-ranges': 'none',
vary: 'Accept-Encoding',
connection: 'close' },
body: '<HTML>\n<HEAD>\n<TITLE>UnauthorizedRegistration</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" …
Run Code Online (Sandbox Code Playgroud) google-chrome push-notification google-cloud-messaging web-push