Onja
1 year ago
2 changed files with 29 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||
const socketIo = require('socket.io'); |
|||
const emitter = require('../services/eventEmitter'); |
|||
const e = require('express'); |
|||
const configure = require('../subscribers/ioSubscriber'); |
|||
|
|||
function configureSocket(server) { |
|||
const io = socketIo(server); |
|||
|
|||
io.on('connection', (socket) => { |
|||
console.log('Nouvelle connexion WebSocket établie'); |
|||
emitter.emit('io.connection', { socket }); |
|||
|
|||
// Ici, vous pouvez mettre tout le code de gestion des connexions WebSocket, y compris les émissions et les écoutes de messages.
|
|||
|
|||
configure(socket); |
|||
|
|||
// Gérez la déconnexion
|
|||
socket.on('disconnect', () => { |
|||
console.log('Connexion WebSocket fermée'); |
|||
emitter.emit('io.disconnect', { socket }); |
|||
}); |
|||
}); |
|||
|
|||
return io; |
|||
} |
|||
|
|||
module.exports = configureSocket; |
Loading…
Reference in new issue