-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
55 lines (49 loc) · 1.64 KB
/
index.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<html>
<head>
<title>EmrChat</title>
<script src="/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<div id="username">
<input type="text" name="usernameTxt" /> <input type="button" name="setUsername" value="Set Username" />
</div>
<div id="sendChat" style="display:none;">
<input type="text" name="chatTxt" /> <input type="button" name="sendBtn" value="Send" />
</div>
<br />
<div id="content"></div>
<script>
$(document).ready(function() {
var username = "anonymous";
$('input[name=setUsername]').click(function(){
if($('input[name=usernameTxt]').val() != ""){
username = $('input[name=usernameTxt]').val();
var msg = {type:'setUsername',user:username};
socket.json.send(msg);
}
$('#username').slideUp("slow",function(){
$('#sendChat').slideDown("slow");
});
});
var socket = new io.connect('http://localhost');
var content = $('#content');
socket.on('connect', function() {
console.log("Connected");
});
socket.on('message', function(message){
content.append(message + '<br />');
}) ;
socket.on('disconnect', function() {
console.log('disconnected');
content.html("<b>Disconnected!</b>");
});
$("input[name=sendBtn]").click(function(){
var msg = {type:'chat',message:username + " : " + $("input[name=chatTxt]").val()}
socket.json.send(msg);
$("input[name=chatTxt]").val("");
});
});
</script>
</body>
</html>