Added HTML5 Push-Notifications

This commit is contained in:
Tim Windelschmidt 2015-09-05 12:18:35 +02:00
parent 681d24175a
commit 200046b0f1
2 changed files with 68 additions and 36 deletions

View File

@ -4,14 +4,15 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.4",
"connect-flash": "0.1.1",
"net-snmp": "1.1.8",
"redis": "0.8.5",
"underscore": "1.5.2",
"express": "3.4",
"jade": "0.35",
"moment": "2.3.1",
"net-snmp": "1.1.8",
"node-notifier": "^4.2.3",
"redis": "0.8.5",
"socket.io": "0.9.16",
"moment": "2.3.1"
"underscore": "1.5.2"
},
"main": "index"
}

View File

@ -1,7 +1,8 @@
var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);
io = require('socket.io').listen(server),
notifier = require('node-notifier');
var flash = require('connect-flash');
var moment = require('moment');
var SnmpMac = require("./snmp-mac");
@ -58,6 +59,8 @@ var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.30-120");
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
var laststate = false;
snmpMac.on('done', function (res) {
simpleanswer.names = res;
simpleanswer.lastchange = new Date().getTime();
@ -87,10 +90,42 @@ io.configure(function () {
io.set('log level', 0);
});
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
});
function work() {
snmpMac.poll();
ippoll.pollCount();
if (spaceanswer.state.open == true && laststate != true) {
laststate == true;
notifier.notify({
title: 'CTDO - Statusänderung',
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
});
} else if (spaceanswer.state.open == false && lasttaste != false) {
laststate == false;
notifier.notify({
title: 'CTDO - Statusänderung',
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
});
}
}
setInterval(work, 60000);
@ -149,7 +184,3 @@ app.post('/form', routes.form);
app.get('/', routes.index);
server.listen(3000, 'localhost');