diff options
Diffstat (limited to 'cmd/dolmetschctld')
-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> |