started chat-io
parent
298fb1b1d2
commit
77ee55eddb
@ -1,10 +1,44 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> Chat App </title>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1> Hello from the other side, at least I can say that i've tried </h1>
|
<h1> Chad Chat </h1>
|
||||||
|
<ul id='messages'></ul>
|
||||||
|
<form id='form'>
|
||||||
|
<input id='input' autocomplete='off'/><button type='submit'>Send</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p> to tell you I'm sorry, for breaking your heart </p>
|
|
||||||
|
|
||||||
<script src='/socket.io/socket.io.js'> </script>
|
<script src='/socket.io/socket.io.js'> </script>
|
||||||
<script> var socket = io(); </script>
|
<script>
|
||||||
|
const socket = io();
|
||||||
|
const form = document.getElementById('form');
|
||||||
|
const input = document.getElementById('input');
|
||||||
|
const messages = document.getElementById('messages');
|
||||||
|
|
||||||
|
//Send msg
|
||||||
|
|
||||||
|
form.addEventListener('submit', function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
if(input.value){
|
||||||
|
socket.emit('chat message', input.value);
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//handler
|
||||||
|
socket.on('chat message', function(msg){
|
||||||
|
const item = document.createElement('li');
|
||||||
|
item.textContent = msg;
|
||||||
|
messages.appendChild(item);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
Reference in New Issue