feat(devices): compute effective online status with stale heartbeat ttl

This commit is contained in:
2026-02-23 14:35:00 +00:00
parent 46c6294e48
commit 53ad0adead
7 changed files with 148 additions and 3 deletions

View File

@@ -32,3 +32,19 @@ export const getRequiredEnv = (name: string): string => {
export const getBetterAuthBaseUrl = (): string => {
return getFirstDefinedEnv('BETTER_AUTH_BASE_URL', 'BETTER_AUTH_URL') ?? `http://localhost:${process.env.PORT ?? '3000'}`;
};
const DEFAULT_DEVICE_ONLINE_STALE_SECONDS = 30;
export const getDeviceOnlineStaleSeconds = (): number => {
const value = getFirstDefinedEnv('DEVICE_ONLINE_STALE_SECONDS');
if (!value) {
return DEFAULT_DEVICE_ONLINE_STALE_SECONDS;
}
const parsed = Number(value);
if (!Number.isInteger(parsed) || parsed <= 0) {
return DEFAULT_DEVICE_ONLINE_STALE_SECONDS;
}
return parsed;
};