Created
April 6, 2017 03:23
-
-
Save Maras0830/b7120d1a8ff1c304ec69b361357abd6e to your computer and use it in GitHub Desktop.
web 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
var socket_lottery_io = io.connect(location.origin + ':3033'); | |
socket_lottery_io.on('lotteryNotification', function(data) { | |
setLotteryNotification(data); | |
}); | |
function setLotteryNotification(data) { | |
Notification.requestPermission(function(status) { | |
if (status === 'granted') { | |
var notification = new Notification(data.lottery.title); | |
notification.onshow = function() { | |
setTimeout(function() { | |
notification.close(); | |
}, 3000); | |
} | |
notification.onclick = function(event) { | |
event.preventDefault(); | |
window.open(data.url, '_blank'); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment