diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-30 21:42:59 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-30 21:42:59 (GMT) |
commit | b48b8d760021bd7a887a24c4bbd239f90c2c2f22 (patch) | |
tree | 27c20e906a1dd83734dbdb854fb8863aa0f622c7 /test/socket.html | |
parent | a37f02747e587b25d45de98d175427d4ccb5cdf7 (diff) |
web socket handler is now completed
Diffstat (limited to 'test/socket.html')
-rw-r--r-- | test/socket.html | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/test/socket.html b/test/socket.html index ab631ac..a7504f8 100644 --- a/test/socket.html +++ b/test/socket.html @@ -14,15 +14,41 @@ padding: 1em; font-family: monospace; margin-top: 1em; + margin-bottom: 1em; } </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: "heslinki", + PASSWORD: "12423" }; + 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) { + this.sock_onmessage = function (event) { $('#rawmsg').append(event.data + "\n"); msg = $.parseJSON(event.data) switch (msg.TYPE) { @@ -31,13 +57,15 @@ $('#buttonrun').attr('disabled','disabled') $('#buttonreconnect').attr('disabled','disabled') $('#buttoncancel').removeAttr('disabled') - $('#buttonlist').removeAttr('disabled') 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)); @@ -47,10 +75,6 @@ this.cancel = function() { this.sock.send(JSON.stringify({COMMAND: "cancel"})); } - - this.list = function() { - this.sock.send(JSON.stringify({COMMAND: "list", LOGIN_NAME: "heslinki", PASSWORD: "12423"})); - } } var s; @@ -78,16 +102,11 @@ s.cancel(); } - function list() { - s.list(); - } - function init() { $('#sessionid').val(""); $('#buttonrun').removeAttr('disabled') $('#buttonreconnect').removeAttr('disabled') $('#buttoncancel').attr('disabled','disabled') - $('#buttonlist').attr('disabled','disabled') } </script> </head> @@ -95,11 +114,13 @@ <h1>Radio Helsinki Rivendell Importer:</h1> + <button id="buttonlist" onclick="list()">list</button> + <div id="listmsg" class="data"></div> + <button id="buttonrun" onclick="run()">start</button> <input id="sessionid" type="text" size="45" label="ID"> <button id="buttonreconnect" onclick="reconnect()">reconnect</button> <button id="buttoncancel" onclick="cancel()">cancel</button> - <button id="buttonlist" onclick="list()">list</button> <div id="rawmsg" class="data"></div> </body> </html> |