Skip to content

Instantly share code, notes, and snippets.

@lucasbrigida
Last active December 15, 2016 21:02
Show Gist options
  • Select an option

  • Save lucasbrigida/bd8d2040c464e48b80ecfa149b4916ca to your computer and use it in GitHub Desktop.

Select an option

Save lucasbrigida/bd8d2040c464e48b80ecfa149b4916ca to your computer and use it in GitHub Desktop.
notification.js
function N() {
var notify = function(title, options) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert(options.body || "This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(title, options);
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(title, options);
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
};
var grant = function(cb) {
Notification.requestPermission().then(function(result) {
console.log(result);
});
function spawnNotification(theBody,theIcon,theTitle) {
var options = {
body: theBody,
icon: theIcon
};
var n = new Notification(theTitle,options);
}
};
return {
notify: notify,
grant: grant
};
}
function BN() {
var notification = new N(),
socket = io('192.168.0.32:3000');
socket.on('welcome', function(e){
console.log('Conectado ao SalãoVIP Broadcast Service');
});
socket.on('push', function(push){
console.log(push);
notification.notify('SalãoVIP', JSON.parse(push));
});
};
jQuery(function(){
setTimeout(function(){
new BN();
}, 5000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment