Replace call/calls variable names with station/stations

This commit is contained in:
Adam Goldsmith 2018-07-10 20:43:06 -04:00
parent 332a057f0c
commit b602a1e314
2 changed files with 18 additions and 18 deletions

View File

@ -1,4 +1,4 @@
let calls = {}; let stations = {};
let messages = []; let messages = [];
@ -11,14 +11,14 @@ Notification.requestPermission(permission => {
}); });
function redrawTable() { function redrawTable() {
let table = document.querySelector('table.calls'); let table = document.querySelector('table.stations');
table.innerHTML = table.innerHTML =
`<tr><th>Callsign</th>` + `<tr><th>Callsign</th>` +
`<th>Last Heard</th>` + `<th>Last Heard</th>` +
`<th>Time since Last Heard</th>`; `<th>Time since Last Heard</th>`;
for (let callsign in calls) { for (let callsign in stations) {
let call = calls[callsign]; let station = stations[callsign];
let nowDelta = new Date(new Date() - call.lastHeard); let nowDelta = new Date(new Date() - station.lastHeard);
let tr = table.appendChild(document.createElement('tr')); let tr = table.appendChild(document.createElement('tr'));
if (nowDelta.getTime() > timeoutLength) { if (nowDelta.getTime() > timeoutLength) {
@ -26,15 +26,14 @@ function redrawTable() {
} }
tr.innerHTML = tr.innerHTML =
`<td>${callsign}</td>` + `<td>${callsign}</td>` +
`<td>${call.lastHeard.toLocaleTimeString('en-GB')}</td>` + `<td>${station.lastHeard.toLocaleTimeString('en-GB')}</td>` +
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>` `<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>`;
;
} }
} }
function alertNotHeard(callsign) { function alertNotHeard(callsign) {
new Notification(`${callsign} has not been heard for 20 Minutes!`, new Notification(`${callsign} has not been heard for 20 Minutes!`,
{body: `Last Heard: ${calls[callsign].lastHeard.toLocaleTimeString('en-GB')}`}); {body: `Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`});
} }
let aprsStream = new WebSocket("ws://localhost:1234"); let aprsStream = new WebSocket("ws://localhost:1234");
@ -46,18 +45,18 @@ aprsStream.onmessage = function(event) {
console.log(message); console.log(message);
messages.push(message); messages.push(message);
if (!(callsign in calls)) { if (!(callsign in stations)) {
calls[callsign] = { stations[callsign] = {
lastHeard: date, lastHeard: date,
}; };
} }
else { else {
window.clearTimeout(calls[callsign].timeout); window.clearTimeout(stations[callsign].timeout);
} }
calls[callsign].delta = date - calls[callsign].lastHeard; stations[callsign].delta = date - stations[callsign].lastHeard;
calls[callsign].timeout = window.setTimeout( stations[callsign].timeout = window.setTimeout(
alertNotHeard, timeoutLength, callsign); alertNotHeard, timeoutLength, callsign);
redrawTable(); redrawTable();

View File

@ -2,22 +2,23 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<script src="./client.js"></script> <script src="./client.js"></script>
<style> <style>
table.calls { table.stations {
border-collapse: collapse; border-collapse: collapse;
} }
table.calls td, table.calls th{ table.stations td, table.stations th{
border: 1px solid black; border: 1px solid black;
padding: 2px;
} }
table.calls tr.timedOut { table.stations tr.timedOut {
background-color: red; background-color: red;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<table class="calls"> <table class="stations">
</table> </table>
</div> </div>
</body> </body>