socket.io + tRPC
I have a socket.io backend with nodejs/express, and a frontend with react.
I have a list of posts that users can delete.
Everytime a user deletes a post, it will send a websocket broadcast to all the other users so it will delete that post from everyone else's screen as well.
My question is how should I implement this? Here is a few options I've considered:
option 1. Instead of using normal trpc routes, when the user presses delete the frontend will send a websocket, and in the websocket on the server it will delete the post, and if its successful then it will broadcast to everyone else, entirely skipping the need for an API delete fetch.
option 2: The frontend will send a fetch delete to the API, and if its successful then the frontend will then send a websocket which will broadcast to everyone else (there seems to be extra steps here)
option 3: The frontend will send a fetch delete to the API, and if its successful then the backend will send a websocket broadcast to everyone else ( I don't know if its possible to do this because socket.io websockets are inside their own "io.on" function and seperate from the trpc routes. )
2 Replies