Open Bastitron opened 2 months ago
I think it makes sense to support WebSockets, but I also think it'd make more sense if we'd keep these listeners a bit more connected to each other. Maybe something like:
interface WebsocketHandler {
fun onConnect(ctx: WsContext) {}
fun onError(ctx: WsContext) {}
fun onClose(ctx: WsContext) {}
fun onMessage(ctx: WsContext) {}
}
// -- example impl:
@Endpoints("/api")
class ExampleEndpoints(val exampleService: ExampleService) {
@Get("/get/{id}")
fun findById(Context ctx) {
// ...
}
@Ws("/connect")
fun connect(): WebsocketHandler {
return ExampleWs()
}
inner class ExampleWs : WebsocketHandler {
private var internalState = "monke"
override fun onConnect(ctx: WsContext) {
this.internalState = exampleService.doSomething()
}
}
}
Good point, I would enjoy this kind of implementation.
Would be nice to have annotations for websocket handling. It would make sense to make them work just like the other annotations: