2013-10-30 21:38:23 +01:00
|
|
|
|
2014-06-29 00:34:59 +02:00
|
|
|
module.exports = function(RED) {
|
|
|
|
"use strict";
|
2018-09-10 17:37:20 +02:00
|
|
|
var notifier = require('node-notifier');
|
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
|
|
|
var image = path.join(__dirname, "/node-red.png");
|
2013-10-30 21:38:23 +01:00
|
|
|
|
2014-06-29 00:34:59 +02:00
|
|
|
function NotifyNode(n) {
|
|
|
|
RED.nodes.createNode(this,n);
|
|
|
|
this.title = n.title;
|
|
|
|
var node = this;
|
2018-09-10 17:37:20 +02:00
|
|
|
|
2016-04-09 19:00:14 +02:00
|
|
|
node.on("input",function(msg) {
|
2018-09-10 17:37:20 +02:00
|
|
|
var title = node.title || msg.topic;
|
|
|
|
if (typeof msg.payload === 'object') {
|
2014-06-29 00:34:59 +02:00
|
|
|
msg.payload = JSON.stringify(msg.payload);
|
|
|
|
}
|
2018-09-10 17:37:20 +02:00
|
|
|
var icon = image;
|
|
|
|
if (msg.icon) {
|
|
|
|
if (fs.existsSync(msg.icon)) { icon = msg.icon; }
|
|
|
|
else { node.error("Bad Icon file: "+msg.icon,msg); }
|
|
|
|
}
|
|
|
|
var icon = msg.icon || image;
|
|
|
|
if (typeof(title) !== 'undefined') {
|
|
|
|
notifier.notify({ message:msg.payload, title:title, icon:icon });
|
2014-06-29 00:34:59 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-09-10 17:37:20 +02:00
|
|
|
notifier.notify({ message:msg.payload, icon:imagefile });
|
2014-06-29 00:34:59 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-30 21:38:23 +01:00
|
|
|
|
2018-09-10 17:37:20 +02:00
|
|
|
RED.nodes.registerType("nnotify",NotifyNode);
|
2014-06-29 00:34:59 +02:00
|
|
|
}
|