WebAPI/SimplePush: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 19: Line 19:
   PushRegistration[] registrations();
   PushRegistration[] registrations();


   // event MUST be of type PushEvent
   attribute EventHandler onregistered;
   attribute EventHandler onmessage;
   attribute EventHandler onunregistered;
};
};


Line 36: Line 36:


interface PushEvent : Event {
interface PushEvent : Event {
  // enum? one of 'update' or 'register-again'
  DOMString type;


   // this is topic string used when registering for push notifications  
   // this is topic string used when registering for push notifications  
Line 73: Line 75:


// apps can do something like
// apps can do something like
navigator.pushNotification.onmessage = function(e) {
// This handler may be triggered *immediately* after mozSetMessageHandler is called
  e.channelID == This is the topic that is being observed
// so applications should ensure they are ready (UI created, state loaded etc.)
  e.version == This is the current version for this topic
navigator.mozSetMessageHandler('push', {
  handleMessage: function(e) {
    if (e.type == 'register-again')
      // re-issue register() calls
    else if (e.type == 'update') {
      e.channelID == This is the topic that is being observed
      e.version == This is the current version for this topic
    }
  }
});
});




// to register to listen for a notification,
// to register to listen for a notification,
// you simply call push.register and pass a
// you simply call push.register
// topic of interest:
navigator.pushNotifications.register();
 
var req = navigator.pushNotifications.register();




// success callback
// success callback
req.onsuccess = function(e) {
navigator.onregistered = function(e) {
   // post to application server
   // post to application server
   e.target.result.pushEndpoint
   e.target.result.pushEndpoint
Line 93: Line 101:
}
}


req.onerror = function(e) {}
navigator.onerror = function(e) {
  e.type == 'registration-failed' or e.type == 'unregistration-failed'
  e.channelID set in case of unregistration
}


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


req = navigator.pushNotifications.unregister(channelID);
navigator.pushNotifications.unregister(channelID);
req.onsuccess() = function() {}
navigator.onunregistered = function(e) {
req.onerror() = function() {}
  // post to app-server
 
}
</pre>
</pre>


Confirmed users
93

edits

Navigation menu