I have clients connecting like this on a websocket
var socket = new SockJS(this.props.stomp);
var stompClient = Stomp.over(socket);
var channel = "/room."+this.props.room.uid
var app = this;
stompClient.connect({room: this.props.room.uid}, function(frame) {
....
and on my Java backend I'm trying to get this header following a tutorial:
public void onApplicationEvent(SessionConnectEvent event) {
StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
String room = sha.getNativeHeader("room").get(0);
logger.debug("Connect event [sessionId: " + sha.getSessionId() +"; room: "+ room + " ]");
}
but the room
is null at this point.
I debugged and found a very complex hierarchy: a MessageHeaderAccessor
contains a map that contains a LinkedList that have a key called nativeHeaders
that contains these native headers.
My question: is there a easy way to access this native header? so far, I only get things like
MessageHeaderAccessor accessor = NativeMessageHeaderAccessor.getAccessor(event.getMessage(), SimpMessageHeaderAccessor.class);
accessor.getMessageHeaders();
Object header = accessor.getHeader("simpConnectMessage");
GenericMessage<?> generic = (GenericMessage<?>) accessor.getHeader("simpConnectMessage");
System.out.println(generic.getHeaders().get("nativeHeaders"));
that I really found hard to understand and to use. Actually, the only thing I want is to track the current numbers of users connect to a channel and I think that implement a ApplicationListener
is the way. I might be wrong here, so if anyone found something or implemented anything similar, I would like to know