Wednesday 20 April 2016

Sending Desktop notification to firefox or mozilla browser


router.all('/sendFireFox.html', function(req, res) {
var dataLoggerDB = req.dataLoggerDB;
var web_subscription = dataLoggerDB.collection("web_subscription");
web_subscription.find().toArray(function(err, items) {
items.forEach(function(item) {
var endpoint=item['ri'];
if(endpoint.indexOf('mozilla')>=0){
var key=item['key'];
key = key.replace(new RegExp(" ", 'g'), "+");
console.log("sending notification to ri "+endpoint);
console.log("sending notification to key "+key);
 webPush.sendNotification(endpoint, 6,key, JSON.stringify({title:'Job alert for you',body:'check new jobs'}))
 .then(function() {
   res.sendStatus(200);
 }, function(err) {
   console.log("err "+err);
   res.sendStatus(500);
 });
}

});
});

});

No comments:

Post a Comment