Monday, 13 March 2017

Why socket.join doesn't work in connection.query?

I think I have found a bug. If I put socket.join(/any room here/) inside connection.query function it won't simply join that room. Interesting fact is that console.log works:

function registerInRoom (user, room) {
    var post_room = {Users_user_id: user, Rooms_room_id: room, ur_id: undefined};
    connection.query('INSERT INTO mydb.users_has_rooms SET ?', post_room, function(err) {
        if (err) throw err;
        socket.room = room;
        console.log("joined room");
        socket.join("Room 1");
    });

};//registerInRoom

And here is working code:

function registerInRoom (user, room) {
    var post_room = {Users_user_id: user, Rooms_room_id: room, ur_id: undefined};
    connection.query('INSERT INTO mydb.users_has_rooms SET ?', post_room, function(err) {
        if (err) throw err;
        socket.room = room;
        console.log("joined room");
    });
    socket.join("Room 1");
};//registerInRoom

My question is... What am I doing wrong in my thinking process?



via filemono

No comments:

Post a Comment