Push API
【Push API】
The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent.
For an app to receive push messages, it has to have an active service worker. When the service worker is active, it can subscribe to push notifications, using PushManager.subscribe().

subscribe 返回一个pushSubscription.其中PushSubscription.endpoint要发送给服务器,服务器以endpoint为地址,给client发push.it is a good idea to keep your endPoint a secret, so others do not hijack it and abuse the push functionality.
navigator.serviceWorker.register('serviceworker.js').then(
function(serviceWorkerRegistration) {
var options = {
userVisibleOnly: true,
applicationServerKey: applicationServerKey
};
serviceWorkerRegistration.pushManager.subscribe(options).then(
function(pushSubscription) {
console.log(pushSubscription.endpoint);
// The push subscription details needed by the application
// server are now available, and can be sent to it using,
// for example, an XMLHttpRequest.
}, function(error) {
// During development it often helps to log errors to the
// console. In a production environment it might make sense to
// also report information about errors back to the
// application server.
console.log(error);
}
);
});
The service worker will be started as necessary to handle incoming push messages, which are delivered to theServiceWorkerGlobalScope.onpush event handler.
每一个endpoint都是独一无二的。不要泄露,否则其它服务器可以给你的client发push。
当push到来时,全局的onpush属性会被调用。
this.onpush = function(event) {
console.log(event.data);
// From here we can write the data to IndexedDB, send it to any open
// windows, display a notification, etc.
}
参考:https://developer.mozilla.org/en-US/docs/Web/API/Push_API
Push API的更多相关文章
- C#—ASP.NET:集成极光推送(Push API v3)
C#—ASP.NET:集成极光推送(Push API v3) 原文地址: https://blog.csdn.net/CXLLLK/article/details/86489994 1.极光推送官 ...
- PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (四) -- Push API 和 Pull API
RabbitMQ 中针对消息的分发提供了 Push API (订阅模式) 和 Pull API (主动获取) 两种模式. 在 PHP 中, 这两种模式分别通过 AMQPQueue 类中的 consum ...
- 信鸽推送Push API
目录 信鸽推送 push API 0. 基本 push 1. 根据 token list,推送到android和ios 2. 推送到android和ios 所有用户 信鸽推送 push API 参考: ...
- JPush API client library for C Sharp(极光推送API)
概述 这是 JPush REST API 的 C# 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能. 对应的 REST API 文档:http://docs.jpush.io/s ...
- puppeteer(五)chrome启动参数列表API
List of Chromium Command Line Switches https://peter.sh/experiments/chromium-command-line-switches/ ...
- 推送消息 web push notification
参考 : https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/ ( step b ...
- Gitlab Webhooks, External Services, and API(二)
一. 使用webhooks webhook 是一个API的概念,并且变得越来越流行.我们能用事件描述的事物越多,webhook的作用范围也就越大.webhook作为 个轻量的事件处理应用,正变得越来越 ...
- RabbitMQ.Client API (.NET)中文文档
主要的名称空间,接口和类 核心API中定义接口和类 RabbitMQ.Client 名称空间: 1 using RabbitMQ.Client; 核心API接口和类 IModel :表示一个AMQP ...
- Poloniex API 文档
Examples PHP wrapper by compcentral: http://pastebin.com/iuezwGRZ Python wrapper by oipminer: http:/ ...
随机推荐
- 【Linux】【JDK】常用命令使用集和裸机配置JDK步骤。
使用Zstack创建完成后的linux服务器,使用SSH登录后,就是一下图,可以查看当前路径下的所有文件. 1.常用的命令: 列出当前文件夹下内容:ll 查看目录中的文件 :ls 创建文件夹:mkdi ...
- IntelliJ IDEA 添加junit插件
一.使用idea做junit测试需要添加junit插件 1.安装插件 File-->settings-->Plguins-->Browse repositories-->输入J ...
- Linux文件浏览命令
1.cat 命令 快快捷查看当前文件的内容.cat适合查看少量信息的文件 cat file 2.more 命令 分页显示文件内容 more file 操作: enter ...
- Hessian 源码简单分析
Hessian 是一个rpc框架, 我们需要先写一个服务端, 然后在客户端远程的调用它即可. 服务端: 服务端通常和spring 做集成. 首先写一个接口: public interface Hell ...
- NIO,OIO,AIO区别
OIO中,每个线程只能处理一个channel(同步的,该线程和该channel绑定). 线程发起IO请求,不管内核是否准备好IO操作,从发起请求起,线程一直阻塞,直到操作完成,如图: NIO中,每个线 ...
- kubectl version报did you specify the right host or port
现象: [root@localhost shell]# kubectl version Client Version: version.Info{Major:", GitVersion:&q ...
- virtualBox下Centos系统扩展LVM磁盘空间
工具准备:下载Gparted Live CD,一个分区管理工具(根据安装的32,64位版本选择对应链接).https://sourceforge.net/projects/gparted/files/ ...
- 重置mysql5.7密码
其实想要重置 5.7 的密码很简单,就一层窗户纸: 1.修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动时不 ...
- WDA-Web Dynpro的POWL(个人对象工作清单)
POWL(Personal Object Worklist) for Web Dynpro 转载地址:https://blogs.sap.com/2013/02/15/powlpersonal-obj ...
- 好玩的Raft动画演示,原理秒懂
关于Raft原理,许多朋友也许不是很明白原理,下面的地址是一个好玩的Raft动画,看完后能够很快的掌握Raft原理: http://thesecretlivesofdata.com/raft/ 动画中 ...