diff --git a/static/js/chat_sockets.js b/static/js/chat_sockets.js index 02fbace..c276540 100644 --- a/static/js/chat_sockets.js +++ b/static/js/chat_sockets.js @@ -41,11 +41,12 @@ // var i = 0 +window.onload = function (){ + let user_id = document.querySelector(".button_profile_header").dataset['userId'] + let url = `ws://localhost:8000/ws/socket-server/?user_id=${user_id}`; -let url = `ws://localhost:8000/ws/socket-server/`; - -const chatSocket = new WebSocket(url); - + const chatSocket = new WebSocket(url); +} function sendMessageSocket (data) { chatSocket.send(JSON.stringify(data)); } @@ -58,6 +59,8 @@ chatSocket.onmessage = function (e) { if (data.type === 'chat'){ document.querySelector(".container-messages").innerHTML = data.html; document.querySelector(".enter-message-inp").focus() + } else if (data.type === "echo"){ + console.log(data) } }