Skip to content

Instantly share code, notes, and snippets.

@peregrinogris
Created November 3, 2014 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peregrinogris/4bc89e61a2319daf53af to your computer and use it in GitHub Desktop.
Save peregrinogris/4bc89e61a2319daf53af to your computer and use it in GitHub Desktop.
JSConfAR ticket sold notification
function sendNotification(data){
new Notification("Entrada Vendida!", {icon: "http://i.imgur.com/PDqr3ZK.png", body: data.availableRegularTickets + "\n"+data.lastBuyerName.substring(0, 30).ucwords()});
}
function ticketSold(data) {
// Let's check if the user is okay to get some notification
if (Notification.permission === "granted") {
// If it's okay let's create a notification
sendNotification(data);
}
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if (!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
sendNotification(data);
}
});
}
}
var socket = io.connect('https://tickets.jsconfar.com');
socket.on('availability', ticketSold);
console.log('attached');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment