summaryrefslogtreecommitdiff
path: root/test/index.html
blob: 031b4584c13317f66bd821cb76ecf90285538ddf (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
<html>
  <head>
    <title>rhrdtime - Testclient</title>
    <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 NTP() {
        this.sock = new WebSocket("ws://localhost:3000/ntp");
        this.sock.onmessage = function (event) {
          $('#timedata').text(event.data);
        }

        this.sock.onmessage = function (event) {
          $('#ntpdata').text(event.data);
        }

        this.update = function() {
          this.sock.send(JSON.stringify({ t1: (+new Date()), t2: 0, t3: 0, t4: 0, tz_offset: 0, week: 0 }));
        }
      }

      function init() {
        var tusock = new WebSocket("ws://localhost:3000/time");

        tusock.onmessage = function (event) {
          $('#tudata').text(event.data);
        }

        ntp = new NTP();
        setInterval(ntp.update.bind(ntp), 1000);
      }
    </script>
  </head>
  <body onload="init()">

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

    <div id="tudata" class="data"></div>

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

    <div id="ntpdata" class="data"></div>

  </body>
</html>