Files
flood/server/models/ServerEvent.ts
2024-08-13 22:31:39 +00:00

19 lines
453 B
TypeScript

import type {ServerEvents} from '@shared/types/ServerEvents';
import type {Response} from 'express';
class ServerEvent {
res: Response;
constructor(res: Response) {
this.res = res;
}
emit<T extends keyof ServerEvents>(id: number, eventType: T, data: ServerEvents[T]) {
this.res.write(`id:${id}\n`);
this.res.write(`event:${eventType}\n`);
this.res.write(`data:${JSON.stringify(data)}\n\n`);
}
}
export default ServerEvent;