-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.js
39 lines (32 loc) · 960 Bytes
/
Client.js
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
var socket = io();
console.log('loaded');
$('#form').submit(function() {
socket.emit('Client_Send_Username', $('#username').val());
console.log('Name is '+$('#username').val());
});
socket.on('svr_msg', function(data) {
document.getElementById('svr-messages').innerHTML = data;
});
socket.on('userlist', function(data) {
document.getElementById('userlist').innerHTML = data;
});
socket.on('Joined', function(data) {
});
socket.on('userExists', function(data) {
document.getElementById('error-container').innerHTML = data;
});
$('#message_form').submit(function() {
//socket.emit('message', $('#input').val());
var text = $('#input').val();
if (text) {
socket.emit('message', {
body: text
});
console.log('sending...');
$('#input').val('');
}
return false;
});
socket.on('newmsg', function(message) {
document.getElementById('messages').innerHTML += '<div>' + message.user + ':' + message.body + '</div>';
});