我与nodejs和socket.io聊天。 我有这段代码:
io.on('connection', function (socket) {
var username = socket.handshake.user.username;
usersOnline.push(username);
socket.broadcast.emit('join', username);
io.sockets.emit('users', {users: usersOnline});
socket.on('disconnect', function () {
socket.broadcast.emit('leave', username);
var index = usersOnline.indexOf(username);
usersOnline.splice(index, 1);
io.sockets.emit('users', {users: usersOnline});
});
});
如何保存不包含在此用户列表中的用户名? Thak你
答案 0 :(得分:0)
我有阵列人 people[socket.id] = {"name": username};
并获取我的用户名people[socket.id].name