Browse Source

emitting events

master
parent
commit
c84088e69d
2 changed files with 14 additions and 1 deletions
  1. +11
    -1
      index.html
  2. +3
    -0
      index.js

+ 11
- 1
index.html View File

@ -22,7 +22,17 @@
</form> </form>
<script src="/socket.io/socket.io.js"></script> <script src="/socket.io/socket.io.js"></script>
<script> <script>
var socket = io();
var socket = io();
var form = document.getElementById('form');
var input = document.getElementById('input');
form.addEventListener('submit', function(e) {
e.preventDefault();
if (input.value) {
socket.emit('chat message', input.value);
input.value = '';
}
});
</script> </script>
</body> </body>
</html> </html>

+ 3
- 0
index.js View File

@ -14,6 +14,9 @@ io.on('connection', (socket) => {
socket.on('disconnect', () => { socket.on('disconnect', () => {
console.log('user disconnected'); console.log('user disconnected');
}); });
socket.on('chat message', (msg) =>{
console.log('message: ' + msg);
});
}); });
server.listen(3030, () => { server.listen(3030, () => {


Loading…
Cancel
Save