document.addEventListener('DOMContentLoaded', function(){
const messagesContainer = document.querySelector("#messages_container");
const messageInput = document.querySelector("[name=message_input]");
const sendMessageButton = document.querySelector("[name=send_message_button]");
let websocket = new WebSocket("wss://212.113.133.150:8080");
websocket.onopen = () => {
console.log('Client connected');
sendMessageButton.onclick = () =>{
websocket.send(messageInput.value);
messageInput.value = "";
};
};
websocket.onmessage = (message) =>{
const newMessage = document.createElement('div');
newMessage.innerHTML = message.data;
messagesContainer.appendChild(newMessage);
};
}, false);