In node.js we can add some middleware function to socket.io server like this
io.use(function(socket, next) {
var req = socket.handshake;
var res = {};
cookieParser(req, res, function(err) {
if (err) return next(err);
session(req, res, next);
});
});
I wonder if we can add some kind of middleware to simple socket.on function as in the following example
io.sockets.on('connection', function(socket){
socket.on('someSignal',
function(data,next){/*middleware function code*/ next();},
function(data){})
});
emitter.on(event, listener) is the alias for emitter.addListener(event, listener). if you want to do this, every request pass through this middleware will add one eventListener.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With