fase(7): api server refactor with composition root
This commit is contained in:
42
dist/realtime/SocketGateway.js
vendored
Normal file
42
dist/realtime/SocketGateway.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SocketGateway = void 0;
|
||||
const BROADCAST_EVENTS = [
|
||||
'crawling.started',
|
||||
'crawling.state_discovered',
|
||||
'crawling.action_executed',
|
||||
'crawling.completed',
|
||||
'crawling.failed',
|
||||
'findings.created',
|
||||
'findings.resolved',
|
||||
'findings.enriched',
|
||||
'fuzzing.started',
|
||||
'fuzzing.vulnerability_detected',
|
||||
'fuzzing.completed',
|
||||
];
|
||||
class SocketGateway {
|
||||
constructor(io, eventBus, logger) {
|
||||
this.io = io;
|
||||
this.eventBus = eventBus;
|
||||
this.logger = logger;
|
||||
}
|
||||
start() {
|
||||
// Subscribe EventBus events → broadcast to all connected clients
|
||||
for (const eventName of BROADCAST_EVENTS) {
|
||||
this.eventBus.subscribe(eventName, {
|
||||
handle: async (event) => {
|
||||
this.io.emit(eventName, event);
|
||||
this.logger.debug({ eventName }, 'Socket event broadcast');
|
||||
},
|
||||
});
|
||||
}
|
||||
this.io.on('connection', (socket) => {
|
||||
this.logger.debug({ socketId: socket.id }, 'Client connected');
|
||||
socket.on('disconnect', () => {
|
||||
this.logger.debug({ socketId: socket.id }, 'Client disconnected');
|
||||
});
|
||||
});
|
||||
this.logger.info('SocketGateway started');
|
||||
}
|
||||
}
|
||||
exports.SocketGateway = SocketGateway;
|
||||
Reference in New Issue
Block a user