send stats only if there is at least one client in the room

This commit is contained in:
LouisLam 2021-08-30 14:55:33 +08:00
parent 22db9c9b8a
commit bf29f28726
2 changed files with 34 additions and 5 deletions

View file

@ -248,3 +248,26 @@ exports.checkStatusCode = function (status, accepted_codes) {
return false;
}
exports.getTotalClientInRoom = (io, roomName) => {
const sockets = io.sockets;
if (! sockets) {
return 0;
}
const adapter = sockets.adapter;
if (! adapter) {
return 0;
}
const room = adapter.rooms.get(roomName);
if (room) {
return room.size;
} else {
return 0;
}
}