-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
77 lines (68 loc) · 1.87 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
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="yes" name="mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<title>aciles test page</title>
<style>
* {
margin: 0.25em;
padding: 0.25em;
font-family: Arial, "Sans Serif";
box-sizing: border-box;
}
html, body {
width: 100%;
max-width: 600px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
input {
width: 100%;
}
textarea {
margin-left: auto;
margin-right: auto;
display: block;
width: 100%;
}
#connection {
color: blue;
}
</style>
</head>
<body>
<p>aciles test page</p>
<p id="connection">not connected</p>
<p><a href="https://github.com/chr15m/pd-ws">source code</a></p>
<input placeholder="message to pd" id="sender"/>
<textarea id="receiver"></textarea>
<script type="text/javascript">
$ = document.getElementById.bind(document);
var ws = new WebSocket("ws://localhost:9001/");
ws.onopen = function() {
$("connection").innerHTML = "connected";
};
/* when a message is received from Pd */
ws.onmessage = function(message) {
// console.log("message", message, message.data);
$("receiver").innerHTML += message.data + "\n";
$("receiver").setAttribute("rows", $("receiver").innerHTML.split("\n").length - 1);
};
ws.onclose = function() {
$("connection").innerHTML = "not connected";
};
/* when enter is pressed send the message to Pd */
$("sender").onkeydown = function(ev) {
if (ev.keyCode == 13) {
console.log($("sender").value);
ws.send($("sender").value);
$("sender").value = "";
}
}
</script>
</body>
</html>