Wednesday, 19 April 2017

socket.join does not work (socket.io)

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?



via Juuso

No comments:

Post a Comment