signalk-server
Version:
An implementation of a [Signal K](http://signalk.org) server for boats.
24 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ONLINE_THRESHOLD_MS = void 0;
exports.isDeviceStale = isDeviceStale;
// 90s threshold: covers Maretron-class devices that send Heartbeat (PGN
// 126993) only every 60s, plus margin for occasional jitter. Anything
// shorter risks flapping for slow-cycle PGNs.
exports.ONLINE_THRESHOLD_MS = 90_000;
/**
* Decide whether a device is stale enough to be removed by Reset Stale.
*
* Folds in both freshness signals (value-bearing deltas and raw N2K
* frames) so the Reset Stale predicate matches the Online badge logic
* in buildSourceStatuses. A device that emits only meta PGNs (Heartbeat
* / Address Claim / Product Information) — or whose data PGNs aren't
* mapped to Signal K paths — is shown Online and must not be reset.
*/
function isDeviceStale(metaLastSeen, frameLastSeen, now, thresholdMs = exports.ONLINE_THRESHOLD_MS) {
const lastSeen = metaLastSeen !== undefined && frameLastSeen !== undefined
? Math.max(metaLastSeen, frameLastSeen)
: (metaLastSeen ?? frameLastSeen);
return lastSeen === undefined || now - lastSeen >= thresholdMs;
}
//# sourceMappingURL=n2k-discovery-staleness.js.map