-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.js
38 lines (33 loc) · 962 Bytes
/
chat.js
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
var socket = io("localhost:3000");
socket.on('chat message', function (msg) {
Push.create("Science Camp Informatik Chat!", {
body: msg.message,
icon: '/cat.png',
timeout: 4000,
onClick: function () {
window.focus();
this.close();
}
});
var div = $('#muster').clone();
div.toggleClass('hidden', false);
div.find('#messageBody').text(msg.message);
div.find('#messageUser').text(msg.user);
div.find('#messageTimestamp').text(msg.timestamp);
$('#messages').append(div);
window.scrollTo(0, document.body.scrollHeight);
});
function senden() {
var message = $('#message').val();
var user = $('#user').val();
if(message){
socket.emit('chat message', {message: message, user: user});
}
$('#message').val('');
}
$(document).ready(function (e) {
$('#message').emojiPicker({
width: '200px',
height: '200px'
});
});