1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-18 00:10:12 -07:00
deskreen/app/server/pollForInactiveRooms.ts
2020-12-25 01:11:01 +02:00

24 lines
690 B
TypeScript

/*
* original JS code from darkwire.io
* translated to typescript for Deskreen app
* */
import getStore from './store';
export default async function pollForInactiveRooms() {
const store = getStore();
const rooms = (await store.getAll('rooms')) || {};
Object.keys(rooms).forEach(async (roomId) => {
const room = JSON.parse(rooms[roomId]);
const timeSinceUpdatedInSeconds = (Date.now() - room.updatedAt) / 1000;
const timeSinceUpdatedInDays = Math.round(
timeSinceUpdatedInSeconds / 60 / 60 / 24
);
if (timeSinceUpdatedInDays > 7) {
await store.del('rooms', roomId);
}
});
setTimeout(pollForInactiveRooms, 1000 * 60 * 60); // every hour
}