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 a room doesn't work for namespaced clients #285

Closed
dvv opened this issue Jun 23, 2011 · 14 comments
Closed

emitting to a room doesn't work for namespaced clients #285

dvv opened this issue Jun 23, 2011 · 14 comments
Labels
bug Something isn't working

Comments

@dvv
Copy link
Contributor

dvv commented Jun 23, 2011

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"')
})
@3rd-Eden
Copy link
Contributor

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
Copy link
Contributor

Fix landed in master

@BrianMcKeever
Copy link

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]

@ghost
Copy link

ghost commented Jul 19, 2012

This is broken for me also.

@donpark
Copy link

donpark commented Aug 27, 2012

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.

@missinglink
Copy link

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

@bijanv
Copy link

bijanv commented Dec 18, 2012

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

@appmonkey8010
Copy link

It still doesn´t work in 1.2.1

@selay
Copy link

selay commented Aug 3, 2015

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);

@Xplouder
Copy link

@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

@alirezanasseh
Copy link

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

@roymckenzie
Copy link

roymckenzie commented Jun 11, 2018

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' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

12 participants