WebAPI/SimplePush: Difference between revisions
< WebAPI
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 81: | Line 81: | ||
</pre> | </pre> | ||
== Server API == | |||
<pre> | |||
</pre> | |||
== Simple event flow == | == Simple event flow == | ||
Revision as of 17:49, 14 November 2012
Client Side API
partial interface Navigator {
Push push;
};
interface Push {
// registers to receive push notifications for a given topic
DOMRequest register(DOMString topic);
// registers to stop receiving push notifications for a given topic
DOMRequest unregister(DOMString topic);
// XXXX should be something like [{topic, pushEndpoint, pushRequestID}]
XXXX registered();
};
interface PushRequestEvent : Event {
// this is the URL to which push notifications from the web application
// must be sent to
DOMString pushEndpoint;
// this is the push request id that must be sent to the push server with
// every push notification update
DOMString pushRequestID;
}
interface PushEvent : Event {
// this is topic string used when registering for push notifications
DOMString topic;
// this is the most current version
unsigned long long version;
}
Client Example
// all notifications will be sent to the system message handler.
navigator.mozSetMessageHandler("push", function(e) {
e.target.result.topic == This is the topic that is being observed
e.target.result.version == This is the current version for this topic
});
// to register to listen for a notification,
// you simply call push.register and pass an
// topic of interest:
var req = navigator.push.register("topic");
// success callback
req.onsuccess(e) = function() {
e.target.result.pushEndpoint
e.target.result.pushRequestID
}
req.onerror() = function(e) {}
// to unregister, you simply call..
req = navigator.push.unregister("topic");
req.onsuccess() = function() {}
req.onerror() = function() {}
Server API
Simple event flow
+---------------+ +-----------------+ +------------------+
| Browser | | Push Server | | App Server |
+------+--------+ +--------+--------+ +---------+--------+
| register() | |
+---------------------------------->| |
| | |
| ok | |
|<---------------------------------+| |
| | |
| register successful | |
|+------------------------------------------------------------------->|
| | |
| | Update |
| | <-------------------------------+
| | Update |
| | <-------------------------------+
| update | |
|<----------------------------------+ |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |