-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathifttt-action.js
executable file
·48 lines (33 loc) · 1.15 KB
/
ifttt-action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
module.exports = function (RED) {
var ifttt = require('ifttt');
var util = require('util');
var utility = require('./utility');
const iftttNodeAction = require('./IFTTTNodeAction');
function IFTTTActionNode(n) {
RED.nodes.createNode(this, n);
var node = this;
// utility.setNodeUnknownStatus(node, undefined);
this.broker = n.broker;
this.brokerNode = RED.nodes.getNode(this.broker);
this.endpoint = n.endpoint;
this.fields = n.fields;
if (this.brokerNode.ifttt) {
const actionInstance = iftttNodeAction.createDefault(node);
node.actionInstance = actionInstance;
node.brokerNode.ifttt.registerAction(actionInstance);
node.on('close', function(done) {
node.brokerNode.ifttt.unregisterAction(actionInstance);
done();
});
} else {
// utility.setNodeRegisterStatus(node, false);
}
// TODO: is this more robust, more dangerous, or no difference to calling node.send directly
this.on("input", function(msg) {
msg.topic = this.endpoint;
node.send(msg);
});
}
RED.nodes.registerType('ifttt-action', IFTTTActionNode);
};