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:/ ...
随机推荐
- 使用NetBox实现ASP网页封装为EXE教程
简单的形容就是把ASP文件打包 成一个EXE文件,并且不需要在调试的机器上安装IIS即可正常调试.如果按照说明书来操作的话,观看比较繁琐,本人为方便大家使用,现制作一个简单的使用教程. 封装过程 1. ...
- [转]【ROLLUP】Oracle分组函数之ROLLUP魅力
原创:http://blog.itpub.net/519536/viewspace-610995 本文通过演示给出Oracle ROLLUP分组函数的用法,体验一下Oracle在统计查询领域中的函数魅 ...
- UVA-714-二分+贪心
题意:K个人复制M本书,每本书有Pi页,要求每个人都能分到至少一本书,如果分到多本书籍,分到的书籍编号是连续的,并且K个人里面分到的书籍总页数最大的那个人总数最小. 如果有多组解,保证 K1 < ...
- 使用swagger 生成 Flask RESTful API
使用swagger 生成 Flask RESTful API http://www.voidcn.com/article/p-rcvzjvpf-e.html swagger官网 https://swa ...
- 安装JavaFX Scene Builder,并配置到Eclipse
转载自:https://www.yiibai.com/javafx/install-javafx-scene-builder-into-eclipse.html 1-JavaFX Scene Buil ...
- 8.Appium的基本使用-3(安装JDK、android-sdk)
1.下载安装JDK :https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html安装教程参 ...
- 36.scrapy框架采集全球玻璃网数据
1.采集目标地址 https://www.glass.cn/gongying/sellindex.aspx 网站比较简单,没什么大的需要注意的问题.2.通过分析测试 https://www.glass ...
- spark partition 理解 / coalesce 与 repartition的区别
一.spark 分区 partition的理解: spark中是以vcore级别调度task的. 如果读取的是hdfs,那么有多少个block,就有多少个partition 举例来说:sparksql ...
- Oracle的基本数据类型(常用)
转自:https://www.2cto.com/database/201810/783959.html 1.字符型 Char 固定长度字符串 占2000个字节 Varchar2 可变长度字符串 占40 ...
- 01_hello world
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...