https://kotlinlang.org logo
#ktor
Title
# ktor
a

Animesh Sahu

10/31/2019, 6:48 AM
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

Evan R.

10/31/2019, 1:45 PM
No, you are not allowed to extend sealed classes
a

Animesh Sahu

10/31/2019, 1:55 PM
@Evan R. Why dont they give us ability to register custom frames with custon opcodes
e

Evan R.

10/31/2019, 3:06 PM
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

Animesh Sahu

10/31/2019, 3:38 PM
@Evan R. Like discord gateway has custom packets like that i'm trying to achieve: https://imgur.com/a/seXjUYK (see top right)
e

Evan R.

10/31/2019, 3:44 PM
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

Animesh Sahu

10/31/2019, 3:45 PM
Ohh ok thanks
e

Evan R.

10/31/2019, 3:46 PM
You might honestly be better off using a library like Discord4J rather than writing directly to a websocket: https://github.com/Discord4J/Discord4J
a

Animesh Sahu

10/31/2019, 3:48 PM
😉 thanks
e

Evan R.

10/31/2019, 3:50 PM
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/