Confirmed users
93
edits
(Removed Bob heart attack example.) |
No edit summary |
||
| Line 71: | Line 71: | ||
// Here, we'll register a channel for "email" updates. | // Here, we'll register a channel for "email" updates. | ||
// Channels can be for anything the app would like to get notifications for.</i> | // Channels can be for anything the app would like to get notifications for.</i> | ||
var reqEmail = navigator. | var reqEmail = navigator.push.register(); | ||
reqEmail.onsuccess = function(e) { | reqEmail.onsuccess = function(e) { | ||
emailEndpoint = e.target.result.pushEndpoint; | emailEndpoint = e.target.result.pushEndpoint; | ||
| Line 79: | Line 79: | ||
<i>// We'll also register a second channel for "im", because we're social and all about the socialists. Or something.</i> | <i>// We'll also register a second channel for "im", because we're social and all about the socialists. Or something.</i> | ||
var reqIm = navigator. | var reqIm = navigator.push.register(); | ||
reqIm.onsuccess = function(e) { | reqIm.onsuccess = function(e) { | ||
imEndpoint = e.target.result.pushEndpoint; | imEndpoint = e.target.result.pushEndpoint; | ||
| Line 88: | Line 88: | ||
<i>// Once we've registered, the AppServer can send version pings to the EndPoint. | <i>// Once we've registered, the AppServer can send version pings to the EndPoint. | ||
// This will trigger a 'push' message to be sent to this handler.</i> | // This will trigger a 'push' message to be sent to this handler.</i> | ||
navigator.mozSetMessageHandler('push', | navigator.mozSetMessageHandler('push', function(message) { | ||
if (message.pushEndpoint == emailEndpoint) <i>// Yay! New Email! Steve and blue can dance!</i> | if (message.pushEndpoint == emailEndpoint) <i>// Yay! New Email! Steve and blue can dance!</i> | ||
getNewEmailMessagesFromAppServer(message.version); | getNewEmailMessagesFromAppServer(message.version); | ||
else if (message.pushEndpoint == imEndpoint) <i>// Yay! An IM awaits. I wonder if it's Sam's IM?</i> | else if (message.pushEndpoint == imEndpoint) <i>// Yay! An IM awaits. I wonder if it's Sam's IM?</i> | ||
getNewChatMessagesFromAppServer(); | getNewChatMessagesFromAppServer(); | ||
}); | |||
<i>// to unregister, you simply call..</i> | <i>// to unregister, you simply call..</i> | ||
AppFramework.addEventListener('user-logout', function() { | AppFramework.addEventListener('user-logout', function() { | ||
navigator. | navigator.push.unregister(emailEndpoint); | ||
navigator. | navigator.push.unregister(imEndpoint); | ||
}); | }); | ||
| Line 106: | Line 104: | ||
// will be called very rarely, but application | // will be called very rarely, but application | ||
// should register again when it is called</i> | // should register again when it is called</i> | ||
navigator.mozSetMessageHandler('push-register', | navigator.mozSetMessageHandler('push-register', function(e) { | ||
if (AppFramework.isUserLoggedIn) { | if (AppFramework.isUserLoggedIn) { | ||
setupAppRegistrations(); | setupAppRegistrations(); | ||
| Line 115: | Line 112: | ||
// registrations will be setup due to event handler</i> | // registrations will be setup due to event handler</i> | ||
} | } | ||
}); | |||
=== On the AppServer === | === On the AppServer === | ||
| Line 137: | Line 133: | ||
}; | }; | ||
interface | interface PushManager { | ||
<i>// registers to receive push notifications for a given topic | <i>// registers to receive push notifications for a given topic | ||