Namespace#use

Namespace#use(fn:Function):Namespace

Registers a middleware, which is a function that gets executed for every incoming Socket and receives as parameter the socket and a function to optionally defer execution to the next registered middleware.

var io = require('socket.io')();
io.use(function(socket, next){
  if (socket.request.headers.cookie) return next();
  next(new Error('Authentication error'));
});

Errors passed to middleware callbacks are sent as special error packets to clients.

doc_SocketIo
2016-09-25 12:15:42
Comments
Leave a Comment

Please login to continue.