-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.html
More file actions
65 lines (53 loc) · 1.93 KB
/
index.html
File metadata and controls
65 lines (53 loc) · 1.93 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
<!DOCTYPE html>
<html>
<head>
<title>Customer</title>
<style>
body { margin: 0; padding-bottom: 3rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
#order_section { display: grid; justify-items: center; align-items: center; margin-top: 100px; cursor: pointer; }
#order_button { align-self: center; width: 50%; height: 100px; font-size: large; }
#order_message { align-self: center; width: 50%; height: 100px; font-size: large; margin: 50px; }
</style>
</head>
<body>
<div id="order_section">
<button id="order_button">Order</button>
<div id="order_message"></div>
</div>
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
<script>
const socket = io('ws://localhost:3000');
socket.on('connected', function(msg) {
console.log('Customer connected')
});
const orderButton = document.getElementById('order_button');
orderButton.addEventListener('click', function(e) {
socket.emit('order_requested', {
id: Math.round(Math.random() * 10000),
item: 'Pizza'
})
});
const appendEvent = (message) => {
const orderMessageElement = document.getElementById('order_message');
const p = document.createElement('p');
p.textContent = `${message}`
orderMessageElement.append(p)
}
socket.on('processing_order', function(data) {
console.log('server_says', data)
const { message } = data;
appendEvent(message);
});
socket.on('order_accepted', function(data) {
console.log('server_says', data)
const { message } = data;
appendEvent(message);
});
socket.on('order_rejected', function(data) {
console.log('server_says', data)
const { message } = data;
appendEvent(message);
});
</script>
</body>
</html>