0.0.118
This commit is contained in:
@@ -4,17 +4,7 @@
|
|||||||
// localStorage.setItem('senderName', senderName);
|
// localStorage.setItem('senderName', senderName);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// chatSocket.onmessage = function (e) {
|
|
||||||
// let data = JSON.parse(e.data);
|
|
||||||
// console.log('Data:', data);
|
|
||||||
//
|
//
|
||||||
// if (data.type === 'chat') {
|
|
||||||
// let messages = document.getElementById('messages')
|
|
||||||
// let cssClass = data.sender === senderName? 'sender' : 'receiver';
|
|
||||||
// messages.insertAdjacentHTML('beforeend', `<div class="${cssClass}">
|
|
||||||
// <p>${data.message}</p>
|
|
||||||
// </div>`)
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// let form = document.getElementById('form')
|
// let form = document.getElementById('form')
|
||||||
// form.addEventListener('submit', (e) => {
|
// form.addEventListener('submit', (e) => {
|
||||||
@@ -42,20 +32,31 @@ chatSocket.onmessage = function (e) {
|
|||||||
// chatSocket.onopen = function () {
|
// chatSocket.onopen = function () {
|
||||||
// console.log("open")
|
// console.log("open")
|
||||||
// }
|
// }
|
||||||
|
function open_socket () {
|
||||||
chatSocket.onopen = function(){
|
chatSocket.onopen = function(){
|
||||||
console.log("open")
|
console.log("open")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
chatSocket.onclose = function () {
|
chatSocket.onclose = function () {
|
||||||
console.log("close")
|
console.log("close")
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessageSocket (data) {
|
function sendMessageSocket (data) {
|
||||||
//
|
//
|
||||||
|
// open_socket()
|
||||||
chatSocket.send(JSON.stringify(data))
|
chatSocket.send(JSON.stringify(data))
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
chatSocket.onmessage = function (e) {
|
||||||
|
let data = JSON.parse(e.data);
|
||||||
|
console.log('Data:', data);
|
||||||
|
console.log("return")
|
||||||
|
if (data.type === 'chat'){
|
||||||
|
document.querySelector(".container-messages").innerHTML = data.html;
|
||||||
|
document.querySelector(".enter-message-inp").focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user