由于某种原因,socket.emit不会运行,也不知道错误在哪里。但是socket.broadcast工作。
io.sockets.on('connection', function (socket) { // on on client connection
socket.on('login', function (uname, pword, email) { // on event login
SetupPlayer(socket);
});
});
这是一个名为
的函数var SetupPlayer= function(socket){
GetPlayer(socket, function(PlayerObj){
GetQuests(socket, function(QuestObj){
socket.room = PlayerObj.RoomID;
socket.emit('PlayerStructure', PlayerObj, QuestObj); // notify other clients about new player also passing players daya using set data structure
socket.broadcast.in(socket.room).emit('AddPlayer', activeusers[socket.room][socket.id]); // same as above
});
});
}
然而,socket.emit
没有任何结果,socket.broadcast.in(socket.room).emit
确实在运行
这是客户代码,但不认为这是问题所在。
socket.on('AddPlayer', function(playerstructure) {
console.log(playerstructure);
});
socket.on('PlayerStructure', function(playerstructure) {
console.log(playerstructure);
});