嗨,伙计们有一个问题,我怎样才能从套接字中获取所有用户AddUsers
并将其转移到套接字get winners
?我试图将它直接调用到函数中,但它并没有显示出来..我需要将它保存到 cookie 中吗?
var usernames = [];
io.sockets.on('connection', function (socket){
socket.on('addUsers', function (data) {
var users = {
data : data.box,
socket_id : socket.id
}
socket.username = data.username;
usernames.push({username : data.username, itemid : data.itemid, box : data.box,socket_id : socket.id});
socket.emit('displayUsers', {users: usernames});
});
socket.on('get winners', function (data) {
socket.emit('display winners', {data: usernames});
});
});