log disconnects, emit user left events, add perMessageDeflate option
This commit is contained in:
parent
a8eca277e4
commit
6b61ff4cd7
1 changed files with 15 additions and 7 deletions
12
src/index.ts
12
src/index.ts
|
@ -36,7 +36,8 @@ const io = socketIO(server, {
|
|||
|
||||
res.writeHead(200, headers);
|
||||
res.end();
|
||||
}
|
||||
},
|
||||
perMessageDeflate: true
|
||||
});
|
||||
|
||||
// listens on host:9090/metrics
|
||||
|
@ -83,13 +84,20 @@ io.on('connection', socket => {
|
|||
for (const roomID of Object.keys(socket.rooms)) {
|
||||
const clients = Object.keys(rooms[roomID].sockets).filter(id => id !== socket.id);
|
||||
|
||||
if (roomID !== socket.id) {
|
||||
socket.to(roomID).emit('user has left', socket.id);
|
||||
}
|
||||
|
||||
if (clients.length > 0) {
|
||||
socket.broadcast.to(roomID).emit('room-user-change', clients);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
socket.on('disconnect', reason => {
|
||||
serverDebug(
|
||||
`${socket.id} was disconnected from url ${socket.conn.request.url} for the following reason: ${reason}`
|
||||
);
|
||||
socket.removeAllListeners();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue