Ura - 26. 11. 2022

This commit is contained in:
Gašper Dobrovoljc committed 2022-11-26 16:28:11 +01:00
commit b23ab042f3
7 files changed
+1582

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script src="/socket.io/socket.io.js"></script>
<script defer src="script.js"></script>
</head>
<body>
<input id="input" type="text" />
<button id="send">Send</button>
<div id="chat"></div>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
const input = document.getElementById('input');
const button = document.getElementById('send');
const chat = document.getElementById('chat');
const name = prompt('Enter your name');
const socket = io();
socket.on('connect', () => {
console.log('connected');
socket.emit('name', name);
});
socket.on('text', (text) => {
console.log(text);
addText(text);
});
button.addEventListener('click', () => {
socket.emit('text', input.value);
addText(input.value);
});
function addText(text) {
const p = document.createElement('p');
p.innerText = text;
chat.appendChild(p);
}