Confirmed users
93
edits
(→API) |
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( | 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( | 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 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 | 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 | 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. | 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( | var req = navigator.pushNotifications.register(); | ||
// success callback | // success callback | ||
req.onsuccess | 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 | req.onerror = function(e) {} | ||
// to unregister, you simply call.. | // to unregister, you simply call.. | ||
req = navigator.pushNotifications.unregister( | 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. | ||
==== | ==== GET /register ==== | ||
Request a new ChannelID. | Request a new ChannelID. | ||
Line 152: | Line 147: | ||
{} | {} | ||
===== Example ===== | ===== Example ===== | ||
DELETE http://push.m.o/ | DELETE http://push.m.o/unregister/foo1234 | ||
--- | --- | ||
{} | {} |