WebAPI/SimplePush: Difference between revisions

Jump to navigation Jump to search
Line 72: Line 72:
// This handler may be triggered *immediately* after mozSetMessageHandler is called
// This handler may be triggered *immediately* after mozSetMessageHandler is called
// so applications should ensure they are ready (UI created, state loaded etc.)
// so applications should ensure they are ready (UI created, state loaded etc.)
navigator.mozSetMessageHandler('push-register', {
  handleMessage: function(e) {
    // (re)issue register() calls
    // to register to listen for a notification,
    // you simply call push.register
    navigator.pushNotifications.register();
  }
});
navigator.mozSetMessageHandler('push', {
navigator.mozSetMessageHandler('push', {
   handleMessage: function(e) {
   handleMessage: function(e) {
     if (e.type == 'register-again')
     e.channelID == This is the topic that is being observed
      // re-issue register() calls
    e.version == This is the current version for this topic
    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,
// you simply call push.register
navigator.pushNotifications.register();


// to unregister, you simply call..
// to unregister, you simply call..
Confirmed users
93

edits

Navigation menu