Default room name is not socket id
See original GitHub issueI’m using socket.io 1.4.5.
if I do
io.to(socketId).emit('some msg');
the message will not be emitted.
after digging a little bit I found that I should prepend /#
before socke id.
socketRoomName = '/#' + socketId;
io.to(socketRoomName).emit('some msg');
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
socket.io emit to default room does not work - Stack Overflow
It was discovered that the default room socket.id being used by the server to set the default room is not the same as...
Read more >Rooms | Socket.IO
Default room . Each Socket in Socket.IO is identified by a random, unguessable, unique identifier Socket#id. For your convenience, each socket ...
Read more >How to manage users in socket.io in Node.js ? - GeeksforGeeks
getUser: This function takes id as a parameter and returns the username by finding it from the array. getUsersInRoom: This function will return ......
Read more >Handling SocketIO rooms with React Hooks - Level Up Coding
Each socket can join required socket.io room by emitting room name to join event, and the server would listen to join event and...
Read more >Socket.io Namespaces and Rooms - DEV Community
By default, if a namespace is not specified, they will be attached to the default namespace / . Namespaces are used to separate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also
io.emit('some msg');
will send it to everyone in the default room. So if you have no use for multiple rooms you can omit it’s usage completely from your code and let socket.io handle it.Take note ‘some msg’ is the event. So you might be looking to do something like
io.emit('msg', 'some msg');
instead and listen formsg
on the client side.You’re right. Just ignore the guy above.
I lost two hours trying to figure out what was going on. Turns out when I did THISID = socket.id it got stored as “EgdohcmzQZnc_FzHAAAA” instead of (‘/#’ + “EgdohcmzQZnc_FzHAAAA”) which is the true socket id. So server side socket.id is /#EgdohcmzQZnc_FzHAAAA, but client side socket.id is EgdohcmzQZnc_FzHAAAA. Who is responsible for this?