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:/ ...
随机推荐
- 【MySql】【Navicat】下载,安装,激活攻略
来了一家新公司,新电脑,最近申请了DB访问的权限. 公司用的MySql数据库,自己下载了MySql workbench,用的也还不错. 现在下载了一个Navicat,比较讨厌的是,现在很多软件都需要注 ...
- Matplotlib模块
不求甚解,不断学习不断添加... 2017.10.26 1.绘制简单的图像 # 第一步创建显示画面,figure('show')指定图表名称 plt.figure('data') #绘制图像--> ...
- 对datetime日期类型进行序列化的处理
datetime类型序列化 在工作中遇到从数据库中取出来一个datetime类型的数据,在对其进行序列化的过程中,报错python datetime.datetime is not JSON ser ...
- spring事务管理实现原理-源码-传播属性
转载请标识 https://me.csdn.net/wanghaitao4j https://blog.csdn.net/wanghaitao4j/article/details/83625260 本 ...
- 重新配置dbconsole的步骤
重新配置dbconsole的步骤emca -repos dropemca -repos createemca -config dbcontrol dbemctl start dbconsole
- HANA Database SR Basis Setting
HANA Database SR Basis Setting: 1.关闭Hana数据库,把System replication专用的IP地址和相关主机名填写到global.ini配置文件里: #su ...
- 同时安装python2和python3环境
一.同时安装两个环境 https://www.cnblogs.com/zhengyihan1216/p/6011640.html 二.快速安装django: https://blog.csdn.net ...
- MFC 如何在一个窗体中嵌套在另一个窗体中
其中的一个方法是讲子窗体设置为非模式对话框,具体操作为 :设置子窗体的border属性为none,style为 child. 在父窗体中需要用create来实现,具体例子如下. 在父窗体的OnInit ...
- JS中点击事件冒泡阻止
JS中点击事件冒泡阻止 解析: 一个div层'out',内含有一个div层'in'.如下: 两个层都绑定了点击事件,但是点击in层的时候,点击事件会出现冒泡现象,同时也会触发out层的点击事件. 但是 ...
- java自定义抛出的异常Exception
package com.zhanzhuang.exception; public class CustomizeException { public static void main(String[] ...