52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
const { CoreSyncDomain } = require('./src/coreSyncDomain');
|
||
|
|
|
||
|
|
module.exports = function(RED) {
|
||
|
|
RED.nodes.registerType('coresync', function(config) {
|
||
|
|
RED.nodes.createNode(this, config);
|
||
|
|
const node = this;
|
||
|
|
const hub = new CoreSyncDomain({
|
||
|
|
frostBaseUrl: config.frostBaseUrl,
|
||
|
|
serviceVersion: config.serviceVersion,
|
||
|
|
dbaseFormat: config.dbaseFormat,
|
||
|
|
assetTagOverride: config.assetTagOverride,
|
||
|
|
sensorTagOverride: config.sensorTagOverride,
|
||
|
|
maxQueuedObservationsPerStream: config.maxQueuedObservationsPerStream,
|
||
|
|
reducer: {
|
||
|
|
angleToleranceDeg: Number(config.angleToleranceDeg),
|
||
|
|
timeScaleMs: Number(config.timeScaleMs),
|
||
|
|
maxGapMs: Number(config.maxGapMs),
|
||
|
|
minDeltaTimeMs: Number(config.minDeltaTimeMs),
|
||
|
|
minDeltaValue: Number(config.minDeltaValue),
|
||
|
|
comparisonMode: config.comparisonMode || 'angle',
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
node.on('input', (msg, send, done) => {
|
||
|
|
try {
|
||
|
|
const output = hub.handleMessage(msg);
|
||
|
|
const dbaseCount = Array.isArray(output[1]) ? output[1].length : (output[1] ? 1 : 0);
|
||
|
|
if (dbaseCount > 0) node.status({ fill: 'blue', shape: 'dot', text: `${dbaseCount} FROST request(s)` });
|
||
|
|
send(output);
|
||
|
|
} catch (error) {
|
||
|
|
node.status({ fill: 'red', shape: 'ring', text: error.message });
|
||
|
|
node.error(error, msg);
|
||
|
|
} finally {
|
||
|
|
if (typeof done === 'function') done();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
node.on('close', (removed, done) => {
|
||
|
|
const closeDone = typeof removed === 'function' ? removed : done;
|
||
|
|
try {
|
||
|
|
const output = hub.flushAll('close');
|
||
|
|
if (output[1]) node.send(output);
|
||
|
|
node.status({});
|
||
|
|
} finally {
|
||
|
|
if (typeof closeDone === 'function') closeDone();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
};
|