1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<!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;
}
</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) {
$('#rawmsg').append(event.data + "\n");
msg = $.parseJSON(event.data)
switch (msg.TYPE) {
case "ACK":
$('#sessionid').val(msg.ID);
$('#buttonrun').attr('disabled','disabled')
$('#buttonreconnect').attr('disabled','disabled')
$('#buttoncancel').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));
}
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: "my-very-personal-import",
LOGIN_NAME: "heslinki",
PASSWORD: "12423",
SHOW_ID: 10002,
CLEAR_SHOW_CARTS: true,
SOURCE_URI: "fake://10000" };
s = new Session(req);
}
function reconnect() {
req = { COMMAND: "reconnect",
LOGIN_NAME: "heslinki",
ID: $('#sessionid').val() };
s = new Session(req);
}
function cancel() {
s.cancel();
}
function init() {
$('#sessionid').val("");
$('#buttonrun').removeAttr('disabled')
$('#buttonreconnect').removeAttr('disabled')
$('#buttoncancel').attr('disabled','disabled')
}
</script>
</head>
<body onload="init()">
<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>
<div id="rawmsg" class="data"></div>
</body>
</html>
|