My bad way
Client-Side
socket.on('connect',function(){ socket.emit('EnterRoom',{room:'test'});})
Server-Side
app.js
io.sockets.on('connection',function(socket){
socket.on('EnterRoom', function(data) {
socket.join(data.room);
app.emit('event:JoinRoom',{room:data.room});
})});
some-module-with-rooms.js
app.on('event:JoinRoom',function(data){if(data.room=='test'){/*anycode*/} });
Emitting an event to all clients in a particular room:
io.sockets.in('room').emit('event_name', data)
So in your case:
io.sockets.on('connection',function(socket){
socket.on('EnterRoom', function(data) {
socket.join(data.room)
io.sockets.in(data.room).emit('JoinRoom', data);
})
});
That will emit only to the selected room. You can the access the room:
io.sockets.manager.rooms
and i quote the docs:
This is a hash, with the room name as a key to an array of socket IDs. Note that the room names will have a leading / character