From eb0c1431669d3c7f6bf18a23bcdf8269a12d4a83 Mon Sep 17 00:00:00 2001 From: borissedw Date: Sun, 13 Aug 2023 13:41:44 +0300 Subject: [PATCH] 0.0.122 --- static/js/chat_sockets.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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) } }