socket.io
socket.io copied to clipboard
Add response Ack in socket.prependAnyOutgoing()
I'm using
socket.use(([event, ...args], next) => {
incommingEventFilter(socket, [event, args], next);
});
socket.prependAnyOutgoing(outgoingEventFilter);
to filter and log all income & outgoing event;
It work well...but...
Client-Side:
socket.emitWithAck("hello", "world", (err, val) => {
//...
});
Server-Side:
socket.on("hello", (arg, callback) => {
console.log(arg); // "world"
callback("got it");
});
In postman client, i received event 'hello' with data 'got it';
The one thing is event 'hello' with 'got it' was not logged by socket.prependAnyOutgoing()
Describe the solution you'd like Please add callback Ack to socket.prependAnyOutgoing() or is there any way to log all callback Ack 🤔🤔
Do you need help with this? If yes you can definitely assigned this to me. From what I can understand the crux of the issue is that the socket.prependAnyOutgoing method in socket.io does not intercept acknowledgments/callbacks. It is designed to intercept outgoing events only, not the corresponding acknowledgments/callbacks. If you want to log all callback acknowledgments, you need to modify your code by intercepting the socket.emitWithAck method instead
Do you need help with this? If yes you can definitely assigned this to me. From what I can understand the crux of the issue is that the socket.prependAnyOutgoing method in socket.io does not intercept acknowledgments/callbacks. It is designed to intercept outgoing events only, not the corresponding acknowledgments/callbacks. If you want to log all callback acknowledgments, you need to modify your code by intercepting the socket.emitWithAck method instead
if (typeof callback === 'function') {
//override Ack Callback to log event callback
let tempFunc = callback;
callback = (response) => {
tempFunc(response);
logger.info(`OUTGOING_EVENT(Callback) ==> ${socket.id} ${JSON.stringify(socket.data.userData) || ''}: message with ${response}`);
}
}
I'm currently using this to override callback function inside every socket.on() event. It's not an intercepting but it's still good 😂😂. I assigned this issue for you, hopfully we will have a better solution. Thank you in advance 😘😘😘
Ops, sorry, seem i don't have assign permission....