diff --git a/.gitignore b/.gitignore
index 3c3629e6..6e0120be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
node_modules
+dashboard/dist
\ No newline at end of file
diff --git a/dashboard/dashboard.js b/dashboard/dashboard.js
index 76064e05..b541d322 100644
--- a/dashboard/dashboard.js
+++ b/dashboard/dashboard.js
@@ -3,18 +3,29 @@ let initialized = false;
module.exports = function (RED) {
if (!initialized) {
initialized = true;
- init(RED.httpNode || RED.httpAdmin, RED.settings);
+ init(RED);
}
return {
- testFunc,
+ emitState,
};
};
const path = require("path");
+const socketio = require("socket.io");
const serveStatic = require("serve-static");
-function init(app, settings) {
+let io = null;
+const dashboardState = {};
+
+function init(RED) {
+ const app = RED.httpNode || RED.httpAdmin;
+ const server = RED.server;
+
+ io = socketio(server);
+ initSocket(io);
+
+ // const settings = RED.settings;
// const path = `${settings.httpNodeRoot}${settings.path}`;
// app.use(path, serveStatic(path.join(__dirname, "/dist")));
@@ -22,6 +33,25 @@ function init(app, settings) {
console.log("react dashboard started at /dashboard");
}
-function testFunc() {
- return "test message";
+function initSocket(io) {
+ io.on("connection", (socket) => {
+ socket.emit("initial-value", dashboardState);
+ });
+}
+
+function emitState(state) {
+ const node_id = state.node_id;
+ state.time = Date.now();
+
+ if (dashboardState.hasOwnProperty(node_id)) {
+ dashboardState[node_id].push(state);
+ } else {
+ dashboardState[node_id] = [state];
+ }
+
+ emit(state);
+}
+
+function emit(state) {
+ io.emit("update-value", state);
}
diff --git a/dashboard/nodes/lower-case.html b/dashboard/nodes/lower-case.html
index 6e8cb407..bf8cb370 100644
--- a/dashboard/nodes/lower-case.html
+++ b/dashboard/nodes/lower-case.html
@@ -28,6 +28,16 @@
},
],
});
+
+ console.log("prepared");
+
+ RED.nodes.eachNode((node) => {
+ console.log(node);
+ });
+
+ RED.nodes.eachConfig((node) => {
+ console.log(node);
+ });
},
});
diff --git a/dashboard/nodes/lower-case.js b/dashboard/nodes/lower-case.js
index f0e45c42..618294f4 100644
--- a/dashboard/nodes/lower-case.js
+++ b/dashboard/nodes/lower-case.js
@@ -4,9 +4,7 @@ module.exports = function (RED) {
function LowerCaseNode(config) {
const node = this;
RED.nodes.createNode(node, config);
-
node.on("input", function (msg, send, done) {
- node.log("input has arrived " + dashboard.testFunc());
send =
send ||
function () {
@@ -19,14 +17,7 @@ module.exports = function (RED) {
if (done) done();
});
- node.on("close", function (removed, done) {
- if (removed) {
- node.log("This node has been disabled/deleted");
- } else {
- node.log("This node is being restarted");
- }
- done();
- });
+ node.log("LowerCase Node created");
}
RED.nodes.registerType("lower-case", LowerCaseNode);
diff --git a/dashboard/nodes/test-node.html b/dashboard/nodes/test-node.html
index 44f66273..e3e8f521 100644
--- a/dashboard/nodes/test-node.html
+++ b/dashboard/nodes/test-node.html
@@ -1,7 +1,3 @@
-
-