Sending private messages can be a little bit trickier than sending public ones. Let’s take a look at the JavaScript code, shown here:
function sendMessage() {
var instantMessage;
if (spanSendTo.text() == "public") {
instantMessage = {
'text' : inputMessage.val()
}
} else {
instantMessage = {
'text' : inputMessage.val(),
'toUser' : spanSendTo.text()
}
}
stompClient.send("/chatroom/send.message", {}, JSON.stringify(instantMessage));
inputMessage.val("").focus();
}
When the client sends a private message in the ...