예제 #1
0
 @Override
 public void onApplicationEvent(SessionDisconnectEvent event) {
   ActivityDTO activityDTO = new ActivityDTO();
   activityDTO.setSessionId(event.getSessionId());
   activityDTO.setPage("logout");
   messagingTemplate.convertAndSend("/topic/tracker", activityDTO);
 }
예제 #2
0
 @MessageMapping("/hello")
 public void greeting(SimpMessageHeaderAccessor headerAccessor, HelloMessage message)
     throws Exception {
   InetSocketAddress clientAddress =
       (InetSocketAddress) headerAccessor.getSessionAttributes().get("remoteAddress");
   String ip = clientAddress.getAddress().getHostAddress();
   String host = clientAddress.getHostName();
   LOG.info("Ping client");
   Thread.sleep(1000); // simulated delay
   String greetingMsg =
       String.format("Hello, %s! From ip: %s, hostname: %s", message.getName(), ip, host);
   messagingTemplate.convertAndSend("/cg/websockets/topic/greetings", new Greeting(greetingMsg));
 }
  public void onApplicationEvent(SessionConnectEvent event) {
    MessageHeaders headers = event.getMessage().getHeaders();
    Principal user = SimpMessageHeaderAccessor.getUser(headers);
    if (user == null) {
      logger.info(event.getSource() + " Connect  user == null");
      user =
          new Principal() {

            @Override
            public String getName() {
              return "test zhxy 1";
            }
          };
    }
    String id = SimpMessageHeaderAccessor.getSessionId(headers);
    //		repository.save(new ActiveWebSocketUser(id, user.getName(), Calendar.getInstance()));
    messagingTemplate.convertAndSend("/topic/friends/signin", Arrays.asList(user.getName()));
  }
 @MessageMapping("/message")
 @SubscribeMapping("/echo")
 public void echo(Message<String> message) {
   messagingTemplate.send("/topic/echo", message);
 }