PushAPI的推送服务URL是怎么设置的?
How is the Push API's push service URL set?
Push API 将推送服务定义为
a system that allows application servers to send push messages to a webapp.
通过不带任何参数调用 serviceWorkerRegistration .pushManager.subscribe()
创建服务订阅。
这个推送服务的URL是如何配置的?我本来希望 .subscribe()
为服务采用 URL 参数。
The Push API 的姊妹规范 Generic Event Delivery Using HTTP Push 说:
push service: This resource is used to create push message subscriptions (see Section 3). A URL for the push service is configured into user agents.
但它没有指定如何进行此配置。
the second document you cite 中的这句话回答了问题:
This document intentionally does not describe how a push service is
discovered. Discovery of push services is left for future efforts, if
it turns out to be necessary at all. User agents are expected to be
configured with a URL for a push service.
目前,浏览器附带了一些特定推送服务的内置知识,例如 Chrome 中的 GCM。在 HTMLRocks 的 Push Notifications on the Open Web 文章中提到了这一点:
Chrome uses GCM to handle the sending and delivery of push messages.... Other browsers are free to use any push service...
但是看看浏览器将来是否会开放会很有趣,这样,正如您所建议的,我们可以在 subscribe
.[=15= 的参数中指定我们自己选择的服务]
你先用navigator.serviceWorker.register('/some-service-worker.js')
注册了一个service worker,然后你调用serviceWorkerRegistration .pushManager.subscribe()
的时候这个seriveceWorkerRegistration
指的就是你刚注册的service worker
最好用一个例子来证明这一点:
navigator.serviceWorker.register('/some-service-worker.js').then(function() {
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true}).then(function() {/*...*/});
});
});
Push API 将推送服务定义为
a system that allows application servers to send push messages to a webapp.
通过不带任何参数调用 serviceWorkerRegistration .pushManager.subscribe()
创建服务订阅。
这个推送服务的URL是如何配置的?我本来希望 .subscribe()
为服务采用 URL 参数。
The Push API 的姊妹规范 Generic Event Delivery Using HTTP Push 说:
push service: This resource is used to create push message subscriptions (see Section 3). A URL for the push service is configured into user agents.
但它没有指定如何进行此配置。
the second document you cite 中的这句话回答了问题:
This document intentionally does not describe how a push service is discovered. Discovery of push services is left for future efforts, if it turns out to be necessary at all. User agents are expected to be configured with a URL for a push service.
目前,浏览器附带了一些特定推送服务的内置知识,例如 Chrome 中的 GCM。在 HTMLRocks 的 Push Notifications on the Open Web 文章中提到了这一点:
Chrome uses GCM to handle the sending and delivery of push messages.... Other browsers are free to use any push service...
但是看看浏览器将来是否会开放会很有趣,这样,正如您所建议的,我们可以在 subscribe
.[=15= 的参数中指定我们自己选择的服务]
你先用navigator.serviceWorker.register('/some-service-worker.js')
注册了一个service worker,然后你调用serviceWorkerRegistration .pushManager.subscribe()
的时候这个seriveceWorkerRegistration
指的就是你刚注册的service worker
最好用一个例子来证明这一点:
navigator.serviceWorker.register('/some-service-worker.js').then(function() {
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true}).then(function() {/*...*/});
});
});