When completed, create an example project like this one: http://sparkjava.com/tutorials/websocket-chat to show the feature.
Check Javalin implementation: https://javalin.io/documentation#websockets
This task is composed of two big areas:
1. Define the DSL to handle Websockets
The DSL will implement methods to add routes of WS type inside the router. I.e.:
Router {
webSocket("/path") {
onConnect {
send("Message back")
}
onError {
send("Message back")
}
onMessage {
send("Message back")
}
onClose {
send("Message back")
}
}
}
All callbacks will have a context
to send/receive data to the client. This context will hold
methods to get/set attributes, headers, etc.
2. Implement the routes on adapters
The above step will add a list of routes to the router. On the adapters implementations, these
routes will be converted into the adapter's library format in the fun startup(server: Server)
method.
You can check the implementation of this method on the
http_server_jetty/src/main/kotlin/JettyServletAdapter.kt
file, but the actual logic is also on the
http_server_servlet/src/main/kotlin/ServletFilter.kt
file.