socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

emitting to a room doesn't work for namespaced clients

Open dvv opened this issue 15 years ago • 14 comments

Failing

io.of('/foo').on('connection', function(client) {
  client.join('aaa');
  this.in('aaa').emit('goes to noone since packet endpoint is set to "/foo/aaa", instead of "/foo" and room: "aaa"')
})

Working

io.of('').on('connection', function(client) {
  client.join('aaa');
  this.in('aaa').emit('goes to aaa members since packet endpoint is set to "aaa"')
})

dvv avatar Jun 23 '11 11:06 dvv

Yes we need better testing for room joins + messages

On Jun 23, 2011, at 1:31 PM, dvv wrote:

Failing

io.of('/foo').on('connection', function(client) {
 client.join('aaa');
 this.in('aaa').emit('goes to noone since packet endpoint is set to "/foo/aaa", instead of "/foo" and room: "aaa"')
})

Working

io.of('').on('connection', function(client) {
 client.join('aaa');
 this.in('aaa').emit('goes to aaa members since packet endpoint is set to "aaa"')
})

Reply to this email directly or view it on GitHub: https://github.com/LearnBoost/Socket.IO-node/issues/285

3rd-Eden avatar Jun 23 '11 11:06 3rd-Eden

https://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.js#L131 sets room flag https://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.js#L195 honors room flag https://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.js#L197 honors endpoint separately from room

https://github.com/LearnBoost/Socket.IO-node/blob/master/lib/namespace.js#L84 scrambles everything, should set only room, i believe

dvv avatar Jun 23 '11 12:06 dvv

Fix landed in master

3rd-Eden avatar Jul 12 '11 07:07 3rd-Eden

This bug appears to no longer be fixed. This works: io.of('').on('connection', function(client) { This doesn't: io.of('/foo').on('connection', function(client) {

I'm using: ├─┬ [email protected] │ ├── [email protected] │ ├── [email protected] │ └─┬ [email protected] │ ├─┬ [email protected] │ │ └── [email protected] │ ├── [email protected] │ ├─┬ [email protected] │ │ ├── [email protected] │ │ └── [email protected] │ └── [email protected]

BrianMcKeever avatar May 06 '12 15:05 BrianMcKeever

This is broken for me also.

ghost avatar Jul 19 '12 04:07 ghost

I did notice that broadcast to rooms joined via namespace does go out but without namespace.

Quickest suggested fix would be to also add 'in' functions to namespace so we can broadcast to a room in context of a namespace.

donpark avatar Aug 27 '12 22:08 donpark

The socket.join() method prepends its namespace.name to any room name you specify: https://github.com/LearnBoost/socket.io/blob/master/lib/socket.js#L166

This seems to be causing some confusion and makes it hard to join a room from another namespace:

ns1 = io.of('/main')
ns2 = io.of('/chat')

ns1.on 'connect', (socket) ->

  # Socket joins room: '/main/myroom'
  socket.join 'myroom' 

  # A hack to join room: '/chat/myroom'
  socket.namespace = ns2
  socket.join 'myroom' 
  socket.namespace = ns1

It would be nice if you could specify the namespace to use when joining a room

missinglink avatar Sep 28 '12 03:09 missinglink

Any updates on this? Can this be re-opened as a bug? I'm also unable to broadcast to rooms within a namespace.

bijanv avatar Dec 18 '12 19:12 bijanv

It still doesn´t work in 1.2.1

appmonkey8010 avatar Dec 15 '14 12:12 appmonkey8010

doesnt work on 1.3.6 The following example works fine if no namespace or namespace is set to '/'. If you set namespace like '/mynamepsace'. Won't work. socket.join('test room'); console.log(io.sockets.adapter.rooms);

selay avatar Aug 03 '15 08:08 selay

@missinglink you last reply here was like 2 years ago but anyway, did you find any solution? i just posted in stackoverflow something related. Please take a look and reply if possible. Ty http://stackoverflow.com/questions/34279278/join-a-namespace-room-from-different-namespace

Xplouder avatar Dec 15 '15 01:12 Xplouder

replied http://stackoverflow.com/questions/34279278/join-a-namespace-room-from-different-namespace/34288957#34288957

missinglink avatar Dec 15 '15 12:12 missinglink

Still not solved in 2018! socket.io 2.1.0, why?!

alirezanasseh avatar Jun 09 '18 00:06 alirezanasseh

I figured it out. Basically, when emitting to namespaced rooms you also need to define the namespace.

io.of('/chat').in( 'cool room' ).emit( 'new message' );

roymckenzie avatar Jun 11 '18 04:06 roymckenzie