Is there a way to extend frame class, it is "actua...
# ktor
a
Is there a way to extend frame class, it is "actual sealed" in package io.ktor.http.cio.websocket, but one should not restrict to have only Text and Binary frames cuz its very hard to send packets for different-different purposes.
e
No, you are not allowed to extend sealed classes
a
@Evan R. Why dont they give us ability to register custom frames with custon opcodes
e
Because those frames and opcodes are part of the websocket specification: https://tools.ietf.org/html/rfc6455#section-5.2 It’s a low-level implementation detail. What other type of data are you trying to send over the websocket?
a
@Evan R. Like discord gateway has custom packets like that i'm trying to achieve: https://imgur.com/a/seXjUYK (see top right)
e
Discord doesn’t have custom packets on their websocket API. According to their docs, those pieces of data like opcodes and such are just JSON encoded strings sent as the payload of the frame, so you’d be sending a payload like
{"op": 10, "d": { "heartbeat_interval": ... }
as a text frame over the websocket for the HELLO operation
a
Ohh ok thanks
e
You might honestly be better off using a library like Discord4J rather than writing directly to a websocket: https://github.com/Discord4J/Discord4J
a
😉 thanks
e
If you still wanna use coroutines with that library though you can use the coroutines reactive extensions: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/