Hi, I just started to use ktor websockets and I ha...
# ktor
a
Hi, I just started to use ktor websockets and I have a little comment about it. I want to broadcast a frame to all connected clients, but I didn't find a convenient way to do it with the current API. For now I have to make a class that tracks all active sessions and send frames via that class. I just want to say it would be a good feature (if I didn't miss anything)
d
To all connected clients without filtering?
a
yes
d
have you considered using a broadcast channel? Like here: https://github.com/ktorio/ktor-samples/blob/master/other/sse/src/SseApplication.kt It is for SSE but could be adapted to websockets too
But your problem is having to maintain a list of clients yourself, or to have to construct a frame per client?
c
Well, for sure it's quite expensive to do by default, perhaps we can have a feature or option for that
d
Do you miss something like:
fun Iterable<WebSocketSession>.send(frame: Frame)
?
a
Copy code
having to maintain a list of clients yourself
This one
I rather miss something like this:
fun WebSocketSession.getActiveSessions(): Iterable<WebSocketSession>
or
fun ApplicationEngineEnvironment.getActiveSessions(): Iterable<WebSocketSession>
👌 1
d
Not sure if it possible to intercept only websocket calls, so a feature could do this.