client initiate

This commit is contained in:
DecDuck
2024-10-08 13:17:30 +11:00
parent 88a07e0723
commit 1c63d62e3d
8 changed files with 66 additions and 9 deletions
+29
View File
@@ -0,0 +1,29 @@
import { v4 as uuidv4 } from "uuid";
export interface ClientMetadata {
name: string;
platform: string;
}
export class ClientHandler {
private temporaryClientTable: {
[key: string]: { timeout: NodeJS.Timeout; data: ClientMetadata };
} = {};
async initiate(metadata: ClientMetadata) {
const clientId = uuidv4();
this.temporaryClientTable[clientId] = {
data: metadata,
timeout: setTimeout(() => {
if (this.temporaryClientTable[clientId])
delete this.temporaryClientTable[clientId];
}, 1000 * 60 * 10), // 10 minutes
};
return clientId;
}
}
export const clientHandler = new ClientHandler();
export default clientHandler;