socket.join not working
See original GitHub issueRepost from SO, but I need answers so here:
So, my socket.join calls are doing nothing. After calling socket.join, and then listing the rooms the socket is in, the socket is only connected to the room defined by it’s id (it’s own room).
function onJoin(room) {
console.log("Joining room: " + room);
socket.join(room);
console.log(socket.id + " now in rooms ", socket.rooms);
}
Would print for example:
> Joining room: 5aba92759b9ffa9fdf579714d6aa125ddb05cb1172611331775e7a69dab37258
> Q6D4h17DvdOZrbrEAAAC now in rooms { Q6D4h17DvdOZrbrEAAAC: 'Q6D4h17DvdOZrbrEAAAC' }
If it makes a difference, here’s how my socket server is being created:
//app.js
var app = express();
var http = require('http');
var server = http.Server(app);
var io = require('socket.io')(server);
var chat = require('./routes/chat/chat')(io);
//chat.js
module.exports = function(io) {
io.sockets.on('connection', function(socket) {
socket.on('join', onJoin);
...
}
Where’s the issue?
- Socket.io v1.7.3
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
socket.join does not work (socket.io) - Stack Overflow
The issue was that socket.join is async. So this would work as expected: socket.join(room, function() { console.log("Socket now in rooms", ...
Read more >Rooms | Socket.IO
A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of...
Read more >Socket.IO - Rooms - Tutorialspoint
Joining Rooms. You can call the join method on the socket to subscribe the socket to a given channel/room. For example, let us...
Read more >Chat Rooms With Socket.io - Medium
You've got yourself a basic express app running on localhost:5000. ... The only difference is socket.in will not include the sender, ...
Read more >Socket = io join multiple rooms, socket.broadcast.emit not working ...
Socket.io join another client to a room, listen for a custom event from the ... Then the problem is the same: socket.broadcast.emit is...
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
The
join
method is asynchronous:@chuckdries welcome to the world of socket.io documentation