How to broadcast message to all active websocket connections?
When I try to store the
WebSocket
object in an array and call send()
on each of them I'll get
4 Replies
Hmm, websockets shouldn't be triggering this. Can you share a bit of your code where you're broadcasting from?
I tried to make a minimal repro, it still fails but with a different error msg
ah, so you're within a worker - yeah that won't work during testing, and won't be of much use when uploaded either
Cloudflare deploys your worker to thousands of servers, and any one might be serving a request, so it's unlikely for all clients to be connected to a single metal
I recommend using Durable Objects and the websocket hibernation api, where you can bring this guarantee in
oh I see, that makes sense, thank you!