Copyright © 2013 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
This specification defines a “Push API” that provides webapps with scripted access to server-sent notifications, for simplicity referred to here as push notifications, as delivered by push services. Push services are a way for application servers to send messages to webapps, whether or not the webapp is active in a browser window.
Push notifications may be delivered via various methods, either via standardized protocols (e.g. Server-Sent Events [SSE], the GSM Short Message Service [GSM-SMS], SIP MESSAGE [RFC3428], or OMA Push [OMA-PUSH]), or via browser-specific methods. The specific method to be used by a webapp is either selected by the user through a push service extension, or by the browser. The Push API is defined to promote compatibility with any delivery method.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document was published by the Web Applications Working Group as a Working Draft.
This document is intended to become a W3C Recommendation.
If you wish to make comments regarding this document, please send them to
public-webapps@w3.org
with a Subject: prefix of [push-api]
(subscribe,
archives).
All comments are welcome.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This section is non-normative.
As defined here, push services support delivery of application server messages in the following contexts and related use cases:
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL in this specification are to be interpreted as described in [RFC2119].
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL], as this specification uses that specification and terminology.
The Function
interface represents a function in the
scripting language being used as defined in [HTML5].
The concepts queue a task and fires a simple event are defined in [HTML5].
The terms event handlers and event handler event types are defined in [HTML5].
The Promise interface, the concepts of a resolver, a resolver's fulfill algorithm and a resolver's reject algorithm are defined in [DOM4].
The term push service extension refers to a browser extension enabling push service configuration for the user, and thereby enabling Push API binding to event delivery via the service.
The term webapp refers to a Web application, i.e. an application implemented using Web technologies, and executing within the context of a Web user agent, e.g. a Web browser or other Web runtime environment.
The term application server refers to the server side of a webapp.
The term push notification refers to an indication to a webapp that there is new information for it from the application server, all or part of which MAY be contained in the push notifications itself.
The term push registration refers to each logical channel aimed at delivering push notifications from an application server to a webapp, which is created by a distinct registration of such webapp via this Push API.
The term push service refers to the mechanisms that allow application servers to send push notifications to webapps.
The term push server refers to a system via which a push service is provided.
User agents must not provide Push API access to webapps without the express
permission of the user. User
agents must acquire consent for
permission through a user interface for each call to the
register()
method, unless a prearranged trust relationship
applies.
User agents may support prearranged trust relationships that do not require such per-request user interfaces.
Permissions that are preserved beyond the current browsing session must be revocable.
This section is non-normative.
There are different deployment alternatives to allow application servers to deliver push notifications to webapps. In a typical deployment application servers send a push notification to a Push server, e.g. by a RESTful interface, which in turn sends a push notification to the user agent providing the execution context for the webapp. The user agent then delivers the push notification to the corresponding webapp to which it was addressed.
The push notification MAY include a version number of the latest information available through this push registration, which the webapp may retrieve if not coincident with the latest version it has already retrieved.
The push notification system MUST ensure that the application eventually has the latest version of data on the application server. The push server may lose intermediate notifications or may lose all state, while fulfilling this requirement. In such an event, it will deliver a push-register system message to the application, so that the application may fetch the latest data from the application server.
pushRegistrations = null; function registerPush() { navigator.push.register().then( function(value) { pushRegistrations.push(value); registerWithAppServer(value); }, function(reason) {alert("darn! "+ reason );} ); } function reRegisterPush(pushRegistration) { for (reg in pushRegistrations) { if (pushRegistrations[reg] == pushRegistration) pushRegistrations.splice(reg,1); } registerPush(); } navigator.push.registrations().then( function(registrations) { if (registrations.length == 0) registerPush(); // assume at least one needed else pushRegistrations = registrations; }, function(reason) {alert("darn! "+ reason );} ); function registerWithAppServer(pushRegistration) { var activate = "http://example.com/push/activate?pushRegistrationId="+ encodeURIComponent(pushRegistration.pushRegistrationId)+ "&pushEndpoint="+encodeURIComponent(pushRegistration.pushEndpoint); asyncXHR(activate); // send activation request to application server }; function gotPush(message) { if (message.version == null) { var reset = "http://example.com/push/reset?pushRegistrationId="+ encodeURIComponent(pushRegistration.pushRegistrationId)+ "&pushEndpoint="+encodeURIComponent(pushRegistration.pushEndpoint); asyncXHR(reset); // send reset request to application server } else { if (message.version > last_version) { var getdata = "http://example.com/push/get?pushRegistrationId="+ encodeURIComponent(pushRegistration.pushRegistrationId)+ "&last="+last_version+"¤t="+message.version; gotdata = function(data) { // handle retrieved data } asyncXHR(getdata, gotdata); // send data retrieval request to app server } } } if (navigator.hasPendingMessages("push")) { // do any special pre-processing before push messages are delivered } last_version = null; // initialize last message version navigator.setMessageHandler("push", gotPush); navigator.setMessageHandler("push-register", reRegisterPush); /* Hypothetical end-to-end flow +--------+ +--------+ +--------+ +--------+ | webapp | | user | | push | | app | | | | agent | | server | | server | +--------+ +--------+ +--------+ +--------+ | | | | |-----register------>| | | | | | | | (user accepts) | | | | | | | |<-setup push service->| | | | | | |<---success---------| | | | | | | |<--activate service with PushService attributes----------------->| | | | | | | |<--push notification-| | | | per service API | | | | | | | (match to user agent) | | | | | | |<--push notification--| | | | per service protocol | | | | | | | (match to webapp) | | | | | | |<---system message--| | | | | | | */
PushManager
InterfaceThe PushManager
interface defines the operations that enable webapps to establish access to push services.
interface PushManager {
Promise register ();
Promise unregister (DOMString pushRegistrationId);
Promise registrations ();
};
register
Promise
that will allow the caller to be notified about the
result of the operation.
Promise
registrations
Promise
that will allow the caller to be notified about the
result of the operation.
Promise
unregister
Promise
that will allow the caller to be notified about the
result of the operation.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
pushRegistrationId | DOMString | ✘ | ✘ | Identifies the push registration that the webapp requests to unregister |
Promise
The register
method when invoked MUST run the following steps:
Promise
object and
resolver its associated resolver.
value
argument.
PushRegistration
object providing the details of
the push
registration.
value
argument.
The unregister
method when invoked MUST run the
following steps:
Promise
object and
resolver its associated resolver.
pushRegistrationId
attribute relates to an
active push
registration of the requesting webapp or alternatively that the requesting webapp has permission to
deactivate such push
registration.
value
argument.
pushRegistrationId
attribute.
DOMString
set to the value of the
pushRegistrationId
attribute as the value
argument.
The registrations
method when invoked MUST run the
following steps:
Promise
object and
resolver its associated resolver.
PushRegistration
object per active push
registration associated to the requesting webapp. A length of zero
for
pushRegistrations indicates that there are no registrations.
value
argument.
PushRegistration
InterfaceThe PushRegistration
interface contains information about a specific
channel used by a webapp to
receive push
notifications.
interface PushRegistration {
readonly attribute DOMString pushEndpoint;
readonly attribute DOMString pushRegistrationId;
};
pushEndpoint
of type DOMString, readonly pushRegistrationId
of type DOMString, readonly PushMessage
InterfaceThe PushMessage
interface represents a System Message
related to a received push notification.
interface PushMessage {
readonly attribute DOMString pushRegistrationId;
readonly attribute unsigned long long? version;
};
pushRegistrationId
of type DOMString, readonly version
of type unsigned long long, readonly , nullableversion
is an
integer value that is incremented when new content is available through a
push registration.
So higher values of version
indicate newer content. Note that
the push server may just
notify of the latest version if multiple notification requests have been recieved
from the application server
before the push server is
ready to send a notification. Thus a notification for each version may not be
received by the user agent
and in turn by the webapp.
This attribute MUST return null when the push server has lost track of the state, in order
to indicate the webapp that it
should ask the application server and restore local state.
PushRegisterMessage
InterfaceThe PushRegisterMessage
interface represents a System Message
related to a push registration that is no longer valid
and thus needs to be created again by the webapp by means of a new invocation of the
register
method.
interface PushRegisterMessage {
readonly attribute DOMString pushRegistrationId;
};
pushRegistrationId
of type DOMString, readonly A webapp that wants to be able to make use of the capabilities provided by this API needs to be registered to the following System Messages:
name | type | description |
---|---|---|
push |
PushMessage |
Incoming push notification |
push-register |
PushRegisterMessage |
Request to register a specific push registration |
Upon receiving a push notification from the push server the User agent MUST run the following steps:
PushMessage
object
pushRegistrationId
of the
PushMessage
object to the identifier of the push registration to
which the push
notification was sent version
of the
PushMessage
object to the version attribute indicated in
the push
notification, if provided
push
including the
previous PushMessage
object to the webapp to which the push notification relates
Upon any event that makes a push registration no longer valid, e.g. push server database failure, the User agent MUST run the following steps:
PushRegisterMessage
object
pushRegistrationId
of the
PushRegisterMessage
object to the identifier of the push registration that
is no longer valid
push-register
including the previous PushRegisterMessage
object to the
webapp to which the push registration
relates
If a push notification or an indication about a push registration being no longer valid is received and the webapp is not active in a browser window, the User agent must invoke the webapp if possible, and deliver the push notification to it. Examples of cases in which webapps should be invokable include:
PushRegistration
object was created.
The editors would like to express their gratitude to the Mozilla and Telefónica Digital teams implementing the Firefox OS Push Notification solution and specially to Doug Turner, Nikhil Marathe, Fernando R. Sela, Guillermo López, Antonio Amaya, José Manuel Cantera and Albert Crespell, for their technical guidance, implementation work and support.