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的更多相关文章

  1. C#—ASP.NET:集成极光推送(Push API v3)

    C#—ASP.NET:集成极光推送(Push API v3) 原文地址: https://blog.csdn.net/CXLLLK/article/details/86489994   1.极光推送官 ...

  2. PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (四) -- Push API 和 Pull API

    RabbitMQ 中针对消息的分发提供了 Push API (订阅模式) 和 Pull API (主动获取) 两种模式. 在 PHP 中, 这两种模式分别通过 AMQPQueue 类中的 consum ...

  3. 信鸽推送Push API

    目录 信鸽推送 push API 0. 基本 push 1. 根据 token list,推送到android和ios 2. 推送到android和ios 所有用户 信鸽推送 push API 参考: ...

  4. JPush API client library for C Sharp(极光推送API)

    概述 这是 JPush REST API 的 C# 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能. 对应的 REST API 文档:http://docs.jpush.io/s ...

  5. puppeteer(五)chrome启动参数列表API

    List of Chromium Command Line Switches https://peter.sh/experiments/chromium-command-line-switches/ ...

  6. 推送消息 web push notification

    参考 : https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/   ( step b ...

  7. Gitlab Webhooks, External Services, and API(二)

    一. 使用webhooks webhook 是一个API的概念,并且变得越来越流行.我们能用事件描述的事物越多,webhook的作用范围也就越大.webhook作为 个轻量的事件处理应用,正变得越来越 ...

  8. RabbitMQ.Client API (.NET)中文文档

    主要的名称空间,接口和类 核心API中定义接口和类 RabbitMQ.Client 名称空间: 1 using RabbitMQ.Client; 核心API接口和类 IModel :表示一个AMQP ...

  9. Poloniex API 文档

    Examples PHP wrapper by compcentral: http://pastebin.com/iuezwGRZ Python wrapper by oipminer: http:/ ...

随机推荐

  1. 框架: require.js

    require.js http://www.bootcdn.cn/require.js/ HTML: <div class="container" data-page=&qu ...

  2. 代码:CSS仿制 苹果按钮图标

    首先,先复习一下:CSS的线性渐变.径向渐变 .linear{ background-image:-webkit-linear-gradient(90deg,#f8f8f8 20%,#dae9fa 9 ...

  3. gzip0

    但是Apache是专门为PHP所匹配的,其兼容性最好),类似于IIS.下面我们具体来说说Apache里怎么启用gzip压缩: Apache启用gzip 如果要开启gzip的话,一定要打开下面二个模块. ...

  4. Hive Ntile分析函数学习

    NTILE(n) 用于将分组数据按照顺序切分成n片,返回当前记录所在的切片值 NTILE不支持ROWS BETWEEN,比如 NTILE(2) OVER(PARTITION BY cookieid O ...

  5. JavaScript取消默认控件并添加新控件(DOM编程艺术第11章)

    这一章实现的这个功能我研究了好久,这个思路我感觉已经是现在的我要膜拜的了,我感觉我的逻辑还是有些问题. 第一个问题:vid.height与vid.videoHeight vid.height = vi ...

  6. Oracle服务无法启动,报:Windows无法启动OracleOraDb10g_home1TNSListener服务,错误 1067:进程意外终止。

    运行配置和移植工具中的Net Configuration Assistant,进行监听程序配置.删除配置,然后重新配置. 切记 一定是先删除配置,再重新配置,而不是新建配置. 或者 打开Net Man ...

  7. Docker 在 Linux 平台的安装 以及一些常见命令

    1,添加,清理 yum 源,查看应用列表 1.1,yum install -y epel-release 1.2,yum clean all 1.3,yum list  (可以不运行) 2,安装, 启 ...

  8. springboot 端口号

    1. 读取端口号 2.多端口运行 2.

  9. IUSER 匿名帐户密码获取

    如何获取IUSR帐号和密码呢?有两种方法 1.安装IIS Resources,打开IIS Resources中的Metabase Explorer->机器名->LM->W3SVC-& ...

  10. hive基础操作

    hive --version  查看hive的版本 hive -S -e "set" | grep auto  ##在shell下可以查找属性的状态.小技巧.