WebAPI/SimplePush: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
(fix)
 
(138 intermediate revisions by 12 users not shown)
Line 1: Line 1:
Client Side API
<p style="border:2px solid red;border-radius:5px;background-color:#FFF;box-shadow:5px 5px 10px #888;padding:.5em;text-align:center;text-weight:bold;font-size:120%;">'''For documentation on <b>Using SimplePush in your App</b>, please see [https://developer.mozilla.org/en-US/docs/Web/API/Simple_Push_API the MDN SimplePush Documentation]'''</p>
<pre>


partial interface Navigator {
<p style="border:2px solid red;border-radius:5px;background-color:#FFF;box-shadow:5px 5px 10px #888;padding:.5em;text-align:center;text-weight:bold;font-size:120%;">'''For documentation on <b>the Service</b>, please see [http://mozilla-push-service.readthedocs.org/en/latest/ the Mozilla Push Service Documentation]'''</p>
  Push push;
};


interface Push {
Go here for [[Firefox/Push_Notifications|project page]]


  // registers to receive push notifications for a given topic
[[Category:Web APIs]]
  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
  unsigned long long version;
}
 
</pre>
 
 
<pre>
 
// 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() {}
 
</pre>
 
 
<pre>
 
 
    +---------------+                +-----------------+              +------------------+
    |  Browser    |                |  Push Server  |              |    App Server    |
    +------+--------+                +--------+--------+              +---------+--------+
          |          register()              |                                |
          +---------------------------------->|                                |
          |                                  |                                |
          |          ok                      |                                |
          |<---------------------------------+|                                |
          |                                  |                                |
          |          register successful    |                                |
          |+------------------------------------------------------------------->|
          |                                  |                                |
          |                                  |        Update                  |
          |                                  | <-------------------------------+
          |                                  |        Update                  |
          |                                  | <-------------------------------+
          |          update                  |                                |
          |<----------------------------------+                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
          |                                  |                                |
</pre>

Latest revision as of 00:03, 12 November 2015

For documentation on Using SimplePush in your App, please see the MDN SimplePush Documentation

For documentation on the Service, please see the Mozilla Push Service Documentation

Go here for project page