diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-02-13 18:36:52 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-02-13 18:36:52 +0100 |
commit | 0380cf79bdfaba16dc433c8e1c3a6bcdbd59c774 (patch) | |
tree | 66b05c1217e7222535c6ae3194984ead9b4e2416 /cmd/dolmetschctld/web-static/socket.html | |
parent | added basic web socket interface (diff) |
make web socket test page a little nicer
Diffstat (limited to 'cmd/dolmetschctld/web-static/socket.html')
-rw-r--r-- | cmd/dolmetschctld/web-static/socket.html | 25 |
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> |