This commit is contained in:
2023-08-24 16:47:24 +03:00
parent fa360267a0
commit 4f294455cc
3 changed files with 65 additions and 13 deletions

View File

@@ -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]

View File

@@ -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 (){

View File

@@ -9,22 +9,25 @@
<script src='{% static "js/jquery_v3_6_4.js" %}'> </script>
<script src='{% static "js/chat_sockets.js" %}'></script>
<script src="{% static "js/global_js.js" %}"></script>
<script>
{#var user_id = {{ user.id }}#}
ws_url = `ws://{% get_ws_address %}/ws/socket-server/?user_id={{ user.id }}`;
let chatSocket = new WebSocket(ws_url);
var chatSocket;
init_ws()
const beep = new Audio('/static/sounds/beep_2.mp3')
</script>
<script src='{% static "js/chat_sockets.js" %}'></script>
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<link rel="stylesheet" href="{% static 'css/styles(boris).css' %}" >
<script src="{% static "js/global_js.js" %}"></script>