summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/socket.html45
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>