summaryrefslogtreecommitdiff
path: root/test/socket.html
blob: d03852702646959b2eb7e9dcf6ca042d92ee1592 (plain)
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
<!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;
      }
    </style>
    <script src="jquery.min.js"></script>
    <script type="text/javascript">
      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);
        }
        this.sock_onopen = function() {
          this.req.COMMAND = "new";
          this.req.TIMEOUT = 200;
          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 = { LOGIN_NAME: "heslinki",
	              PASSWORD: "12423",
	              SHOW_ID: 10002,
	              CLEAR_SHOW_CARTS: true,
	              SOURCE_URI: "fake://10000" };
        s = new Session(req);
      }

      function cancel() {
        s.cancel();
      }
</script>
  </head>
  <body>

    <h1>Radio Helsinki Rivendell Importer:</h1>

    <button onclick="run()">start</button>
    <button onclick="cancel()">cancel</button>
    <div id="rawmsg" class="data"></div>
  </body>
</html>