From c9d6b46f0f9e59abe27ac9d8b65783d2b737e02d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 4 Nov 2018 01:48:02 +0000 Subject: [PATCH] update how recently a domain has been active --- lib/device-tracker.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/device-tracker.js b/lib/device-tracker.js index 2958a49..853c6e2 100644 --- a/lib/device-tracker.js +++ b/lib/device-tracker.js @@ -14,6 +14,7 @@ Devices.add = function (store, servername, newDevice, isPort) { if (!store._domains) { store._domains = {}; } if (!store._domains[servername]) { store._domains[servername] = []; } store._domains[servername].push(newDevice); + Devices.touch(store, servername); // add device // TODO only use a device id @@ -126,7 +127,11 @@ Devices.active = function (store, id) { }; */ Devices.exist = function (store, servername) { - return !!(Devices.list(store, servername).length); + if (Devices.list(store, servername).length) { + Devices.touch(store, servername); + return true; + } + return false; }; Devices.next = function (store, servername) { var devices = Devices.list(store, servername); @@ -138,5 +143,14 @@ Devices.next = function (store, servername) { device = devices[devices._index || 0]; devices._index = (devices._index || 0) + 1; + if (device) { Devices.touch(store, servername); } return device; }; +Devices.touch = function (store, servername) { + if (!store._recency) { store._recency = {}; } + store._recency[servername] = Date.now(); +}; +Devices.lastSeen = function (store, servername) { + if (!store._recency) { store._recency = {}; } + return store._recency[servername] || 0; +};