Websockets connected clients count
Hi, I'd like to know how to get the amount of connected clients.
6 Replies
Thank you for anyone's help in advance.
I believe you have to track them on your app side, it's not something that the protocol does automatically for you. Maybe use something like redis if your function is executed in serverless environments?
If you were on a server, you could have created a global variable which increments and decrements on
onOpen
and onClose
but for workers you will need to store this value on an external storage solutions like KV
or DurableObject
unfortunately you will have manually keep track of it
Thank you everyone for your help
add solved tag