我已经通过以下方式实现了socketio-auth
require('socketio-auth')(io, {
authenticate: auth.authenticate_user,
postAuthenticate: auth.postAuthenticate,
disconnect: auth.disconnect,
timeout: 1000
});
在身份验证后,我获得了套接字和数据,以便可以跟踪客户端
postAuthenticate: function(socket, data) {
var username = data.username;
usersController.getUser({displayName:username}, function(user, err) {
socket.client.user = user[0];
socket.emit('user', user[0]);
usersController.updateUser(
{_id:user[0]._id},
{socketId: socket.id, connectionStatus: true},
function(){}
)
**Need to send notification to another client here**
});
我需要让其他客户端进行身份验证。但是我可以像下面这样从io获得客户。我们如何才能从postauthenticate内部访问io?
io.sockets.clients().forEach(function (socket) { .. });