WebAPI/SimplePush: Difference between revisions
< WebAPI
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
// registers to receive push notifications for a given topic | // registers to receive push notifications for a given topic | ||
DOMRequest register( | DOMRequest register(DOMString topic); | ||
// registers to stop receiving push notifications for a given topic | // registers to stop receiving push notifications for a given topic | ||
DOMRequest unregister( | DOMRequest unregister(DOMString topic); | ||
}; | }; | ||
Revision as of 05:33, 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);
};
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
DOMString version;
}
// 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() {}
// register() will send a request to the
// push server including:
application id making this request
the string token that was passed into the register() call
user auth: TBD, but most probably headless browserid
+---------------+ +-----------------+ +------------------+
| Browser | | Push Server | | App Server |
+------+--------+ +--------+--------+ +---------+--------+
| register() | |
+---------------------------------->| |
| | |
| ok | |
|<---------------------------------+| |
| | |
| register successful | |
|+------------------------------------------------------------------->|
| | |
| | Update |
| | <-------------------------------+
| | Update |
| | <-------------------------------+
| update | |
|<----------------------------------+ |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |