Confirmed users
93
edits
No edit summary |
|||
Line 19: | Line 19: | ||
PushRegistration[] registrations(); | PushRegistration[] registrations(); | ||
attribute EventHandler onregistered; | |||
attribute EventHandler | 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. | // This handler may be triggered *immediately* after mozSetMessageHandler is called | ||
// so applications should ensure they are ready (UI created, state loaded etc.) | |||
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 | // you simply call push.register | ||
navigator.pushNotifications.register(); | |||
// success callback | // success callback | ||
navigator.onregistered = function(e) { | |||
// post to application server | // post to application server | ||
e.target.result.pushEndpoint | e.target.result.pushEndpoint | ||
Line 93: | Line 101: | ||
} | } | ||
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.. | ||
navigator.pushNotifications.unregister(channelID); | |||
navigator.onunregistered = function(e) { | |||
// post to app-server | |||
} | |||
</pre> | </pre> | ||