event handling middleware for socket.io