Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
Latest commit
99 lines (88 loc) · 2.77 KB
/
Copy pathindex.html
File metadata and controls
99 lines (88 loc) · 2.77 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<style>
body {}
.roomsContainer {
float:left;
width:100px;
border-right:1px solid black;
height:300px;
padding:10px;
overflow:scroll-y;
}
.conversationContainer {
float:left;
width:300px;
height:250px;
overflow:scroll-y;
padding:10px;
}
#data {
}
</style>
<scriptsrc="/socket.io/socket.io.js"></script>
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
//Will be adding CHATROOM LOGIC HERE
//We have Server Side funtions, now we need to add client side functions
varsocket=io.connect('http://localhost:3000');
socket.on('connect',function(){
socket.emit('addUser',prompt("What's your name"));
});
socket.on('updateChat',function(username,data){
$('#conversation').append('<b>'+username+':</b> '+data+'<br>');
});
socket.on('updateRooms',function(rooms,currentRoom){
$('#rooms').empty();
$.each(rooms,function(key,value){
if(value===currentRoom){
$('#rooms').append('<div>'
+value
+'</div>');
}else{
$('#rooms').append('<div><a href="#" onclick="switchRoom(\''+value+'\')">'
+value
+'</a></div>');
}
});
});
functionswitchRoom(room){
socket.emit('switchRoom',room);
}
//when the page loads we need to do a few things
$(function(){
//get sent data on click
$('#datasend').click(function(){
varmessage=$('#data').val();
//clear the input box
$('#data').val('');
$('#data').focus();
//send it to the server
socket.emit('sendChat',message);
});
//allow the client to use enter key
$('#data').keypress(function(e){
if(e.which==13){
$(this).blur();
//select the send box
$('#datasend').focus().click();
//Select the input box
$('#data').focus();
}
});
});
</script>
</head>
<body>
<divclass="roomsContainer">
<b>ROOMS</b>
<divid="rooms"></div>
</div>
<divclass="conversationContainer">
<divid="conversation"></div>
<inputid="data" style="width:200px;" />
<inputtype="button" id="datasend" value="send" />
</div>
</body>
</html>