-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add broadcast-packet send-socket-packet events #78
Conversation
@ddrachov well, that's interesting, thanks for this 👍 There is another API suggestion here: socketio/socket.io#4145. Would it suit your use case? |
@darrachequesne Hey, the socketio/socket.io#4145 is good, but unfortunately it will not intercept events which are going through adapter reason of how adapters implemented. All of them use the broadcast method of base adapter class which in turn do not use emit of Socket/Namespace/BroadcastOperator classes. As well socketio/socket.io#4145 will not intercept emit on namespace cause it uses broadcast operator which is using broadcast method of adapter. The main disadvantage is that there is no single place except engine where we could add our function to intercept all outgoing events. |
Hmm, you are absolutely right.
As a matter of fact, you can already do that: io.on("connection", (socket) => {
socket.conn.on("packet", ({ type, data }) => {
// called for each packet received
});
socket.conn.on("packetCreate", ({ type, data }) => {
// called for each packet sent
});
}); I've included it in the documentation: https://socket.io/docs/v4/server-socket-instance/#socketconn The Does it cover your use case? |
@darrachequesne That one is good. Did not know about those events. It could stop working if underlying engine will be changed? |
No, the compression is applied after that.
That's unlikely, but in any case, the change would be backward incompatible and would require a new major version. So I think you can rely on those events. |
This feature was implemented in version 4.5.0: socket.onAnyOutgoing((event, ...args) => {
console.log(event);
}); Thanks for the work on this 👍 |
Adding new events on adapter instance to be able to add aspects like logger or metric to events which are emitter by socket.io-(*)-emitters.
Could you please point me where could I update that page with new events if you fine with that change.