This website works better with JavaScript.
Home
Explore
Help
Sign In
Mobile-Devices-ITM
/
socket-io-chat
generated from
gmarx/git-template
Watch
1
Star
0
Fork
0
Code
Issues
0
Pull Requests
0
Projects
0
Releases
0
Wiki
Activity
Browse Source
emitting events
master
Gerardo Marx Chávez-Campos
2 years ago
parent
820bc6af59
commit
c84088e69d
2 changed files
with
14 additions
and
1 deletions
Split View
Diff Options
Show Stats
Download Patch File
Download Diff File
+11
-1
index.html
+3
-0
index.js
+ 11
- 1
index.html
View File
@ -22,7 +22,17 @@
<
/
form
>
<
script
src
=
"/socket.io/socket.io.js"
>
<
/
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
>
<
/
body
>
<
/
html
>
+ 3
- 0
index.js
View File
@ -14,6 +14,9 @@ io.on('connection', (socket) => {
socket
.
on
(
'disconnect'
,
(
)
=>
{
console
.
log
(
'user disconnected'
)
;
}
)
;
socket
.
on
(
'chat message'
,
(
msg
)
=>
{
console
.
log
(
'message: '
+
msg
)
;
}
)
;
}
)
;
server
.
listen
(
3030
,
(
)
=>
{
Write
Preview
Loading…
Cancel
Save