Quei
Explore posts from serversReusable websocket component
No, no, you got me completely right... I couldn't figure out how to reuse the connection from
server\api\websocket.ts
, so I just created a new "client" to send the messages.
In a later stage, server\api\websocket.ts
will be secured so that only the server can send messages.
The browser will also connect to server\api\websocket.ts
, but it will only be the consumer of the messages in the end.
And this will be the baseline for my reactivity—when something changes in the backend, I'll notify all consumers to update via a regular API call.49 replies
Reusable websocket component
I’m also a bit puzzled when I read this. It should actually be global according to how it’s used, but I need to test it. It’s clearly stated here that it’s global:
https://nuxt-socket-io.netlify.app/usage/
49 replies
Reusable websocket component
If I take a look at this guide:
https://socket.io/how-to/use-with-nuxt It looks like it's exactly what I was searching for. I just need to trigger
https://socket.io/how-to/use-with-nuxt It looks like it's exactly what I was searching for. I just need to trigger
socket.emit("blabla")
.49 replies
Reusable websocket component
With the alternative using sockets, for example, I don’t need to worry about cleaning up entries, and I also don’t really need to care about who is connected and who isn’t (which I think is similar to KV). I can simply send a message to consumers, and it’s not permanent, meaning I don’t have to clean it up after sending or setting something.
49 replies
Reusable websocket component
Hmm, you’re using a temporary store and all consumers will read from there. Isn’t that kind of an ugly solution? Then I’d also need to delete the entries from time to time, and the frontend would need extra logic to handle that too.
I did something similar in the past with Socket.io, and I was hoping to use a built-in feature in Nuxt this time. If I can’t figure out how to do this, I’ll need to install the Socket.io package again.
49 replies
Reusable websocket component
I think we're not talking about the same thing! 🙂 I adapted the example from here:
https://stackblitz.com/edit/nitro-web-sockets-fmeygr?file=server%2Fservice%2Fmail%2FparseEmail.ts I hope this example makes things clearer! I know how to send and react to messages inside
https://stackblitz.com/edit/nitro-web-sockets-fmeygr?file=server%2Fservice%2Fmail%2FparseEmail.ts I hope this example makes things clearer! I know how to send and react to messages inside
_ws.ts
, but I’m unsure how to reuse this to send a message from another component to the same "room."
I created service/mail/parseEmail.ts
to clarify what I want to do. As a test, I simply created a function that logs a message every 10 seconds, and // message('newMail') ???
is a placeholder where it should send something to all peers.
Hopefully, this makes the problem clearer! It would be awesome if you could replace the placeholder with something that works 😄49 replies
Reusable websocket component
If by "dedicated message bus" you mean a topic where the "clients" (in this case, the frontend) subscribe, then yes, that's exactly what I'm trying to do. The example above is just a quick and dirty implementation to see if it would work in my existing project—and yes, it does! Now, I’m at the stage where I want to implement the WebSockets more cleanly.
49 replies