-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
61 lines (60 loc) · 1.76 KB
/
index.html
File metadata and controls
61 lines (60 loc) · 1.76 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<head>
<title>Chatnow</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script>
var socket = io.connect('http://chat.nocarrots.com');
//var socket = io.connect('http://localhost');
var id;
socket.on('msg', function (data){
var chatlog = $("#chatlog");
chatlog.append(data['id'] + ": " + data['msg'] + "\n");
chatlog.scrollTop(chatlog[0].scrollHeight);
});
socket.on('welcome', function (data){
id = data['id'];
$('#id').html(id);
var active_users = data['num_users'];
$('#active_users').html(active_users);
});
socket.on('users_update', function (data){
var active_users = data['num_users'];
$('#active_users').html(active_users);
});
function send_message(){
var m = $("<div>").text($("#msg").val()).html();
$("#msg").val("");
var chatlog = $("#chatlog");
chatlog.append(id + ": " + m + "\n");
chatlog.scrollTop(chatlog[0].scrollHeight);
socket.emit('msg', { msg : m, id: id });
}
$('document').ready(function(){
$("#msg").keypress(function(e){
if(e.which == 13){
send_message();
}
});
});
</script>
</head>
<body>
<div id="chatwrapper">
<div id="id_container">
Your ID is: <span id='id'></span>
</div>
<div id="active_users_container">
Users connected: <span id='active_users'></span>
</div>
<br/>
<textarea id="chatlog" readonly="readonly"></textarea>
<br/>
<input id="msg" type="text"></input>
<input id="submit" type="submit" value="Submit" onclick="send_message()"></input>
<br/>
<br/>
</div>
</body>
</html>