Skip to content

Instantly share code, notes, and snippets.

@joshbirk
Created January 31, 2012 17:19
Show Gist options
  • Save joshbirk/1711686 to your computer and use it in GitHub Desktop.
Save joshbirk/1711686 to your computer and use it in GitHub Desktop.
Using Streaming API w/ jQuery And Notifications


 j$ = jQuery.noConflict();


 j$(document).ready(function() {

 j$.cometd.configure({
url:'https://'+window.location.hostname+'/cometd/23.0',
requestHeaders: {"Authorization": "OAuth {!$Api.Session_ID}"}
});
j$.cometd.init();
j$.cometd.subscribe('/topic/AllDogs', function(message) {

 console.log(message);

 flashObject.handleDogData(message.data.sobject,message.data.event.type);

 console.log(window.webkitNotifications.checkPermission());
if (window.webkitNotifications.checkPermission() != 0){return;}
console.log(message.data.sobject.Name + 'has has been '+message.data.event.type)
window.webkitNotifications.createNotification('http://www.salesforce.com/favicon.ico', message.data.sobject.Name, 'has has been '+message.data.event.type).show();

 });

 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment