Added HTML5 Push-Notifications
This commit is contained in:
parent
681d24175a
commit
931cd29833
|
@ -0,0 +1,54 @@
|
||||||
|
var notifier = require('node-notifier');
|
||||||
|
|
||||||
|
var Notification = function (currentstate) {
|
||||||
|
|
||||||
|
this.notificate = function () {
|
||||||
|
|
||||||
|
notifier.on('click', function (notifierObject, options) {
|
||||||
|
// Happens if `wait: true` and user clicks notification
|
||||||
|
});
|
||||||
|
|
||||||
|
notifier.on('timeout', function (notifierObject, options) {
|
||||||
|
// Happens if `wait: true` and notification closes
|
||||||
|
});
|
||||||
|
|
||||||
|
if (currentstate == true && laststate != true) {
|
||||||
|
laststate == true;
|
||||||
|
notifier.notify({
|
||||||
|
title: 'CTDO - Status',
|
||||||
|
message: 'Der Chaostreff Dortmund ist nun offen.',
|
||||||
|
icon: path.join('public/img/green.png'), // absolute path (not balloons)
|
||||||
|
sound: true, // Only Notification Center or Windows Toasters
|
||||||
|
wait: true // wait with callback until user action is taken on notification
|
||||||
|
}, function (err, response) {
|
||||||
|
// response is response from notification
|
||||||
|
});
|
||||||
|
console.log("State changed to Open");
|
||||||
|
} else if (currentstate == false && laststate != false) {
|
||||||
|
laststate == false;
|
||||||
|
notifier.notify({
|
||||||
|
title: 'CTDO - Status',
|
||||||
|
message: 'Der Chaostreff Dortmund ist nun geschlossen.',
|
||||||
|
icon: path.join('public/img/red.png'), // absolute path (not balloons)
|
||||||
|
sound: true, // Only Notification Center or Windows Toasters
|
||||||
|
wait: true // wait with callback until user action is taken on notification
|
||||||
|
}, function (err, response) {
|
||||||
|
// response is response from notification
|
||||||
|
});
|
||||||
|
console.log("State changed to Close");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Notification;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"net-snmp": "1.1.8",
|
"net-snmp": "1.1.8",
|
||||||
"redis": "0.8.5",
|
"redis": "0.8.5",
|
||||||
"underscore": "1.5.2",
|
"underscore": "1.5.2",
|
||||||
|
"node-notifier": "^4.2.3",
|
||||||
"jade": "0.35",
|
"jade": "0.35",
|
||||||
"socket.io": "0.9.16",
|
"socket.io": "0.9.16",
|
||||||
"moment": "2.3.1"
|
"moment": "2.3.1"
|
||||||
|
|
|
@ -6,6 +6,7 @@ var flash = require('connect-flash');
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
var SnmpMac = require("./snmp-mac");
|
var SnmpMac = require("./snmp-mac");
|
||||||
var IpPoll = require("./ip-poll");
|
var IpPoll = require("./ip-poll");
|
||||||
|
var Notification = require("./notification");
|
||||||
var Flukso = require("./flukso");
|
var Flukso = require("./flukso");
|
||||||
var routes = require("./routes");
|
var routes = require("./routes");
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
@ -57,6 +58,7 @@ var usercountanswer = { at: 0, current_value: 0, datapoints: [
|
||||||
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
|
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
|
||||||
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.30-120");
|
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.30-120");
|
||||||
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
||||||
|
var notification = new Notification(spaceanswer.state.open)
|
||||||
|
|
||||||
snmpMac.on('done', function (res) {
|
snmpMac.on('done', function (res) {
|
||||||
simpleanswer.names = res;
|
simpleanswer.names = res;
|
||||||
|
@ -91,6 +93,7 @@ io.configure(function () {
|
||||||
function work() {
|
function work() {
|
||||||
snmpMac.poll();
|
snmpMac.poll();
|
||||||
ippoll.pollCount();
|
ippoll.pollCount();
|
||||||
|
notification.notificate(spaceanswer.state.open);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(work, 60000);
|
setInterval(work, 60000);
|
||||||
|
|
Loading…
Reference in New Issue