-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.html
More file actions
38 lines (38 loc) · 1.11 KB
/
chat.html
File metadata and controls
38 lines (38 loc) · 1.11 KB
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
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
</head>
<body>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off" /><button>Send</button>
</form>
<!--<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>-->
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
// var socket = io( ,http,{'transports': ['websocket']});
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('local', function(msg){
socket.emit('my other event', { my: 'data' });
});
socket.on('local2', function(msg){
socket.emit('my other event2', { my: 'data' });
});
socket.on('timer', function(msg){
console.log('timer rise!');
// socket.close();
// socket = io();
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
</script>
</body>
</html>