This commit is contained in:
2023-08-12 14:37:27 +03:00
parent f5c709eb7b
commit 437ee3066f

View File

@@ -21,32 +21,48 @@
let url = `ws://localhost:8000/ws/socket-server/`; let url = `ws://localhost:8000/ws/socket-server/`;
//
// const chatSocket = new WebSocket(url);
const chatSocket = new WebSocket(url); // chatSocket.onmessage = function (e) {
// let data = JSON.parse(e.data)
chatSocket.onmessage = function (e) { // console.log('Data: ', data)
let data = JSON.parse(e.data) // }
console.log('Data: ', data)
}
// chatSocket.onopen = function () { // chatSocket.onopen = function () {
// console.log("open") // console.log("open")
// } // }
// function open_socket () { // // function open_socket () {
chatSocket.onopen = function(){ // chatSocket.onopen = function(){
console.log("open") // console.log("open")
} // // chatSocket
// }
// } // }
chatSocket.onclose = function () { // var i = 0
console.log("close")
}
function sendMessageSocket (data) { function sendMessageSocket (data) {
let chatSocket = new WebSocket(url);
chatSocket.onopen = function (){
console.log("open")
chatSocket.send(JSON.stringify(data))
}
chatSocket.onclose = function () {
console.log("close")
return false
}
// //
// }
// open_socket() // open_socket()
chatSocket.send(JSON.stringify(data)) // chatSocket.OPEN
// chatSocket.onopen = function (){
// console.log("open")
//
// } // }
} }