How to write custom middleware and pass to socket-io custom event pipeline?

40
December 03, 2020, at 07:30 AM

I am using socket-io for building a chat app. And I have many custom events and for each event I want to pass different middleware function? In my case io.use(somefunction()) not working! I want to pass middleware function to my custom event like this? io.on('my-custom-event', middleware, function() { ... })

Socket-io route Code : (Path : /routes/user.js)

module.exports.user_status_info = function (io,socket) {
    socket.on('custom-event', io.use(require('../../middleware/_chat-validation-middlewares/custom-event').validate(io,socket)), function (data, callback) { ... }
}

Middleware : (Path : /middleware/custom-event.js)

module.exports.validate = function (io,socket) {
    io.use((socket, next) => {
        console.log("I AM A MIDDLEWARE...")
        next();
    }); }

Current Implementation throwing error when I am trying to pass middleware in route pipeline.

READ ALSO
TYPO3 on XAMPP: Changes in backend not/unreliably persisted

TYPO3 on XAMPP: Changes in backend not/unreliably persisted

I've a running TYPO3 project on a Linux webserver and now I'm trying to get it working properly on a local Windows 10 machine with XAMPP for development purposes

65
DBConnection error and include_once error

DBConnection error and include_once error

Now i hope this topic stays here,

39
Arranging rectangles in a circle with equal distance

Arranging rectangles in a circle with equal distance

I'm writing a program that renders mind mapsSo far, I've succeeded in drawing the root node and the first level of child nodes around it, in a circle

26
How to filter integer value based on string parameter input on list on kotlin?

How to filter integer value based on string parameter input on list on kotlin?

I am trying to filter an object type list based on a string value which is working fine, but now I need to filter based on an integer attribute of the objects on the list

50