Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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