|
@@ -35,8 +35,8 @@ io.on("connection", socket => {
|
35
|
35
|
socket.broadcast.to(roomID).emit("new-user", socket.id);
|
36
|
36
|
}
|
37
|
37
|
io.in(roomID).emit(
|
38
|
|
- "room-user-count",
|
39
|
|
- io.sockets.adapter.rooms[roomID].length
|
|
38
|
+ "room-user-change",
|
|
39
|
+ Object.keys(io.sockets.adapter.rooms[roomID].sockets)
|
40
|
40
|
);
|
41
|
41
|
});
|
42
|
42
|
|
|
@@ -48,9 +48,11 @@ io.on("connection", socket => {
|
48
|
48
|
socket.on("disconnecting", () => {
|
49
|
49
|
const rooms = io.sockets.adapter.rooms;
|
50
|
50
|
for (const roomID in socket.rooms) {
|
51
|
|
- const remaining = rooms[roomID].length - 1;
|
52
|
|
- if (remaining > 0) {
|
53
|
|
- socket.broadcast.to(roomID).emit("room-user-count", remaining);
|
|
51
|
+ const clients = Object.keys(rooms[roomID].sockets).filter(
|
|
52
|
+ id => id !== socket.id
|
|
53
|
+ );
|
|
54
|
+ if (clients.length > 0) {
|
|
55
|
+ socket.broadcast.to(roomID).emit("room-user-change", clients);
|
54
|
56
|
}
|
55
|
57
|
}
|
56
|
58
|
});
|