node-red-contrib-motechat
Version:
ultranet topic and payload communication
28 lines (26 loc) • 908 B
JavaScript
module.exports = (RED) => {
"use strict"
const { setEi } = require('../lib/mcClient.js')
let isReg = require('../lib/mcClient.js').isRegist
function set(config) {
RED.nodes.createNode(this, config)
const node = this
const { EiName, EiTag, EiLoc } = config
node.on('input', (msg, send, done) => {
send = send || function () { node.send.apply(node, arguments) }
let [name, tag, location] = [
msg.EiName || EiName,
msg.EiTag || EiTag,
msg.EiLoc || EiLoc
]
if (isReg()){
setEi({ name, tag, location }).finally(() => { send(msg) })
}
else{
send([null, "Motechat hasn't registered!"])
}
if (done) done()
})
}
RED.nodes.registerType("set", set)
}