X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=score.js;h=85ab488b39d9a17f05ee9a81bcb86c787f85c3f7;hb=a863d093841773e0e17cc4965c073b443e195071;hp=f2534d114377a2ad9762a5d36f969ebfcdbd88c9;hpb=9a76268af587f36d67dd1d3e41fcfb81f4133a06;p=ultimatescore diff --git a/score.js b/score.js index f2534d1..85ab488 100644 --- a/score.js +++ b/score.js @@ -63,6 +63,12 @@ function setclockfromstate() setclock(amount); } +function setclocklimitfromstate() +{ + let amount = parseInt(state['clock_limit_min']) * 60 + parseInt(state['clock_limit_sec']); + clock_limit = amount; +} + function showclock() { if (clock_visible) return; @@ -235,3 +241,40 @@ update_score(); //play(); //startclock(); + +let websocket = null; + +function open_ws() +{ + console.log("Connecting..."); + try { + if (websocket) + websocket.close(); + websocket = new WebSocket("ws://127.0.0.1:5250/"); + websocket.onopen = function(evt) { + console.log("Connected to client."); + }; + websocket.onclose = function(evt) { + console.log("Disconnected from client."); + setTimeout(open_ws, 100); + }; + websocket.onmessage = function(evt) { + let msg = evt.data; + let m = msg.match(/^update (.*)/); + if (m !== null) { + update(m[1]); + } + m = msg.match(/^eval (.*)/); + if (m !== null) { + eval(m[1]); + } + }; + websocket.onerror = function(evt) { + console.log('Error: ' + evt.data); + }; + } catch (exception) { + console.log('Error: ' + exception); + setTimeout(open_ws, 100); + } +}; +open_ws();