Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7a7369d
Incoming msgs have now _socketId property added on reception. Outgoin…
alberto-schena-gizero Jul 1, 2020
f74c99a
Safety check
alberto-schena-gizero Jul 1, 2020
d93f266
Now "on connect" messages contain the _socketid property.
alberto-schena-gizero Jul 2, 2020
86be503
Added node to signal client disconnection (with _socketid property).
alberto-schena-gizero Jul 2, 2020
ccc668e
Corrected node tooltip description
alberto-schena-gizero Jul 2, 2020
37ae9a5
Added cookies to new connection messages
alberto-schena-gizero Jul 3, 2020
641715b
Added multicast mode for message sending
alberto-schena-gizero Jul 3, 2020
58a25c4
Switched back to cookie single string representation
alberto-schena-gizero Jul 3, 2020
8d70778
Fix due to node-red array handling within global variables.
alberto-schena-gizero Jul 3, 2020
003897a
Switched back to client node and made it handle both connections and …
alberto-schena-gizero Jul 14, 2020
31768d5
Added _socketid property to yad-switch incoming messages.
alberto-schena-gizero Jul 20, 2020
8b83c88
Added _socketid in yad-switch feedback (unicast) messages
alberto-schena-gizero Jul 22, 2020
a00f50b
New release
Jul 22, 2020
046fd66
Now client nodes can notify when users [dis]connect from/to any dashb…
alberto-schena-gizero Jul 31, 2020
63fcebb
Added cookies to clientDisconnected messages
alberto-schena-gizero Aug 13, 2020
479c989
Improved message in DevTool console
alberto-schena-gizero Oct 9, 2020
ea59a3f
Added socket [dis]connection callbacks on YAD-managed elements
alberto-schena-gizero Oct 9, 2020
73ce842
Set httpNodeRoot as socket.io cookie path
alberto-schena-gizero Oct 28, 2020
7248f00
Spike: Cannot read property 'emit' of undefined
alberto-schena-gizero Oct 28, 2020
34f050f
Removed trailing slash in cookiePath
alberto-schena-gizero Oct 28, 2020
ad654e7
added support for homonymous yad elements
alberto-schena-gizero Feb 18, 2021
33b03f2
added user agent to [dis]connection messages
alberto-schena-gizero Feb 23, 2021
ac7663f
added user agent to [dis]connection messages
alberto-schena-gizero Feb 23, 2021
e0dad59
removed warning message
alberto-schena-gizero Feb 23, 2021
0558e77
added support to message-conveyed element id
alberto-schena-gizero Feb 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions coreWidgets/yad-toggle-switch/yad-switch-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,36 @@ module.exports = function(RED) {

yadNode.prototype.recMessage = function(m) {
var node = this;
var msg = {};
var msg = {
_socketid: m._socketid
};
if(node.config.topic !== '') {
msg.topic = node.config.topic;
}
if(m.payload === true) {
node.sendBackToUIHelper(true);
node.sendBackToUIHelper(true, m._socketid);
msg.payload = RED.util.evaluateNodeProperty(node.config.onValue, node.config.onValueType, node);
node.send(msg);
} else if(m.payload === false) {
node.sendBackToUIHelper(false);
node.sendBackToUIHelper(false, m._socketid);
msg.payload = RED.util.evaluateNodeProperty(node.config.offValue, node.config.offValueType, node);
node.send(msg);
}
}

yadNode.prototype.sendBackToUIHelper = function(state) {
yadNode.prototype.sendBackToUIHelper = function(state, _socketid) {
var node = this;
if(!node.config.decoupled) {
if(node.config.replay === true) {
node.yad.sendMessage(node, {payload: state}, 'state');
node.yad.sendMessage(node, {
payload: state,
_socketid
}, 'state');
} else {
node.yad.sendMessage(node, {payload: state});
node.yad.sendMessage(node, {
payload: state,
_socketid
});
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions nodes/yad-client-node.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2020 cinhcet

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -21,7 +21,7 @@
defaults: {
yad: {
value: "",
required: true,
required: false,
type: "yad-configuration"
},
name: {
Expand All @@ -32,7 +32,7 @@
outputs: 1,
icon: "yad-icon.svg",
label: function() {
return this.name || "ui client connect";
return this.name || "client node";
},
paletteLabel: 'client node'
});
Expand All @@ -50,5 +50,7 @@
</script>

<script type="text/x-red" data-help-name="yad-client-node">
<p>Emits message if new ui client connects</p>
<p>Emits messages when UI clients connect to, or disconnect from, the configured dashboards.</p>
<p>If you specify a YAD Configuration, the node will notify about user activity regarding to the related dashboard only.
Otherwise, the node will notify about any configured dashboard.</p>
</script>
45 changes: 36 additions & 9 deletions nodes/yad-client-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,44 @@ module.exports = function(RED) {
RED.nodes.createNode(this, config);
var node = this;
node.config = config;
node.yad = RED.nodes.getNode(node.config.yad);

function newClientConnectedCallback() {
node.send({payload: 'newClientConnected'});

function registerClientEventHandlers(yadConfiguration) {
function sendConnectionMessage(message) {
node.send({
payload: 'newClientConnected',
_dashboard: yadConfiguration.name,
...message
});
}

function sendDisconnectionMessage(message) {
node.send({
payload: 'clientDisconnected',
_dashboard: yadConfiguration.name,
...message
});
}

yadConfiguration.eventEmitter.on('newClientConnected', sendConnectionMessage);
yadConfiguration.eventEmitter.on('clientDisconnected', sendDisconnectionMessage);

node.on('close', function() {
yadConfiguration.eventEmitter.removeListener('newClientConnected', sendConnectionMessage);
yadConfiguration.eventEmitter.removeListener('clientDisconnected', sendDisconnectionMessage);
});
}

node.yad.eventEmitter.on('newClientConnected', newClientConnectedCallback);

node.on('close', function() {
node.yad.eventEmitter.removeListener('newClientConnected', newClientConnectedCallback);
});
if(node.config.yad) {
var yadConfiguration = RED.nodes.getNode(node.config.yad);
registerClientEventHandlers(yadConfiguration);
} else {
RED.nodes.eachNode(function(n) {
if(n.type === 'yad-configuration') {
var yadConfiguration = RED.nodes.getNode(n.id);
registerClientEventHandlers(yadConfiguration);
}
});
}
}

RED.nodes.registerType("yad-client-node", yadNode);
Expand Down
9 changes: 4 additions & 5 deletions nodes/yad-node.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2020 cinhcet

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -25,8 +25,7 @@
type: "yad-configuration"
},
elementID: {
value: "",
required: true
value: ""
},
replayLastMessage: {
value: false
Expand All @@ -42,8 +41,8 @@
outputs: 1,
icon: "yad-icon.svg",
label: function() {
return this.name || this.elementID;
},
return this.name || this.elementID || 'universal node';
},
paletteLabel: 'universal node'
});
</script>
Expand Down
63 changes: 49 additions & 14 deletions nodes/yad.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ module.exports = function(RED) {
var socketIoPath = join(fullPath, 'socket.io');

if(!socketIOInstances.has(node.yadPath)) {
let socketIOInstance = socketIO(server, {path: socketIoPath});
let socketIOInstance = socketIO(server, {
path: socketIoPath,
cookiePath: RED.settings.httpNodeRoot.replace(/\/$/, '') || '/'
});
socketIOInstance.use(function(socket, next) {
if(socket.handshake.xdomain === false) {
return next();
Expand Down Expand Up @@ -105,13 +108,20 @@ module.exports = function(RED) {
node.socketList[socket.id] = socket;

// emit event when new ui client connects
node.eventEmitter.emit('newClientConnected');
node.eventEmitter.emit('newClientConnected', {
_socketid: socket.id,
_cookies: socket.handshake.headers.cookie,
_useragent: socket.handshake.headers['user-agent']
});

// receive message from ui
socket.on('toNR', function(msg) {
if(msg.hasOwnProperty('elementID') && msg.hasOwnProperty('msg')) {
if(node.elementNodes.hasOwnProperty(msg.elementID)) {
node.elementNodes[msg.elementID].recMessage(msg.msg);
if(msg.hasOwnProperty('msg')) {
msg.msg._socketid = socket.id;
if(msg.hasOwnProperty('elementID')) {
if(node.elementNodes.hasOwnProperty(msg.elementID)) {
node.elementNodes[msg.elementID].recMessage(msg.msg);
}
}
}
});
Expand Down Expand Up @@ -140,6 +150,13 @@ module.exports = function(RED) {

socket.on('disconnect', function() {
delete node.socketList[socket.id];

// emit event when ui client disconnects
node.eventEmitter.emit('clientDisconnected', {
_socketid: socket.id,
_cookies: socket.handshake.headers.cookie,
_useragent: socket.handshake.headers['user-agent']
});
});
});

Expand Down Expand Up @@ -168,15 +185,33 @@ module.exports = function(RED) {

yad.prototype.sendMessage = function(elementNode, msg, replayMsgId) {
var node = this;
var sendMsg = {elementID: elementNode.elementID, msg: msg, type: 'msg'};
node.io.emit('fromNR', JSON.stringify(sendMsg));

// optional save message for replay when a new client connects
if(replayMsgId) {
if(typeof replayMsgId === 'string') {
elementNode.replayMessages[replayMsgId] = msg;
var sendMsg = {elementID: msg._elementid || elementNode.elementID, msg: msg, type: 'msg'};
if(!sendMsg.elementID) {
elementNode.warn('Element ID must either be configured in node or specified by msg._elementid');
} else {
if(msg.hasOwnProperty('_socketid')) {
(Array.isArray(msg._socketid) ? msg._socketid : [msg._socketid])
.forEach(function(socketId) {
if(typeof socketId === 'string') {
const socket = node.socketList[socketId];
if(socket) {
socket.emit('fromNR', JSON.stringify(sendMsg));
}
} else {
elementNode.warn('_socketid must be a string or a string array');
}
});
} else {
elementNode.warn('replayMsgId is not a string');
node.io.emit('fromNR', JSON.stringify(sendMsg));
}

// optional save message for replay when a new client connects
if(replayMsgId) {
if(typeof replayMsgId === 'string') {
elementNode.replayMessages[replayMsgId] = msg;
} else {
elementNode.warn('replayMsgId is not a string');
}
}
}
}
Expand Down Expand Up @@ -276,7 +311,7 @@ module.exports = function(RED) {
node.copySrcFile('../templates/bareboneDashboardTemplate/index.html');
node.copySrcFile('../templates/bareboneDashboardTemplate/widgets.js');
node.copySrcFile('../templates/bareboneDashboardTemplate/style.css');

node.createManifestJSON();

} catch(e) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-component-dashboard",
"version": "1.0.0",
"version": "1.0.1",
"description": "dashboard",
"keywords": [
"node-red",
Expand All @@ -15,7 +15,7 @@
"parcel-bundler": "^1.11.0",
"yad-icons-iconify": "cinhcet/yad-icons-iconify",
"lit-element": "^2.3.1",
"justgage": "^1.3.5"
"justgage": "^1.3.5"
},
"node-red": {
"nodes": {
Expand Down
Loading