0

code i have code sample like this:

****sample code here *******

 socket.on("case1", ()={
     console.log("im here+++++++")
     //do something
    });

    socket.on("case2", ()={
     console.log("im here+++++++")
     //do something
    });

    socket.on("case3", ()={
     console.log("im here+++++++")
     //do something
    });

****end sample code here *******

*

*

*

*

and i want it to become like this :

****expecting new code like below*******

socket.on("case1", ()={
 //do something
});

socket.on("case2", ()={
 //do something
});

socket.on("case3", ()={
 //do something
});

****end expecting new code like below*******

however still print out as "im here+++++++" as per sample code above.

something like middleware for every socket.on before executing do something

no matter what event they are in, from case1 to caseN

*

*

*

is there a way to do it? i had try to search and found https://stackoverflow.com/questions/43360629/dispatch-action-on-the-callback-of-socket-on but it not working

i also had tried this from socket.io

io.use(function(socket, next) {
            console.log("1234567")
              console.log(socket.request.user);
          next();
        });

but not working as well

can someone help?

zhang yu
  • 45
  • 1
  • 4

0 Answers0