diff --git a/static/js/chat_socket_start.js b/static/js/chat_socket_start.js new file mode 100644 index 0000000..270de63 --- /dev/null +++ b/static/js/chat_socket_start.js @@ -0,0 +1,142 @@ + + + + + + // let window_messages = document.querySelector(".container-messages") + // let new_timeout_time; + // if (window_messages !== null){ + // // check_new_messages(window) + // new_timeout_time = short_timeout + // } else { + // new_timeout_time = long_timeout + // } + // if (check_msg !== null){ + // clearInterval(check_msg) + // } + // check_new_messages_timeout(new_timeout_time) +} + +// function getSocketState () { + +// 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) + init_ws() + // chatSocket.onopen = function (){ + } else if (chatSocket.readyState === 1){ + + clearInterval(sw_int) + console.log("open") + + } else { + + console.log("connecting...") + } + + // } + + + + },1000) +} + +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 middleWareJS (){ +// let prs_ = null +// // if (r !== 'undefined' && r !== null && r !== ""){ +// // +// // let prs = JSON.parse(r) +// // prs_ = JSON.parse(r) +// // } else { +// // // +// // } +// // let r = getCookieValue('user_alerts') +// // +// // return prs_; +// +// } + +// var res_cookie = null +// var name_cookie = null +// +// // var old_cookeis = document.cookie +// // var name_delete = null +// +// function getCookieValue(name_1) { +// name_cookie = name_1 +// let cur_state = document.cookie; +// +// let finded_str = ''; +// let cur_state_by_opts = cur_state.split('; '); +// for (let i=0; i= 0) { +// finded_str = cur_state_by_opts[i]; +// delete cur_state_by_opts[i]; +// } +// } +// let save_str = cur_state_by_opts.join('; '); +// +// let result = document.cookie.match("(^|[^;]+)\s*" + name_1 + "\s*=\s*([^;]+)") +// res_cookie = result ? result.pop() : "" +// return res_cookie +// // name_delete = name +// } \ No newline at end of file diff --git a/static/js/global_js.js b/static/js/global_js.js index 7675735..d4cea57 100644 --- a/static/js/global_js.js +++ b/static/js/global_js.js @@ -22,104 +22,6 @@ function middleWareJS(){ } - - - - - - // let window_messages = document.querySelector(".container-messages") - // let new_timeout_time; - // if (window_messages !== null){ - // // check_new_messages(window) - // new_timeout_time = short_timeout - // } else { - // new_timeout_time = long_timeout - // } - // if (check_msg !== null){ - // clearInterval(check_msg) - // } - // check_new_messages_timeout(new_timeout_time) -} - -// function getSocketState () { - -// 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) - init_ws() - // chatSocket.onopen = function (){ - } else if (chatSocket.readyState === 1){ - - clearInterval(sw_int) - console.log("open") - - } else { - - console.log("connecting...") - } - - // } - - - - },1000) -} - -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) } document.addEventListener('DOMContentLoaded', function() { @@ -139,12 +41,13 @@ document.addEventListener('DOMContentLoaded', function() { window.addEventListener('scroll', () => { let headerBG = document.getElementById('header_bg') - headerBG.style.backgroundColor = 'rgb(248 248 248 / 90%)' - headerBG.style.padding = '20px 40px' + headerBG.style.backgroundColor = 'rgb(248 248 248 / 90%)' + headerBG.style.padding = '20px 40px' // headerBG.style.paddingBottom = 'padding: 10px 40px 10px 40px' // headerBG.style.paddingRight = 'padding: 10px 40px 10px 40px' // headerBG.style.paddingLeft = 'padding: 10px 40px 10px 40px' }) + // Действия при изменении URL @@ -166,45 +69,3 @@ window.addEventListener('scroll', () => { -// var window_messages = document.querySelector(".container-messages") - -// function middleWareJS (){ -// let prs_ = null -// // if (r !== 'undefined' && r !== null && r !== ""){ -// // -// // let prs = JSON.parse(r) -// // prs_ = JSON.parse(r) -// // } else { -// // // -// // } -// // let r = getCookieValue('user_alerts') -// // -// // return prs_; -// -// } - -// var res_cookie = null -// var name_cookie = null -// -// // var old_cookeis = document.cookie -// // var name_delete = null -// -// function getCookieValue(name_1) { -// name_cookie = name_1 -// let cur_state = document.cookie; -// -// let finded_str = ''; -// let cur_state_by_opts = cur_state.split('; '); -// for (let i=0; i= 0) { -// finded_str = cur_state_by_opts[i]; -// delete cur_state_by_opts[i]; -// } -// } -// let save_str = cur_state_by_opts.join('; '); -// -// let result = document.cookie.match("(^|[^;]+)\s*" + name_1 + "\s*=\s*([^;]+)") -// res_cookie = result ? result.pop() : "" -// return res_cookie -// // name_delete = name -// } \ No newline at end of file