I have a nodejs + socket.io solution and sockets join different rooms. How can i select sockets from different rooms to broadcast to them a certain message without using a for loop that will stall the application for all users?
1 Answers
3
votes
The solution is simple, make every "special" user (the ones that you want to group) connect to a secret channel with Socket.IO, in your server-side code:
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
if (condition_to_determine_is_user_has_access) {
socket.join('specials');
socket.broadcast.to('specials').emit("new special user has joined");
}
});
You may also want to block access to that channel to un-allowed users, based on cookies / sessions.
Read more here: http://www.danielbaulig.de/socket-ioexpress/