org.springframework.web.socket.messaging.SessionConnectEvent Java Examples

The following examples show how to use org.springframework.web.socket.messaging.SessionConnectEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketConnectHandler.java    From bearchoke with Apache License 2.0 7 votes vote down vote up
@Override
    public void onApplicationEvent(SessionConnectEvent event) {
        if (log.isDebugEnabled()) {
            log.debug("Caught Web Socket connect event");
        }

        MessageHeaders headers = event.getMessage().getHeaders();
        Principal user = SimpMessageHeaderAccessor.getUser(headers);

        if(user == null) {
            return;
        }

        String id = SimpMessageHeaderAccessor.getSessionId(headers);

        if (log.isDebugEnabled()) {
            log.debug("Current web socket session id: " + id);
        }

        if (StringUtils.isNotBlank(id)) {
            repository.save(new ActiveWebSocketUser(id, user.getName(), Calendar.getInstance()));
        }

//        messagingTemplate.convertAndSend("/topic/friends/signin", Arrays.asList(user.getName()));
    }
 
Example #2
Source File: EventExchange.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@EventListener
public void onSessionConnected(SessionConnectEvent event) {
    Message msg = event.getMessage();
    StompHeaderAccessor accessor = StompHeaderAccessor.wrap(msg);
    String sessionId = accessor.getSessionId();

    String spaceKey = (String) webSocketSessionStore.getAttribute(sessionId, "spaceKey");

    log.debug("Session connect: spaceKey => {}, sessionId => {} ", spaceKey, sessionId);

    if (spaceKey == null) {
        return;
    }

    boolean isToBeOnline = onlineWorkspaceStore.isEmpty(spaceKey);
    onlineWorkspaceStore.addSession(spaceKey, sessionId);

    if (isToBeOnline) {
        eventPublisher.publishEvent(new WorkspaceOnlineEvent(event, spaceKey));
    }
}
 
Example #3
Source File: WebSocketConnectHandler.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(SessionConnectEvent event) {
	MessageHeaders headers = event.getMessage().getHeaders();
	Principal user = SimpMessageHeaderAccessor.getUser(headers);
	if (user == null) {
		return;
	}
	String id = SimpMessageHeaderAccessor.getSessionId(headers);
	this.repository.save(new ActiveWebSocketUser(id, user.getName(), Calendar.getInstance()));
	this.messagingTemplate.convertAndSend("/topic/friends/signin", Collections.singletonList(user.getName()));
}