emitting to a room doesn't work for namespaced clients
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"')
})
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
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
Fix landed in master
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]
This is broken for me also.
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.
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
Any updates on this? Can this be re-opened as a bug? I'm also unable to broadcast to rooms within a namespace.
It still doesn´t work in 1.2.1
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);
@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
replied http://stackoverflow.com/questions/34279278/join-a-namespace-room-from-different-namespace/34288957#34288957
Still not solved in 2018! socket.io 2.1.0, why?!
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' );