WebAPI/SimplePush: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 10: Line 10:
   // registers to receive push notifications for a given topic
   // registers to receive push notifications for a given topic
   // DOMRequest.result is a PushRegistration in case of success
   // DOMRequest.result is a PushRegistration in case of success
   DOMRequest register(DOMString topic);
   DOMRequest register();


   // registers to stop receiving push notifications for a given topic  
   // registers to stop receiving push notifications for a given topic  
   // DOMRequest.result is a PushRegistration in case of success
   // DOMRequest.result is a PushRegistration in case of success
   DOMRequest unregister(DOMString topic);
   DOMRequest unregister(ChannelID channelID);


   // returns the list of all push registrations for this origin
   // returns the list of all push registrations for this origin
Line 24: Line 24:


interface PushRegistration {
interface PushRegistration {
  // this is the string that was used when calling register()
  DOMString topic;
   // this is the URL to which push notifications from the web application
   // this is the URL to which push notifications from the web application
   // must be sent to.
   // must be sent to.
Line 36: Line 32:
   // this is the push request id that must be sent to the push server with
   // this is the push request id that must be sent to the push server with
   // every push notification update
   // every push notification update
   DOMString pushRequestID;
   DOMString channelID;
 
};
};


Line 43: Line 38:


   // this is topic string used when registering for push notifications  
   // this is topic string used when registering for push notifications  
   DOMString topic;
   DOMString channelID;


   // this is the most current version  
   // this is the most current version  
Line 59: Line 54:
// apps can do something like
// apps can do something like
navigator.pushNotification.onmessage = function(e) {
navigator.pushNotification.onmessage = function(e) {
   e.topic == This is the topic that is being observed
   e.channelID == This is the topic that is being observed
   e.version == This is the current version for this topic
   e.version == This is the current version for this topic
});
});
Line 68: Line 63:
// topic of interest:
// topic of interest:


var req = navigator.pushNotifications.register("topic");
var req = navigator.pushNotifications.register();




// success callback
// success callback
req.onsuccess(e) = function() {
req.onsuccess = function(e) {
   // post to application server
   // post to application server
   e.target.result.pushEndpoint
   e.target.result.pushEndpoint
Line 78: Line 73:
}
}


req.onerror() = function(e) {}
req.onerror = function(e) {}


// to unregister, you simply call..
// to unregister, you simply call..


req = navigator.pushNotifications.unregister("topic");
req = navigator.pushNotifications.unregister(channelID);
req.onsuccess() = function() {}
req.onsuccess() = function() {}
req.onerror() = function() {}
req.onerror() = function() {}
Line 118: Line 113:
* On Errors, calls will return a proper error code, and where permitted, a standard JSON block containing information regarding the error. The contents of this block are not intended for end user display and have yet to be finalized.
* On Errors, calls will return a proper error code, and where permitted, a standard JSON block containing information regarding the error. The contents of this block are not intended for end user display and have yet to be finalized.


==== POST /register ====
==== GET /register ====
Request a new ChannelID.  
Request a new ChannelID.  


Line 152: Line 147:
  {}
  {}
===== Example =====
===== Example =====
  DELETE http://push.m.o/delete/foo1234
  DELETE http://push.m.o/unregister/foo1234
  ---
  ---
  {}
  {}
Confirmed users
93

edits

Navigation menu