One kind of socket.io custom parser. Based on official socket.io-parser.
U can register the function that will be executed before encode message or after decode message
So that u can have the union entrance if u want to monitor every input or output message.
npm i socket.io-custom-parser
2.1 set parser
let parser = require('socket.io-custom-parser');
let beforeEncode = (obj) => {
//do something before every encode operation.
//...
console.log('send message:', obj);
};
let afterDecode = (obj) => {
//do something after every decode operation.
//...
console.log('receive message:', obj);
};
parser.setBeforeEncode(beforeEncode);
parser.setAfterDecode(afterDecode);
2.2 then in socket.io, use the defined parser above as the custom parser. need socket.io custom-parser example?
const io = require('socket.io')(httpServer, {
path: 'xxxx',
pingTimeout: 10000,
pingInterval: 5000,
parser: parser
});
Thanks for socket.io-parser