I'm using socket.io and express both with feathersjs. For metrics gathering I'm trying to capture round-trips for requests made both through Express as well as through socket.io.
The express side is easy with express middleware.
I can catch the socket.io inbound request via socket.use
:
const app = express(feathers());
... (set up feathers services etc.)
app.configure(socketio(function(io) {
io.use(function(socket, next) {
socket.use((packet, next) => {
... (extract the verb and pathing info from the packet)
next();
});
next();
});
});
However, I can't find any equivalent of socket.use
on the outbound/acknowledgement side. There's some events inside engine.io under the covers but I can't access them.
I'm really trying to find an equivalent set of events emitted for each request/response (the latter being the equivalent to finish
in express).
I can't use connect/disconnect events here; I want to capture each request made over the socket and the responses sent for them, regardless of the feathers service and module.
Feathers.js hooks could be used for this, but it would require passing a bunch of context from the socket.io middleware into feathers, which I was hoping to not do.
Anyone know a way to do this?
In case anyone comes here looking for a way to do this, I'm not sure why I didn't think of it sooner.
The inbound packet (available in
socket.use
) will include a function as its last parameter if it should be acknowledged.Wrapping the last function to inject my own logic worked.
pseudo-code