diff options
-rw-r--r-- | src/helsinki.at/rhrdtime/rhrdtime.go | 6 | ||||
-rw-r--r-- | test/index.html | 32 |
2 files changed, 30 insertions, 8 deletions
diff --git a/src/helsinki.at/rhrdtime/rhrdtime.go b/src/helsinki.at/rhrdtime/rhrdtime.go index 806e64e..af51902 100644 --- a/src/helsinki.at/rhrdtime/rhrdtime.go +++ b/src/helsinki.at/rhrdtime/rhrdtime.go @@ -180,9 +180,9 @@ func RunMartini(ps *pubsub.PubSub, addr string) { m.Get("/time", func(w http.ResponseWriter, r *http.Request) { handleTimeUpdateClient(w, r, ps) }) - // m.Get("/ntp", func(w http.ResponseWriter, r *http.Request) { - // handleTimeUpdateClient(w, r, ps) - // }) + m.Get("/ntp", func(w http.ResponseWriter, r *http.Request) { + handleNTPClient(w, r, ps) + }) m.RunOnAddr(addr) } diff --git a/test/index.html b/test/index.html index 41d0a3a..031b458 100644 --- a/test/index.html +++ b/test/index.html @@ -6,7 +6,7 @@ background-color: #555; } - #timedata { + div.data { background-color: white; border: 1px solid; padding: 1em; @@ -15,12 +15,30 @@ </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 sock = new WebSocket("ws://localhost:3000/time"); + var tusock = new WebSocket("ws://localhost:3000/time"); - sock.onmessage = function (event) { - $('#timedata').text(event.data); + tusock.onmessage = function (event) { + $('#tudata').text(event.data); } + + ntp = new NTP(); + setInterval(ntp.update.bind(ntp), 1000); } </script> </head> @@ -28,7 +46,11 @@ <h1>Radio Helsinki Rivendell Time:</h1> - <div id="timedata"></div> + <div id="tudata" class="data"></div> + + <h1>Radio Helsinki Rivendell NTP:</h1> + + <div id="ntpdata" class="data"></div> </body> </html> |