From bedc1853e9f28bab43a3aca7581a8cfbc00aa89d Mon Sep 17 00:00:00 2001 From: chaniotis_alex Date: Thu, 9 Jan 2020 09:39:50 +0000 Subject: [PATCH] Upload files to 'public/js' --- public/js/scoreboard.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 public/js/scoreboard.js diff --git a/public/js/scoreboard.js b/public/js/scoreboard.js new file mode 100644 index 0000000..dbd16c6 --- /dev/null +++ b/public/js/scoreboard.js @@ -0,0 +1,27 @@ +//οριζω την ip του raspberry pi και θετω την τιμη score=0 +(function() { + var ws = new WebSocket('ws://192.168.1.11:8080', 'json'); + var score = 0; + + //ενημερωτικα μηνυματα για τον server και παιρνω την προηγουμενη τιμη απο την μεταβλητη score. + ws.onopen = function () { + console.log('Websocket ws is now open'); + ws.send('Hello from SmartHoop!'); + document.getElementById('score').innerHTML = score; + }; + + //με το event score που αποστελενεται απο τον node server αυξανω κατα 1 την μεταβλητη score + ws.onmessage = function (event) { + if (event.data.indexOf('SCORE:') != -1) { + score++; + document.getElementById('score').innerHTML = score; + } + console.log('Message was ', event.data); + }; + + //σε περιπτωση λαθους δειχνουμε το σφαλμα + ws.onerror = function(error) { + console.log('Error detected: ' + error.data); + } + +}());