我想我发现了一个错误。如果我把socket.join(/ 这里的任何房间 /)放在connection.query函数中,它就不会简单地加入那个房间。有趣的事实是console.log有效:
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
这是工作代码:
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
我的问题是......在我的思考过程中,我做错了什么?
答案 0 :(得分:0)
原来我的问题是由于覆盖了原来的socket而引起的。不应该做什么:
socket.id = result.insertId;