-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
197 lines (168 loc) · 6.72 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Un super tchat de test">
<meta name="author" content="fkeloks">
<title>Mon super tchat</title>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/starter-template/starter-template.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/messenger/1.5.0/css/messenger.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/messenger/1.5.0/css/messenger-theme-flat.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Menu</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="">Mon super tchat</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Accueil</a></li>
<li><a href="#about">A-Propos</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row" style="margin-top: 35px;">
<div class="col-md-12">
<h1>Mon super Tchat avec NodeJs !</h1>
<form id="connect">
<div class="form-group">
<label for="name">Saisissez votre pseudonyme :</label>
<input class="form-control" type="text" id="name" name="name" placeholder="Mon pseudo" autocomplete="off" autofocus="" required="">
</div>
<div class="form-group">
<label for="password">Saississez votre mot de passe :</label>
<input class="form-control" type="password" id="password" name="password" placeholder="Mon mot de passe" autocomplete="off" required="">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" value="Me connecter">
</div>
</form>
</div>
<div class="col-md-4">
<div id="users-list" style="display:none">
<h4>Utilisateurs connectés :</h4>
<div id="users"></div>
</div>
</div>
<div class="col-md-8">
<div id="tchat" class="message-wrap col-lg-12" style="display:none">
<div id="messages" class="msg-wrap"></div>
</div>
</div>
<div class="col-md-12">
<form id="new-message" style="display:none;margin-top: 20px;">
<div class="form-group">
<label id="label" for="message">Veuillez taper un message à envoyer :</label>
<input class="form-control" type="text" name="message" id="message" minlength="3" placeholder="Mon message" required="" autocomplete="off">
</div>
</form>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/messenger/1.5.0/js/messenger.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/messenger/1.5.0/js/messenger-theme-flat.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
<script type="text/javascript">
Messenger.options = {
extraClasses: 'messenger-fixed messenger-on-top messenger-on-right',
theme: 'flat'
}
try {
var socket = io.connect('http://localhost:8080');
} catch (ex) { }
var pseudo = '';
$('#connect').on('submit', function(e) {
e.preventDefault();
let pseudo = $('#name').val();
let password = $('#password').val();
socket.emit('VerifyLogin', {pseudo: pseudo, password: password});
})
socket.on('LoginIsValid', function(isValid) {
if(isValid) {
pseudo = $('#name').val();
$('#label').prepend(pseudo + ', ');
$('title').html(pseudo + ', accès au tchat');
$('#connect').remove();
$('#tchat, #new-message, #users-list').fadeIn();
$('#message').focus();
} else {
$('#name, #password').val('');
$('#name').focus();
}
})
socket.on('NewUser', function(users) {
let usersDiv = $('#users');
usersDiv.empty();
users.forEach(function(user) {
usersDiv.append('<img src="https://api.adorable.io/avatars/60/' + user + '" title="' + user + '"></img>');
})
})
$('#new-message').submit(function(e) {
e.preventDefault();
let message = $('#message');
socket.emit('NewMessage', {message: message.val(), name: pseudo});
$('#message').val('');
})
socket.on('ShowMessages', function(message){
$('#no-message').remove();
let messagesDiv = $('#messages');
messagesDiv.append(
'<div class="media msg">' +
' <div class="media-body">' +
' <small class="pull-right time">' + message.date + '</small>' +
' <h5 class="media-heading"> ' + message.author + '</h5>' +
' <small class="col-lg-10">' + message.text + '</div>' +
'</div>'
);
messagesDiv.animate({scrollTop: messagesDiv.prop('scrollHeight')}, 250);
})
socket.on('InitMessages', function(messages){
let messagesDiv = $('#messages');
if(messages.length === 0) {
messagesDiv.append('<div class="media msg" id="no-message">Aucun message à afficher...</div>');
} else {
$('#no-message').remove();
messages.forEach(function(message){
messagesDiv.append(
'<div class="media msg">' +
' <div class="media-body">' +
' <small class="pull-right time">' + message.date + '</small>' +
' <h5 class="media-heading"> ' + message.author + '</h5>' +
' <small class="col-lg-10">' + message.text + '</div>' +
'</div>'
);
messagesDiv.animate({scrollTop: messagesDiv.prop('scrollHeight')}, 75);
});
}
})
socket.on('ShowAlert', function(alert) {
Messenger().post({
message: alert.message,
type: alert.type,
hideAfter: 3,
showCloseButton: true
});
})
</script>
</body>
</html>