-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
68 lines (54 loc) · 1.76 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
<!doctype html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello, world!</h1>
<h2>Comm through Webview bind:</h2>
<p id='world'>no-world</p>
<h2>Comm through API:</h2>
<p id='version'>no-version</p>
<h2>Comm through Web Socket: </h2>
<h3> WP Log: </h3>
<p id='wp-log'></p>
<h3> WP Message: </h3>
<label for="l-msg">Message:</label>
<input type="text" id="i-msg" onkeyup="socket.send(this.value);"><br>
<p id='wp-message'></p>
</body>
<script>
hello().then((x) => { document.getElementById("world").innerHTML = x })
hello().then((x) => { console.log(x) })
function setVersion(v) {
document.getElementById("version").innerHTML = v;
}
function addWPLog(v) {
document.getElementById("wp-log").insertAdjacentHTML('beforeEnd', v);
document.getElementById("wp-log").insertAdjacentHTML('beforeEnd', '<br>');
}
fetch("http://localhost:8090/version")
.then(response => response.text())
.then(data => setVersion(data))
.catch(function () {
setVersion("ERROR");
});
let socket = new WebSocket("ws://127.0.0.1:8090/ws");
addWPLog("Attempting Connection...");
socket.onopen = () => {
addWPLog("Successfully Connected");
socket.send("Hi From the Client!");
};
socket.onmessage = function (event) {
document.getElementById("wp-message").insertAdjacentHTML('beforeEnd', event.data);
document.getElementById("wp-message").insertAdjacentHTML('beforeEnd', '<br>');
}
socket.onclose = event => {
addWPLog("Socket Closed Connection: ", event);
socket.send("Client Closed!")
};
socket.onerror = error => {
addWPLog("Socket Error: ", error);
};
</script>
</html>