forked from SFernandoS/serv-dialogo-redes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
30 lines (28 loc) · 985 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat em Tópicos</title>
</head>
<body>
<h2>Chat em Tópicos</h2>
<input type="text" id="messageInput" placeholder="Digite uma mensagem">
<button onclick="sendMessage()">Enviar Mensagem</button>
<ul id="messages"></ul>
<script>
const userId = prompt("Digite seu ID de usuário");
const topicName = prompt("Digite o nome do tópico");
const ws = new WebSocket(`ws://localhost:8000/ws/topic/${userId}/${topicName}`);
ws.onmessage = (event) => {
const messages = document.getElementById('messages');
const message = document.createElement('li');
message.textContent = event.data;
messages.appendChild(message);
};
function sendMessage() {
const messageText = document.getElementById('messageInput').value;
ws.send(messageText);
}
</script>
</body>
</html>