/*********************************************************************************** Abstractor | Heartbeat monitor | MIT L. | ©2016 Hexagon Monitors the frequency of messages received, outputs "timeout" when no message has arrived in x ms. ---------------------------------------------------------------------------- Options -----------------+-----------------+----------------------+----------------- Option | Type | Default | Mandatory -----------------+-----------------+----------------------+----------------- timeout | number | 60 000 | yes -----------------+-----------------+----------------------+----------------- I/O -------------------------------+----------------------+--------------------- Input | Possible triggers | Output -------------------------------+----------------------+--------------------- | timeout | -------------------------------+----------------------+--------------------- ***********************************************************************************/ "use strict"; const Node = require("../node.js"); class Heartbeat extends Node { constructor(parameters) { var defaults = { timeout: 600000 }; super(parameters, defaults); this.lastGood = undefined; this.reset(); } timeout() { this.trigger( "timeout", this.lastGood ); } reset() { let self = this; if (this.timer) clearTimeout(this.timer); this.timer = setTimeout( function () { self.timeout(); }, this.config.timeout ); } invoke(msg) { this.reset(); this.lastGood = msg; } } module.exports = Heartbeat;