`wsBefore` gives access to a `WsHandler` object, b...
# javalin
r
wsBefore
gives access to a
WsHandler
object, but it doesn't have attributes (like
Context
available in
before
). Is there any way to create an interceptor/filter for websockets and pass custom data to websocket handlers (preferably to just put an attribute to
WsContext
)?
d
i don’t think so, jetty destroys the original request pretty fast
you’ll have to make your own map to keep track of it, i think 🤔
r
Can I define two
onConnect
handlers? Will both run? In the same order? Will both work on the same
WsContext
?
Copy code
app.wsBefore { ws ->
        ws.onConnect { ctx ->
            ctx.attribute("key", "testValue")
        }
    }
    <http://app.ws|app.ws>("/path") { ws ->
        ws.onConnect { ctx ->
            val v = ctx.attribute<String>("key")
            // will this work ?
        }
    }
d
this will most likely work, but
onConnect
in a
wsBefore
and
onMessage
in a
ws
might not (since Jetty has probably killed the upgrade-request by then)
r
I'm testing this now. onConnect should be enough for me.
Is
WsHandler
instance shared by all clients?
I see it is
Ok, I've managed to make it work Thx for help
t
Is
WsHandler
instance shared by all clients?
that's a strange way of thinking about
it's a bit like asking if a
Handler
in `get("/") { ... }`` is shared by all request to
/
there's no shared state between clients