Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitting to single room when socket was joined via socket.join([rooms]) doesn't emit. #2905

Closed
1 task done
andrewgrewell opened this issue Mar 29, 2017 · 2 comments
Closed
1 task done

Comments

@andrewgrewell
Copy link

andrewgrewell commented Mar 29, 2017

You want to:

  • report a bug

Current behaviour

Doing io.in(roomA).emit(...) will not emit to that room if the socket was joined via socket.join([roomA, roomB, ...])

Steps to reproduce

see: fiddle to reproduce
example:

io.on('connect', (socket) => {
  console.log('client connected to root, socket id: ' + socket.id);

  socket.on('disconnect', () => console.log('client disconnected from root, socket id: ' + socket.id));

  var rooms = ['a', 'b', 'c'];
  socket.join(rooms, (err) => {

    // respond with the status of the joins
    socket.emit('joined-rooms', {
      status: err ? 'success' : 'failure',
      error: err,
      message: `${err ? 'failed to join' : 'joined'} rooms: a, b, c`
    });


    // send a message to each single room that we joined - this seems to fail
    rooms.forEach((room) => {
      console.log('emitting message to room', room);
      io.in(room).emit('message', {
        multiRoom: false,
        message: `this message was sent to a single room '${room}'`
      });
    });


    // send a message to all rooms that we joined - this will work
    console.log('emitting message to all rooms', rooms);
    io.in(rooms).emit('message', {
      multiRoom: true,
      message: `this message was sent to rooms '${rooms}'`
    });
  });
});

Expected behaviour

I would expect to be able to do socket.join([...multipleRooms]) and later io.in(singleRoom).emit(...)

Setup

  • socket.io version: 1.7.3 (both client and server)

Solution

For now I am just doing rooms.forEach(room => socket.join(room) and then I am able to emit to a single room

@andrewgrewell andrewgrewell changed the title [BUG] Emitting to single room when socket was joined via socket.join([rooms]) doesn't emit. Emitting to single room when socket was joined via socket.join([rooms]) doesn't emit. Mar 29, 2017
@darrachequesne
Copy link
Member

That feature was recently added (#2879), and is not released yet.

@andrewgrewell
Copy link
Author

Gotcha, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants