After a while of trying to emit a message directly (failing to get access to emitSocket()
I found out that is is possible to send a message to myself via node.receive()
For anybody interested or anybody saying I'm doing it all wrong here are some code fragments:
- the $watch code:
$scope.$watch('msg', function(msg) {
if (!msg) { return; } // Ignore undefined msg
if ($scope._data[0]===undefined) {
console.log('uPlot first Message > asking for replay');
$scope.send({payload:"R"});
return;
}
if (msg.hasOwnProperty('fullDataset')) {
console.log('uPlot fullDataset received:',msg);
// do something with the full dataset
});
} else if (isNewDataPoint(msg)){
console.log('uPlot dataPoint received:',msg);
// do something with the datapoint
}
});
- in
beforeSend
trigger let's trigger a message to myself
beforeSend: function (msg, orig) {
if (orig.msg.payload === 'R') {
node.receive(orig.msg);
return;
}
if (orig) {
var newMsg = {};
// do something here if your node emits data
}
},
- in
convert
return the full dataset if a replay is requested
convert: function(value,fullDataset,msg,step) {
if (msg.payload==='R') {
return fullDataset;
}
var conversion = {
updatedValues: {
msg:{
fullDataset : []
}},
newPoint: {},
}
// do your converting business
return conversion;
},
- in
beforeEmit
return the full dataset again (if present and well formed)
beforeEmit: function(msg, fullDataset) {
if (fullDataset && fullDataset.hasOwnProperty('msg') && fullDataset.msg.hasOwnProperty('fullDataset')) {
return fullDataset
};
// prepare your payload ready for launch
return { msg: newMsg };
},
and then you should get something like this if you switch the tab or refresh your page:
later messages simply add a new datapoint:
Let's see if this solution works in a longer development and debugging period
and all of this will later perhaps look like this (just a proof of concept and my own capabilities)