Reputation: 9226
I want to implement Socket.io
's Room
functionality and my configuration is like this:
io.on('connection', function (socket) {
socket.join('123');
//...
}
And when I want to emit an event:
socket.in('123').emit('sendMessage', {items:values]});
But everyone gets this message except the sender of this message. Why? Do I have to emit()
a separate message for sender?
If I use socket.to('123')
instead of socket.in('123')
I get the same result and nothing changes. I use the Socket.io
's official documents:
http://socket.io/docs/rooms-and-namespaces/
Upvotes: 1
Views: 191
Reputation: 11289
To get this to send to everyone including the sender you need to use the following syntax:
io.sockets.in('123').emit('message', 'cool game');
note that this is using the global io which I would assume you would have included like this:
var io = require('socket.io');
Upvotes: 2