diff options
Diffstat (limited to 'web-static')
-rw-r--r-- | web-static/socket.html | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/web-static/socket.html b/web-static/socket.html index 466431d..fc1b270 100644 --- a/web-static/socket.html +++ b/web-static/socket.html @@ -61,6 +61,34 @@ function init() { $('#buttonstate').removeAttr('disabled','disabled'); } + + function Subscription(req) { + this.req = req + this.sock = new WebSocket("wss://rdimport.helsinki.at/rhctl/socket"); + this.sock_onmessage = function (event) { + $('#rawmsg').text(event.data); + } + this.sock.onmessage = this.sock_onmessage.bind(this); + + this.sock_onopen = function() { + this.sock.send(JSON.stringify(this.req)); + $('#buttonsub').attr('disabled','disabled') + } + this.sock.onopen = this.sock_onopen.bind(this); + } + + var sub; + + function sub() { + req = { COMMAND: "subscribe", ARGS: [ $('#subtype').val() ]}; + sub = new Subscription(req); + } + + function init() { + $('#buttonstate').removeAttr('disabled','disabled'); + $('#buttonsub').removeAttr('disabled','disabled'); + } + </script> </head> <body onload="init()"> @@ -72,5 +100,11 @@ <div id="statemsg" class="data"></div> </div> + <div> + <input id="subtype" type="text" size="30" value="state"> + <button id="buttonsub" onclick="sub()">subscribe</button> + <div id="rawmsg" class="data"></div> + </div> + </body> </html> |