From 4f294455cca677d2ddc2a8a7cf9f8d94716801a9 Mon Sep 17 00:00:00 2001 From: borissedw Date: Thu, 24 Aug 2023 16:47:24 +0300 Subject: [PATCH] 0.0.166 --- static/js/chat_sockets.js | 3 +- static/js/global_js.js | 66 +++++++++++++++++++++++++++++++++------ templates/tb_base.html | 9 ++++-- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/static/js/chat_sockets.js b/static/js/chat_sockets.js index 96ae4ac..b5387c7 100644 --- a/static/js/chat_sockets.js +++ b/static/js/chat_sockets.js @@ -14,7 +14,8 @@ function sendMessageSocket (data) { -chatSocket.onmessage = function (e) { + +function wsReceiveData (e) { let old_item_tab_user_list = inital_old_tab() let el_tab = old_item_tab_user_list[0] diff --git a/static/js/global_js.js b/static/js/global_js.js index 54330ee..bef7c71 100644 --- a/static/js/global_js.js +++ b/static/js/global_js.js @@ -23,18 +23,38 @@ function getNewMessageSession(){ } // function getSocketState () { -chatSocket.onclose = function (){ - console.log("closed") - setTimeout(onopen_ws,1000) -} -function onopen_ws (){ +// function onopen_ws (){ +// let sw_int = setInterval(function (){ +// if (chatSocket.readyState > 1){ +// chatSocket = new WebSocket(ws_url) +// // chatSocket.onopen = function (){ +// } else if (chatSocket.readyState === 1){ +// clearInterval(sw_int) +// } else { +// console.log("connecting...") +// } +// +// // } +// +// +// +// },1000) +// } + + +// } +function restart_ws (){ let sw_int = setInterval(function (){ if (chatSocket.readyState > 1){ - chatSocket = new WebSocket(ws_url) + // chatSocket = new WebSocket(ws_url) + init_ws() // chatSocket.onopen = function (){ } else if (chatSocket.readyState === 1){ + clearInterval(sw_int) + console.log("open") + } else { console.log("connecting...") } @@ -46,13 +66,41 @@ function onopen_ws (){ },1000) } -chatSocket.onopen = function (){ - console.log("open") +function init_ws () { + chatSocket = new WebSocket(ws_url); + + if (chatSocket.readyState !== 1) { + restart_ws() + } + + chatSocket.addEventListener('open',socket_open) + chatSocket.addEventListener('close',socket_close) + chatSocket.addEventListener('message',wsReceiveData) + + // chatSocket.onmessage = function (e) { + // wsReceiveData(e); + // return false; + // } + // chatSocket.onclose = function (){ + // console.log("closed") + // setTimeout(restart_ws,1000) + // + // } + // chatSocket.onopen = function (){ + // console.log("open") + // } + } -// } +function socket_open(e){ + console.log("connect") +} +function socket_close(e){ + console.log("closed") + setTimeout(restart_ws,1000) +} // var window_messages = document.querySelector(".container-messages") // function getNewMessageSession (){ diff --git a/templates/tb_base.html b/templates/tb_base.html index a612038..9c3977c 100644 --- a/templates/tb_base.html +++ b/templates/tb_base.html @@ -9,22 +9,25 @@ + + - + - +