refactor(core): Use type-safe event emitters (no-changelog) (#10234)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-07-30 13:23:01 +02:00
committed by GitHub
parent 99dc56c7a1
commit 1fca3af335
12 changed files with 124 additions and 89 deletions

View File

@@ -1,4 +1,3 @@
import { EventEmitter } from 'events';
import { ServerResponse } from 'http';
import type { Server } from 'http';
import type { Socket } from 'net';
@@ -17,6 +16,11 @@ import { OrchestrationService } from '@/services/orchestration.service';
import { SSEPush } from './sse.push';
import { WebSocketPush } from './websocket.push';
import type { PushResponse, SSEPushRequest, WebSocketPushRequest } from './types';
import { TypedEmitter } from '@/TypedEmitter';
type PushEvents = {
editorUiConnected: string;
};
const useWebSockets = config.getEnv('push.backend') === 'websocket';
@@ -28,7 +32,7 @@ const useWebSockets = config.getEnv('push.backend') === 'websocket';
* @emits message when a message is received from a client
*/
@Service()
export class Push extends EventEmitter {
export class Push extends TypedEmitter<PushEvents> {
private backend = useWebSockets ? Container.get(WebSocketPush) : Container.get(SSEPush);
constructor(private readonly orchestrationService: OrchestrationService) {
@@ -37,7 +41,6 @@ export class Push extends EventEmitter {
handleRequest(req: SSEPushRequest | WebSocketPushRequest, res: PushResponse) {
const {
user,
ws,
query: { pushRef },
} = req;