-
Hey, been using express-zod-api for a bit on a couple of projects with good success, so thanks for that. I saw this project was being built too and was using Socket.IO too so wanted to try and use this library too. Everything seems pretty good although I have one question: is it possible to send events out (emissions) to clients outside of places that are supplied with the relevant objects (like Use case: an HTTP API request that is sent to the server that then looks up a client based on metadata and if found, sends an emission, waits for an acknowledgement, and returns said data to the HTTP request. The way I did this before was to just store the clients in an external object alongside their metadata, but seeing as this library allows you to attach metadata, I wanted to give that a shot. This could be done again if it's the best solution (although typings might get a bit tricky). The other way of doing this (that actually might be considered better, but I'm not sure?) would be to convert the HTTP API call to a (socket) action, where it would then have context. That or doing something with hooks, for example storing a copy of the parameter(s) from the I know it (emitting) can be done with the raw Socket.IO class but it has no typings. There may be an undocumented way of doing this too, so I thought I'd ask in case, or maybe I missed something in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hello @zoton2 ,
It's not supposed to work that way. HTTP server is only used as transport and for handshake to upgrade the connection to websockets. Moreover, "look up a client" means that there is a client, so that it is expected to be already connected via sockets. Therefore:
— that's exactly what I'd recommend to do. So, you don't need to do any lookups. Your client emits the event (action), and you handle that action by emitting another event towards the original event owner (client). You'd not even need hooks for that. Very simple. Thank you for sharing your experience! |
Beta Was this translation helpful? Give feedback.
Hello @zoton2 ,
It's not supposed to work that way. HTTP server is only used as transport and for handshake to upgrade the connection to websockets. Moreover, "look up a client" means that there is a client, so that it is expected to be already connected via sockets. Therefore:
— that's exactly what I'd recommend to do.
So, you don't need to do any lookups. Your client emits the event (action), and you handle that action by emitting another event towards the original event owner (client). You'd not even ne…