summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-13 18:36:52 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-13 18:36:52 +0100
commit0380cf79bdfaba16dc433c8e1c3a6bcdbd59c774 (patch)
tree66b05c1217e7222535c6ae3194984ead9b4e2416
parentadded basic web socket interface (diff)
make web socket test page a little nicer
-rw-r--r--cmd/dolmetschctld/web-static/socket.html25
1 files changed, 13 insertions, 12 deletions
diff --git a/cmd/dolmetschctld/web-static/socket.html b/cmd/dolmetschctld/web-static/socket.html
index d286cdc..903868d 100644
--- a/cmd/dolmetschctld/web-static/socket.html
+++ b/cmd/dolmetschctld/web-static/socket.html
@@ -23,34 +23,35 @@
</style>
<script src="jquery.min.js"></script>
<script type="text/javascript">
- function State(req) {
- this.req = req
- this.sock = new WebSocket("ws://localhost:8234/api/v1/socket");
+ function Controller(url) {
+ this.sock = new WebSocket(url);
this.sock_onmessage = function (event) {
- $('#statemsg').text(event.data);
+ $('#rawmsg').text(event.data);
$('#buttonstate').removeAttr('disabled','disabled');
}
this.sock.onmessage = this.sock_onmessage.bind(this);
this.sock_onopen = function() {
- this.sock.send(JSON.stringify(this.req));
- $('#buttonstate').attr('disabled','disabled')
+ $('#buttonstate').removeAttr('disabled','disabled');
}
this.sock.onopen = this.sock_onopen.bind(this);
+
+ this.send = function(req){
+ $('#rawmsg').text("");
+ this.sock.send(JSON.stringify(req));
+ }
}
- var s;
+ var ctrl = new Controller("ws://localhost:8234/api/v1/socket");
function state() {
req = { command: "state" };
- s = new State(req);
+ ctrl.send(req);
}
-
function init() {
- $('#buttonstate').removeAttr('disabled','disabled');
+ $('#buttonstate').attr('disabled','disabled')
}
-
</script>
</head>
<body onload="init()">
@@ -59,7 +60,7 @@
<div>
<button id="buttonstate" onclick="state()">get state</button>
- <div id="statemsg" class="data"></div>
+ <div id="rawmsg" class="data"></div>
</div>
</body>