Added new websocket endpoint

This commit is contained in:
Rohan Sircar 2020-08-06 19:35:46 +05:30
parent 5f01174764
commit 21fa7b5e64
2 changed files with 15 additions and 3 deletions

View File

@ -1,5 +1,8 @@
package org.ros.chatto.websocket;
import javax.validation.Valid;
import org.ros.chatto.model.ChatMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.SimpMessagingTemplate;
@ -14,11 +17,20 @@ public class WebSocketController {
private final SimpMessagingTemplate smt;
@MessageMapping("/chat2")
// @SendTo("/topic/messages")
// @SendToUser("/queue/reply")
public void send2(@Payload final Message message) throws Exception {
smt.convertAndSendToUser(message.getTo(), "/queue/reply", message);
// return message;
}
@MessageMapping("/chat")
// @SendTo("/topic/messages")
// @SendToUser("/queue/reply")
public void send(@Payload final Message message) throws Exception {
smt.convertAndSendToUser(message.getTo(), "/queue/reply", message);
public void send(@Valid final ChatMessage message) throws Exception {
smt.convertAndSendToUser(message.getToUser().getUserName(),
"/queue/reply", message);
// return message;
}

View File

@ -14,7 +14,7 @@
}
function connect() {
var socket = new SockJS('/chat');
var socket = new SockJS('/chat2');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
setConnected(true);