WebAPI/SimplePush: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<code>
<pre>


// all notifications will be sent to the system message handler.
// all notifications will be sent to the system message handler.
Line 44: Line 44:
user auth:  TBD, but most probably headless browserid
user auth:  TBD, but most probably headless browserid


</code>
</pre>

Revision as of 23:26, 1 November 2012


// 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() {

   // url of the push server endpoint to
   // post new version number
 
  e.target.result.pushEndpoint
}

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