SocketIO groups


I'm trying SocketIO and I'm stuck. I can't find any proper documentation.

Here is a sample code of what I'd like to do :'group1').join('group2');'group3').on('message', function(){});

Is there any workaround to those two particular actions ? Thanks !

Problem courtesy of: Alexandre Kirszenberg


The function io.sockets.clients is what I needed. It allows me to traverse the clients of a specific room, adding them to a group if necessary, or registering an event.

Solution courtesy of: Alexandre Kirszenberg


What you need to do is join() a socket into a group:

var io = require('').listen(80);

io.sockets.on('connection', function (socket) {
  socket.join('justin bieber fans'); // put socket in a channel'justin bieber fans').emit('new fan'); // broadcast a message to a channel'rammstein fans').emit('new non-fan'); // to another channel

You need to do this for every socket that connects to you.

This is from documentation at (search for Rooms).

Discussion courtesy of: diversario

This recipe can be found in it's original form on Stack Over Flow.