client initiate

This commit is contained in:
DecDuck
2024-10-08 13:17:30 +11:00
parent ceacd8469d
commit 909432a6ce
8 changed files with 66 additions and 9 deletions

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;