-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
40 lines (33 loc) · 1.15 KB
/
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
31
32
33
34
35
36
37
38
39
40
<html>
<head>
<script type="text/javascript">
const ws = new WebSocket('ws://02.suportelab.com.br:15010');
// A classe `WebSocket` nos navegadores tem uma sintaxe um pouco diferente de `ws`
// Ao invés da sintax de EventEmmiter `on('open')`, você adiciona um callback
// a propriedade `onopen`.
ws.onopen = function() {
document.querySelector('#send').disabled = false;
document.querySelector('#send').addEventListener('click', function() {
var nome = document.getElementById("nome").value;
var msg2 = document.getElementById("message").value;
ws.send(nome + ': ' + msg2);
console.log(msg2);
});
};
ws.onmessage = function(msg) {
var obj = msg.utf8Data;
document.querySelector('#messages').innerHTML += `<div>${msg.data}</div>`;
};
</script>
</head>
<body>
<h1>Chat</h1>
<div>
<input id="nome" placeholder="Nome"></br>
<input id="message" placeholder="Message">
<button id="send" disabled="true">Send</button>
</div>
<div id="messages">
</div>
</body>
</html>