-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
69 lines (64 loc) · 3.09 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>ChatMe</title>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<div class="col-xsm-2 col-sm-8 col-md-10 col-lg-12 container ">
<br>
<div class="col-xsm-2 col-sm-8 col-md-10 col-lg-12 jumbotron">
<nav class="col-xsm-2 col-sm-4 col-md-6 col-lg-10 col-xlg-12 navbar-nav"><a href="#" class=" nav-link"><img class=" rounded-circle col-lg-1" src="./favicon.ico" alt="logo" srcset=""></a></nav>
<br>
<h1 class="col-xsm-2 col-sm-8 col-md-10 col-lg-12 display-4">send message</h1>
<br>
<input id="name" type="text" class="col-xsm-2 col-sm-8 col-md-10 col-lg-12 form-control" placeholder="Name">
<br>
<textarea id="message" type="text" class="col-xsm-2 col-sm-8 col-md-10 col-lg-12 form-control" placeholder="Message"> </textarea>
<br>
<button id="send" class="btn btn-success">send</button>
<br>
<p class="text-center display-5">Paullaster ©2020</p>
</div>
<br>
<div id="messages">
</div>
</div>
<script>
const socket = io();
$(() =>{
$("#send").click(() =>{
let message = {name: $('#name').val(), message:$('#message').val()};
postMessages(message);
});
getMessages();
});
const addMessages = (message) =>{
$("#messages").append(`<h4>${
message.name
} </h4> <p> ${message.message}</p>`)
}
socket.on('message', addMessages)
const getMessages = () =>{
$.get('http://localhost:4000/messages', (data) =>{
data.forEach(element => {
addMessages(element);
},this);
})
}
const postMessages = (message) =>{
$.post('http://localhost:4000/messages',message)
}
</script>
</body>
</html>