use of com.github.chipolaris.bootforum.messaging.SystemMessage in project BootForum by chipolaris.
the class WebSocketEventsListener method handleSessionDisconnectEvent.
@EventListener
private void handleSessionDisconnectEvent(SessionDisconnectEvent event) {
String username = "Anonymous";
Principal user = event.getUser();
if (user != null) {
username = user.getName();
}
logger.info(String.format("Disconnect username: %s", username));
chatManager.removeConnectedUser(username);
this.template.convertAndSend("/system", new SystemMessage(String.format("User \"%s\" disconnected", username), System.currentTimeMillis()));
// remove subscriptions to each chat room if exists
Message<byte[]> message = event.getMessage();
SimpMessageHeaderAccessor simpMessageHeaderAccessor = SimpMessageHeaderAccessor.wrap(message);
Map<String, Object> sessionAttributes = simpMessageHeaderAccessor.getSessionAttributes();
if (sessionAttributes.size() > 0) {
for (String key : sessionAttributes.keySet()) {
String simpDestination = (String) sessionAttributes.get(key);
boolean removeResult = chatManager.removeSubscribedUser(simpDestination, username);
if (removeResult) {
logger.info(String.format("User %s unsubscribes from simpDestination: %s", username, simpDestination));
this.template.convertAndSend(simpDestination, new RoomMessage(username, "leave", System.currentTimeMillis(), null));
} else {
logger.info(String.format("A session from user %s unsubscribes to simpDestination: %s", username, simpDestination));
}
}
}
}
use of com.github.chipolaris.bootforum.messaging.SystemMessage in project BootForum by chipolaris.
the class WebSocketEventsListener method handleSessionConnectedEvent.
@EventListener
private void handleSessionConnectedEvent(SessionConnectedEvent event) {
String username = "Anonymous";
Principal user = event.getUser();
if (user != null) {
username = user.getName();
}
logger.info(String.format("Connect username: %s", username));
chatManager.addConnectedUser(username);
this.template.convertAndSend("/system", new SystemMessage(String.format("User \"%s\" connected", username), System.currentTimeMillis()));
}
Aggregations