20 lines
672 B
JavaScript
20 lines
672 B
JavaScript
const uptime = document.querySelector('#time')
|
|
const ws = new WebSocket('ws://172.16.17.21:8080');
|
|
ws.onopen = () => {
|
|
ws.send('Hello Server!');
|
|
}
|
|
|
|
ws.onmessage = (e) => {
|
|
console.log('Received:', e.data);
|
|
var jsondata = JSON.parse(e.data);
|
|
if (jsondata.uptime.hour === '0' && jsondata.uptime.minute === '0') {
|
|
uptime.innerHTML = jsondata.uptime.second + "s "
|
|
return
|
|
}
|
|
if (jsondata.uptime.hour === '0') {
|
|
uptime.innerHTML = jsondata.uptime.minute + "m " + jsondata.uptime.second + "s "
|
|
return
|
|
}
|
|
uptime.innerHTML = jsondata.uptime.hour + "h " + jsondata.uptime.minute + "m " + jsondata.uptime.second + "s "
|
|
}
|