Hi. I want to get the instance who called connectToServer in the client endpoint.
I can achieve it by the programmatic way.
public class BilibiliLiveClientEndpoint extends Endpoint {
public BilibiliLiveClientEndpoint(BilibiliLive bilibiliLive) {
this.bilibiliLive = bilibiliLive;
session = ContainerProvider.getWebSocketContainer().connectToServer(new BilibiliLiveClientEndpoint(this), ClientEndpointConfig.Builder.create().build(), new URI(URL));
But I can't find a way to achieve it by the annotation way.
@ClientEndpoint
public class BilibiliLiveClientEndpointAnnotated {
@OnOpen
public void onOpen(Session session) {
try {
BilibiliLive bilibiliLive = BilibiliLiveJakarta.sessionBilibiliLiveJakartaMap.get(session);
session = ContainerProvider.getWebSocketContainer().connectToServer(BilibiliLiveClientEndpointAnnotated.class, new URI(URL));
sessionBilibiliLiveJakartaMap.put(session, this);
It seems that the only way to index the instance who called connectToServer is by session. But the session is not returned if the onOpen method is not completed. so the bilibiliLive instance is null.
Is there a way to achieve it by the annotation way? Thank you.