-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
69 lines (58 loc) · 1.78 KB
/
index.html
File metadata and controls
69 lines (58 loc) · 1.78 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
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="connection.js"></script>
<script src="api.js"></script>
<script src="ChoseUpdater.js"></script>
</head>
<body>
<form id="from" onsubmit="sendData()">
<input id="input" type="text" placeholder="Write something...">
<input id="file-input" type="file">
<input type="submit">
</form>
<div id="status"></div>
<ul id="categories">
</ul>
</body>
<script>
//Try opening a WebSocket connection
const socket = new WebSocket(new Connection('test').getWebsocketConnection())
console.log(socket)
choseUpdater();
/**
*Method for sending data (string or file)
*/
async function sendData() {
event.preventDefault()
const inputElement = document.getElementById("input")
const input = inputElement.value
const fileInput = document.getElementById("file-input").files[0]
const formData = new FormData()
if (fileInput !== undefined) {
formData.append("file", fileInput)
}
//sending a post request to the server with data
await API.sendData(fileInput === undefined ? input : formData)
}
/**
*Method for update categories
*/
function choseUpdater() {
socket.onopen = function (e) {
//if WebSocket connection success -> WebSocket start
let updater = new Updater(new UpdateWebSocket)
updater.updater()
}
socket.onerror = function (e) {
//if WebSocket connection failed -> Fetching start
let updater = new Updater(new UpdateFetch)
updater.updater()
}
}
//call the methods checkCookie every one second
setInterval(checkCookie, 1000)
</script>
</html>