-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatroom.html
88 lines (71 loc) · 3.08 KB
/
chatroom.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
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
<html>
<head>
<title>FSE Chat Room</title>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
</head>
<body>
<div class="row">
<div class="col-md-4"> </div>
<div class="col-md-1"> </div>
<div class="col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<div style="float:left"><h3 class="panel-title">FSE Chat Room</span></h3></div>
<div style="float:right"><a href="/" style="color:#fff"><span class="glyphicon glyphicon-log-out" aria-hidden="true"></span></a></div>
</div>
<div class="panel-body">
<div id="content">
<div class="list-group" style="height:320px; overflow: auto;" id="content-chats">
</div>
<p><input type="text" style="height:100px;" class="form-control" placeholder="Type Message" id="m">
</p></div>
<div class="jumbotron">
<p style="text-align: center;"><a href="#" id="post-chat" class="btn btn-primary" role="button">POST</a></p>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-1"> </div>
<div class="col-md-4"> </div>
</div>
<p2 id ='log'>Print username<p2>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io();
var myParagraph = document.getElementById("log");
myParagraph.innerHTML = document.cookie;
$('#post-chat').click(function(){
var msg = '{"msg" : "' + $('#m').val() + '","username" : "' + retrieveUsername(document.cookie) + '"}';
myParagraph.innerHTML = msg;
socket.emit('chat message', msg);
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
var newMessage = formChatMessage(msg);
$('#content-chats').append(newMessage);
});
function retrieveUsername(cookie){
var username = cookie.split('=')[1];
return username;
};
function formChatMessage(msg){
var newMessage = [ '<a href="#" class="list-group-item">',
'<div style="float:left; color:blue;"><h6><strong>' + msg.username + '</strong></h6></div> ',
'<div style="float:right ; color:blue;"><h6><strong>' + msg.timestamp + '</strong></h6></div>',
'<div> </div>',
'<div>'+ msg.msg + '</div></a>' ].join("\n");
return newMessage;
}
</script>
</body>
<html>