WebAPI/SimplePush: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
Client Side API
Client Side API
<pre>
partial interface Navigator {
  Push push;
};
interface Push {
  // registers to receive push notifications for a given topic
  DOMRequest register("topic");
  // registers to stop receiving push notifications for a given topic
  DOMRequest unregister("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;
}
</pre>
<pre>
<pre>


Line 22: Line 61:
req.onsuccess(e) = function() {
req.onsuccess(e) = function() {


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



Revision as of 05:30, 14 November 2012

Client Side API


partial interface Navigator {
  Push push;
};

interface Push {

  // registers to receive push notifications for a given topic 
  DOMRequest register("topic");

  // registers to stop receiving push notifications for a given topic 
  DOMRequest unregister("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                  |                                 |
           |<----------------------------------+                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |
           |                                   |                                 |