diff --git a/src/main/resources/static/js/main.js b/src/main/resources/static/js/main.js index 503892a..3f84f6b 100644 --- a/src/main/resources/static/js/main.js +++ b/src/main/resources/static/js/main.js @@ -119,3 +119,14 @@ function getAvatarColor(messageSender) { usernameForm.addEventListener('submit', connect, true) messageForm.addEventListener('submit', send, true) + +// Notification message when user leaves the chat +window.onbeforeunload = sendLeaveMessage +function sendLeaveMessage() { + var chatMessage = { + sender: username, + type: 'LEAVE' + }; + stompClient.send("/app/chat.send", {}, JSON.stringify(chatMessage)); + return null +}