chaniotis_alex
5 years ago
1 changed files with 27 additions and 0 deletions
@ -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); |
|||
} |
|||
|
|||
}()); |
Loading…
Reference in new issue