mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
expose send, status, log, warn, error, debug, trace, name, id in setup code of function node
This commit is contained in:
parent
f72903ccc2
commit
5d7a625883
@ -25,6 +25,7 @@ module.exports = function(RED) {
|
||||
} else if (!util.isArray(msgs)) {
|
||||
msgs = [msgs];
|
||||
}
|
||||
if(_msgid === "") _msgid = RED.util.generateId();
|
||||
var msgCount = 0;
|
||||
for (var m=0; m<msgs.length; m++) {
|
||||
if (msgs[m]) {
|
||||
@ -268,7 +269,23 @@ module.exports = function(RED) {
|
||||
var iniScript = null;
|
||||
var iniOpt = null;
|
||||
if (node.ini && (node.ini !== "")) {
|
||||
var iniText = "(async function () {\n"+node.ini +"\n})();";
|
||||
var iniText = `
|
||||
(async function(__send__) {
|
||||
var node = {
|
||||
id:__node__.id,
|
||||
name:__node__.name,
|
||||
log:__node__.log,
|
||||
error:__node__.error,
|
||||
warn:__node__.warn,
|
||||
debug:__node__.debug,
|
||||
trace:__node__.trace,
|
||||
status:__node__.status,
|
||||
send: function(msgs, cloneMsg) {
|
||||
__node__.send(__send__, "", msgs, cloneMsg);
|
||||
}
|
||||
};
|
||||
`+ node.ini +`
|
||||
})(send);`;
|
||||
iniOpt = createVMOpt(node, " setup");
|
||||
iniScript = new vm.Script(iniText, iniOpt);
|
||||
}
|
||||
@ -280,7 +297,9 @@ module.exports = function(RED) {
|
||||
}
|
||||
var promise = Promise.resolve();
|
||||
if (iniScript) {
|
||||
context.send = function(m) { node.send(m); };
|
||||
promise = iniScript.runInContext(context, iniOpt);
|
||||
delete context.send;
|
||||
}
|
||||
|
||||
function processMessage(msg, send, done) {
|
||||
|
Loading…
Reference in New Issue
Block a user