Not correctly checking number of clients in room (step-04)
See original GitHub issueIn step-04/index.js the server checks how many clients are in the room by calling
var numClients = io.sockets.sockets.length;
log('Room ' + room + ' now has ' + numClients + ' client(s)');
However this returns undefined, as well as doesn’t actually try and check for the given room.
A proposed fix:
var clientsInRoom = io.nsps['/'].adapter.rooms[room];
var numClients = clientsInRoom === undefined ? 0 : Object.keys(clientsInRoom).length;
Or if you also want to upgrade to socket v1.4
var clientsInRoom = io.nsps['/'].adapter.rooms[room];
var numClients = clientsInRoom === undefined ? 0 : Object.keys(clientsInRoom.sockets).length;
A full fix + some small cleans up 😃 would look like
var clientsInRoom = io.nsps['/'].adapter.rooms[room];
var numClients = clientsInRoom === undefined ? 0 : Object.keys(clientsInRoom).
// socket.io 1.4.8
var numClients = clientsInRoom === undefined ? 0 : Object.keys(clientsInRoom.sockets).length;
// max two clients
if (numClients === 2) {
socket.emit('full', room);
return;
}
log('Room ' + room + ' now has ' + (numClients + 1) + ' client(s)');
if (numClients === 0) {
socket.join(room);
log('Client ID ' + socket.id + ' created room ' + room);
socket.emit('created', room, socket.id);
} else {
log('Client ID ' + socket.id + ' joined room ' + room);
io.sockets.in(room).emit('join', room);
socket.join(room);
socket.emit('joined', room, socket.id);
io.sockets.in(room).emit('ready');
}
See: https://github.com/AlexRobinson-/webrtc-web/blob/fix-check-room-clients/step-04/index.js
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:21 (17 by maintainers)
Top Results From Across the Web
how to get socket.io number of clients in room? - Stack Overflow
my socket.io version 1.3.5 on('create or join', function (numClients, room) { socket. join(room); }); I use this code for get clients in room...
Read more >discord python bot examples - Fenice S.r.l
Im going to be hosting a discord bot 24/7 and i want the Status to display the current date and time, as example....
Read more >Hdwificampro instructions - Edizioni La Grafica
Step 04 : Search by HDWifiCamPro from the Tools section and Click on the “Install” button. Hardware controls. 7V Playback software You are...
Read more >bypass google drive limit reddit
Bypass Google Drive Download Limit (Quota Exceeded) Error 2021 [New Method]. There's a few steps we need to go through to accomplish this:...
Read more >Getting Started with Translational Core
You will need a valid payment method (Lawson account number or PO#) associated with ... Step 04. Submit samples. All samples must be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@aaronang go for it!
@thbaja @nitobuendia Thank you!
I’ve published the changes to codelab text.