update how recently a domain has been active
This commit is contained in:
parent
0a67728239
commit
c9d6b46f0f
|
@ -14,6 +14,7 @@ Devices.add = function (store, servername, newDevice, isPort) {
|
||||||
if (!store._domains) { store._domains = {}; }
|
if (!store._domains) { store._domains = {}; }
|
||||||
if (!store._domains[servername]) { store._domains[servername] = []; }
|
if (!store._domains[servername]) { store._domains[servername] = []; }
|
||||||
store._domains[servername].push(newDevice);
|
store._domains[servername].push(newDevice);
|
||||||
|
Devices.touch(store, servername);
|
||||||
|
|
||||||
// add device
|
// add device
|
||||||
// TODO only use a device id
|
// TODO only use a device id
|
||||||
|
@ -126,7 +127,11 @@ Devices.active = function (store, id) {
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
Devices.exist = function (store, servername) {
|
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) {
|
Devices.next = function (store, servername) {
|
||||||
var devices = Devices.list(store, servername);
|
var devices = Devices.list(store, servername);
|
||||||
|
@ -138,5 +143,14 @@ Devices.next = function (store, servername) {
|
||||||
device = devices[devices._index || 0];
|
device = devices[devices._index || 0];
|
||||||
devices._index = (devices._index || 0) + 1;
|
devices._index = (devices._index || 0) + 1;
|
||||||
|
|
||||||
|
if (device) { Devices.touch(store, servername); }
|
||||||
return device;
|
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;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue