summaryrefslogtreecommitdiff
path: root/cmd/dolmetschctld/web-static/socket.html
blob: b9bebbb9165b47b78543364c423573b941b68e76 (plain) (blame)
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
<!DOCTYPE HTML>
<html>
  <head>
    <title>dolmetschctl Websocket 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 Controller(url) {
        this.sock = new WebSocket(url);
        this.sock_onmessage = function (event) {
          $('#rawmsg').text(event.data);
          $('#buttonstate').removeAttr('disabled','disabled');
        }
        this.sock.onmessage = this.sock_onmessage.bind(this);

        this.sock_onopen = function() {
          $('#buttonstate').removeAttr('disabled','disabled');
        }
        this.sock.onopen = this.sock_onopen.bind(this);

        this.send = function(req){
          $('#rawmsg').text("");
          this.sock.send(JSON.stringify(req));
        }
      }

      var ctrl = new Controller("ws://localhost:8234/api/v1/socket");

      function state() {
        req = { command: "state" };
        ctrl.send(req);
      }

      function set_language() {
        req = { command: "language", arguments: [ $('#inputlang').val() ] };
        ctrl.send(req);
      }

      function init() {
        $('#buttonstate').attr('disabled','disabled')
      }
    </script>
  </head>
  <body onload="init()">

    <h1>dolmetschctl Websocket Testclient</h1>

    <div>
      <button id="buttonstate" onclick="state()">get state</button>
      <button id="buttonlang" onclick="set_language()">set language</button>
      <input type="text" id="inputlang" length="10">
      <div id="rawmsg" class="data"></div>
    </div>

  </body>
</html>