diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-04-02 21:21:37 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-04-02 21:21:37 (GMT) |
commit | 1d79406f4dc196dfd1649640cd29dbabb5042954 (patch) | |
tree | fa6f44c72289009141d03c1f411985d2b370c4b7 /test/socket.html | |
parent | 33d25040c355c24637656bd360613d0a9673be23 (diff) |
added websocket testclient to static files, some cleanups
Diffstat (limited to 'test/socket.html')
-rw-r--r-- | test/socket.html | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/test/socket.html b/test/socket.html deleted file mode 100644 index c179456..0000000 --- a/test/socket.html +++ /dev/null @@ -1,159 +0,0 @@ -<!DOCTYPE HTML> -<html> - <head> - <title>rhimportd - Testclient</title> - <meta charset="utf-8"> - <style type="text/css"> - body { - background-color: #555; - } - - div.data { - background-color: white; - border: 1px solid; - padding: 1em; - font-family: monospace; - margin-top: 1em; - margin-bottom: 1em; - } - - td { - text-align: right; - } - </style> - <script src="jquery.min.js"></script> - <script type="text/javascript"> - function SessionList(req) { - this.req = req - this.sock = new WebSocket("ws://localhost:4080/public/socket"); - this.sock_onmessage = function (event) { - $('#listmsg').text(event.data); - this.sock.close(); - } - this.sock.onmessage = this.sock_onmessage.bind(this); - - this.sock_onopen = function() { - this.sock.send(JSON.stringify(this.req)); - } - this.sock.onopen = this.sock_onopen.bind(this); - } - - var sl; - - function list() { - req = { COMMAND: "list", - LOGIN_NAME: $('#username').val(), - PASSWORD: $('#token').val()}; - sl = new SessionList(req); - } - - - function Session(req) { - this.req = req - $('#rawmsg').text(""); - this.sock = new WebSocket("ws://localhost:4080/public/socket"); - this.sock_onmessage = function (event) { - $('#rawmsg').append(event.data + "\n"); - msg = $.parseJSON(event.data) - switch (msg.TYPE) { - case "ack": - $('#sessionid').val(msg.ID); - buttonsRunning(); - break; - case "done": - case "error": - this.sock.close(); - init(); - break; - } - } - this.sock.onmessage = this.sock_onmessage.bind(this); - - this.sock_onopen = function() { - this.sock.send(JSON.stringify(this.req)); - } - this.sock.onopen = this.sock_onopen.bind(this); - - this.cancel = function() { - this.sock.send(JSON.stringify({COMMAND: "cancel"})); - } - } - - var s; - - function run() { - req = { COMMAND: "new", - TIMEOUT: 200, - REFERENCE_ID: $('#refid').val(), - LOGIN_NAME: $('#username').val(), - PASSWORD: $('#token').val(), - SHOW_ID: 10002, - CLEAR_SHOW_CARTS: true, - SOURCE_URI: $('#source').val() }; - s = new Session(req); - } - - function reconnect() { - req = { COMMAND: "reconnect", - LOGIN_NAME: $('#username').val(), - ID: $('#sessionid').val() }; - s = new Session(req); - } - - function cancel() { - s.cancel(); - } - - function detach() { - s.sock.close(); - buttonsIdle(); - } - - function buttonsIdle() { - $('#buttonrun').removeAttr('disabled') - $('#buttonreconnect').removeAttr('disabled') - $('#buttondetach').attr('disabled','disabled') - $('#buttoncancel').attr('disabled','disabled') - } - - function buttonsRunning() { - $('#buttonrun').attr('disabled','disabled') - $('#buttonreconnect').attr('disabled','disabled') - $('#buttondetach').removeAttr('disabled') - $('#buttoncancel').removeAttr('disabled') - } - - function init() { - $('#sessionid').val(""); - buttonsIdle(); - } -</script> - </head> - <body onload="init()"> - - <h1>Radio Helsinki Rivendell Importer:</h1> - - <p> - <table> - <tr><td>Username</td><td><input id="username" type="text" size="20" value="heslinki"></td></tr> - <tr><td>Token</td><td><input id="token" type="text" size="20"></td></tr> - </table> - </p> - - <p> - <button id="buttonlist" onclick="list()">list</button> - <div id="listmsg" class="data"></div> - </p> - - <p> - <input id="source" type="text" size="30" value="fake://10000"> - <input id="refid" type="text" size="15" value="test-reference-id"> - <button id="buttonrun" onclick="run()">start</button> - <button id="buttondetach" onclick="detach()">detach</button> - <input id="sessionid" type="text" size="45"> - <button id="buttonreconnect" onclick="reconnect()">reconnect</button> - <button id="buttoncancel" onclick="cancel()">cancel</button> - <div id="rawmsg" class="data"></div> - </p> - </body> -</html> |