@gregoriusrippenstein/node-red-contrib-introspection 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/nodes/60-client-code.html +44 -0
- package/nodes/60-client-code.js +23 -2
- package/package.json +1 -1
- /package/{icons → nodes/icons}/subflow.svg +0 -0
package/README.md
CHANGED
|
@@ -91,14 +91,15 @@ Send a flow to another Node-RED instance. This will replace **any existing** flo
|
|
|
91
91
|
|
|
92
92
|
### ClientCode
|
|
93
93
|
|
|
94
|
-
ClientCode is a node for executing client side, i.e., in the editor, Javascript code triggered by a server side event. Any code that can be executed in the browseer console can be executed in the ClientCode node.
|
|
94
|
+
ClientCode is a node for executing client side, i.e., in the editor, Javascript code triggered by a server side event. Any code that can be executed in the browseer console can be executed in the ClientCode node. A ClientCode node can also send a message back to the server using `node.send(...)` which becomes the server side output of the node.
|
|
95
95
|
|
|
96
|
-
The context
|
|
96
|
+
The context in which the code is exected includes:
|
|
97
97
|
|
|
98
98
|
- `payload` which is the the `msg.payload` value
|
|
99
99
|
- `topic` which is the `msg.topic` value
|
|
100
|
+
- `node.send(payload)` where `payload` becomes the output the node on the server side
|
|
101
|
+
- `node.error("msg")` where msg is shown as a notification within the editor
|
|
100
102
|
|
|
101
|
-
For more details, [client side code](https://github.com/gorenje/node-red-contrib-introspection/blob/2f5aca9374b28fcb6890c312f943f913ecb4cfce/nodes/60-client-code.html#L3-L8) with the context and [server side code](https://github.com/gorenje/node-red-contrib-introspection/blob/2f5aca9374b28fcb6890c312f943f913ecb4cfce/nodes/60-client-code.js#L13-L22).
|
|
102
103
|
|
|
103
104
|
## Node-RED Versions
|
|
104
105
|
|
|
@@ -2,7 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
RED.comms.subscribe('introspect:client-code-perform', (event,data) => {
|
|
4
4
|
if ( data.msg == "execfunc" ) {
|
|
5
|
+
|
|
6
|
+
var doSend = (data, nodeid) => {
|
|
7
|
+
$.ajax({
|
|
8
|
+
url: "ClientCode/" + nodeid,
|
|
9
|
+
type: "POST",
|
|
10
|
+
contentType: "application/json; charset=utf-8",
|
|
11
|
+
data: JSON.stringify(data),
|
|
12
|
+
|
|
13
|
+
success: function (resp) {
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
error: function (jqXHR, textStatus, errorThrown) {
|
|
17
|
+
RED.notify("ClientCode Communcation Failure: " +
|
|
18
|
+
nodeid + ": " + textStatus, {
|
|
19
|
+
type: "error",
|
|
20
|
+
id: nodeid,
|
|
21
|
+
timeout: 3000
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var doError = (msg,nodeid) => {
|
|
28
|
+
RED.notify("ClientCode Failed: " + nodeid + ": " + msg, {
|
|
29
|
+
type: "error",
|
|
30
|
+
id: nodeid,
|
|
31
|
+
timeout: 3000
|
|
32
|
+
});
|
|
33
|
+
console.log( "ClientCode: Error with node: " + nodeid +": " +msg);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var nodeid = data.nodeid;
|
|
37
|
+
|
|
38
|
+
var node = {
|
|
39
|
+
send: (dt) => {
|
|
40
|
+
doSend(dt, nodeid)
|
|
41
|
+
},
|
|
42
|
+
error: (mg) => {
|
|
43
|
+
doError(mg, nodeid)
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
5
47
|
var payload = data.payload;
|
|
48
|
+
var topic = data.topic;
|
|
49
|
+
|
|
6
50
|
eval( data.func );
|
|
7
51
|
}
|
|
8
52
|
});
|
package/nodes/60-client-code.js
CHANGED
|
@@ -20,9 +20,30 @@ module.exports = function(RED) {
|
|
|
20
20
|
nodeid: node.id
|
|
21
21
|
})
|
|
22
22
|
);
|
|
23
|
-
|
|
24
|
-
send(msg);
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
25
|
RED.nodes.registerType("ClientCode", ClientCodeFunctionality);
|
|
26
|
+
|
|
27
|
+
RED.httpAdmin.post("/ClientCode/:id",
|
|
28
|
+
RED.auth.needsPermission("ClientCode.write"),
|
|
29
|
+
(req,res) => {
|
|
30
|
+
var node = RED.nodes.getNode(req.params.id);
|
|
31
|
+
if (node != null) {
|
|
32
|
+
try {
|
|
33
|
+
if (req.body && node.type == "ClientCode" ) {
|
|
34
|
+
node.send(req.body);
|
|
35
|
+
res.sendStatus(200);
|
|
36
|
+
} else {
|
|
37
|
+
res.sendStatus(404);
|
|
38
|
+
}
|
|
39
|
+
} catch(err) {
|
|
40
|
+
res.sendStatus(500);
|
|
41
|
+
node.error("ClientCode: Submission failed: " +
|
|
42
|
+
err.toString())
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
res.sendStatus(404);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
28
49
|
}
|
package/package.json
CHANGED
|
File without changes
|