feat: implement AudioSocketModule and WebRTCHandler for audio streaming; refactor SocketIOService to support module-based event handling

This commit is contained in:
Marco Beretta 2025-04-05 10:37:53 +02:00
parent 77ca00c87b
commit 2eda62cf67
No known key found for this signature in database
GPG key ID: D918033D8E74CC11
4 changed files with 292 additions and 156 deletions

View file

@ -0,0 +1,40 @@
const { AudioHandler } = require('./WebRTCHandler');
const { logger } = require('~/config');
class AudioSocketModule {
constructor(socketIOService) {
this.socketIOService = socketIOService;
this.audioHandler = new AudioHandler();
this.moduleId = 'audio-handler';
this.registerHandlers();
}
registerHandlers() {
this.socketIOService.registerModule(this.moduleId, {
connection: (socket) => this.handleConnection(socket),
disconnect: (socket) => this.handleDisconnect(socket),
});
}
handleConnection(socket) {
// Register WebRTC-specific event handlers for this socket
this.audioHandler.registerSocketHandlers(socket, this.config);
logger.debug(`Audio handler registered for client: ${socket.id}`);
}
handleDisconnect(socket) {
// Cleanup audio resources for disconnected client
this.audioHandler.cleanup(socket.id);
logger.debug(`Audio handler cleaned up for client: ${socket.id}`);
}
// Used for app shutdown
cleanup() {
this.audioHandler.cleanupAll();
this.socketIOService.unregisterModule(this.moduleId);
}
}
module.exports = { AudioSocketModule };