Does anyone know of any chat like

Does anyone know of any chat-like workers-rs example for websockets & durable objects? I'm trying to figure out the communication between different sockets and an example would help a lot πŸ™‚ The only examples I've found are trivial echo servers
1 Reply
radix
radixβ€’11mo ago
I'm mostly trying to figure out if I need to use something like futures-channel, or if I can just do it by keeping a Vec of Websockets (with a Mutex at some level) another thing that I am confused about is the concept of a "websocket pair" -- what is the point of that? even with just the "server" end I can both receive and send messages, so it doesn't seem like the usual concept of a split socket with send and receive sides. I'm trying to figure out if the concept of a pair helps me in the chat-like use case ok, so I got this working with a futures-channel mpsc. I'm still not 100% sure that I need the channel, but it worked. basically, for every websocket connection, I spin up two tasks: one for handling the incoming socket events (and which I also send a TX side of a channel), and one for handling broadcasts from that first task which listens to the RX side of the channel, locks a vec of WebSockets, and sends the message to each of them ok, I immediately realized how silly that design is and it turns out I don't need the two tasks at all, I can just clone & pass the Arc<RwLock<Vec<WebSocket>>> into my single task that handles incoming events, and have it broadcast to all of them without going through the channel
Want results from more Discord servers?
Add your server