feat: add sessions stats endpoint

This commit is contained in:
Carlos Valente
2024-10-20 22:19:33 +02:00
committed by Carlos Valente
parent 71c468d069
commit 82810f1cb1
8 changed files with 71 additions and 3 deletions
@@ -1,8 +1,32 @@
import { GetInfo } from 'ontime-types';
import { GetInfo, SessionStats } from 'ontime-types';
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
import { publicFiles } from '../../setup/index.js';
import { getNetworkInterfaces } from '../../utils/networkInterfaces.js';
import { socket } from '../../adapters/WebsocketAdapter.js';
import { getLastRequest } from '../../api-integration/integration.controller.js';
import { getLastLoadedProject } from '../../services/app-state-service/AppStateService.js';
import { runtimeService } from '../../services/runtime-service/RuntimeService.js';
const startedAt = new Date();
/** Gathers information related to runtime */
export async function getSessionStats(): Promise<SessionStats> {
const { connectedClients, lastConnection } = socket.getStats();
const lastRequest = getLastRequest();
const projectName = await getLastLoadedProject();
const { playback } = runtimeService.getRuntimeState();
return {
startedAt: startedAt.toISOString(),
connectedClients,
lastConnection: lastConnection !== null ? lastConnection.toISOString() : null,
lastRequest: lastRequest !== null ? lastRequest.toISOString() : null,
projectName,
playback,
timezone: startedAt.getTimezoneOffset(),
};
}
/**
* Adds business logic to gathering data for the info endpoint