Browse Source

broadcasting

master
parent
commit
74a5264c14
2 changed files with 9 additions and 0 deletions
  1. +7
    -0
      index.html
  2. +2
    -0
      index.js

+ 7
- 0
index.html View File

@ -33,6 +33,13 @@
input.value = ''; input.value = '';
} }
}); });
socket.on('chat message', function(msg) {
var item = document.createElement('li');
item.textContent = msg;
messages.appendChild(item);
window.scrollTo(0, document.body.scrollHeight);
});
</script> </script>
</body> </body>
</html> </html>

+ 2
- 0
index.js View File

@ -16,7 +16,9 @@ io.on('connection', (socket) => {
}); });
socket.on('chat message', (msg) =>{ socket.on('chat message', (msg) =>{
console.log('message: ' + msg); console.log('message: ' + msg);
io.emit('chat message', msg);
}); });
}); });
server.listen(3030, () => { server.listen(3030, () => {


Loading…
Cancel
Save