Created
November 3, 2014 19:48
-
-
Save peregrinogris/4bc89e61a2319daf53af to your computer and use it in GitHub Desktop.
JSConfAR ticket sold notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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