forked from PLCHome/node-red-contrib-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ads-system.js
42 lines (35 loc) · 1.15 KB
/
ads-system.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
module.exports = function (RED) {
'use strict'
var util = require('util')
var debug = require('debug')('node-red-contrib-ads:adsSystemNode')
function adsSystemNode(config) {
RED.nodes.createNode(this, config)
var node = this
node.adsDatasource = RED.nodes.getNode(config.datasource)
if (node.adsDatasource) {
node.topic = config.topic||''
node.hasTopic = String(node.topic).length > 0
debug('config:',node)
node.onData = function (data){
const msg = {
payload: data
}
if (node.hasTopic) {
msg.topic = node.topic
}
node.send(msg)
debug('onData:','node.id',node.id,'node.type',node.type,'msg',msg)
}
node.adsDatasource.systemRegister(node)
this.on("input", function(msg) {
debug('input:','node.id',node.id,'node.type',node.type,'msg',msg)
node.adsDatasource.systemUpdate(node)
})
node.on('close', function () {
debug('close:','node.id',node.id,'node.type',node.type,'enter')
node.adsDatasource.systemUnregister(node)
})
}
}
RED.nodes.registerType('ADS System', adsSystemNode)
}