Abstract notifications, pretty print durations, don't popup test
This commit is contained in:
parent
1a85f4f0d6
commit
2b3914a11c
32
client.js
32
client.js
@ -5,11 +5,21 @@ let messages = [];
|
|||||||
const timeoutLength = 20 * 60 * 1000; // 20 Minutes
|
const timeoutLength = 20 * 60 * 1000; // 20 Minutes
|
||||||
const lowVoltage = 11.9;
|
const lowVoltage = 11.9;
|
||||||
|
|
||||||
Notification.requestPermission(permission => {
|
if (Notification.permission !== "granted") {
|
||||||
if (permission === "granted") {
|
Notification.requestPermission(permission => {
|
||||||
new Notification("Test notification", {body: "whatever"});
|
if (permission === "granted") {
|
||||||
}
|
new Notification("Test notification", {body: "whatever"});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function prettyDuration(duration) {
|
||||||
|
let date = new Date(timeoutLength);
|
||||||
|
return date.getUTCHours() > 0 ? date.getUTCHours() + " Hours": "" +
|
||||||
|
date.getUTCMinutes() > 0 ? date.getUTCMinutes() + " Minutes": "" +
|
||||||
|
date.getUTCSeconds() > 0 ? date.getUTCSeconds() + " Seconds": "" +
|
||||||
|
date.getUTCMilliseconds() > 0 ? date.getUTCMilliseconds() + " Milliseconds" : "";
|
||||||
|
}
|
||||||
|
|
||||||
function redrawTable() {
|
function redrawTable() {
|
||||||
let table = document.querySelector('table.stations');
|
let table = document.querySelector('table.stations');
|
||||||
@ -40,14 +50,18 @@ function redrawTable() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notify(title, body) {
|
||||||
|
return new Notification(title, {body: body, requireInteraction: true});
|
||||||
|
}
|
||||||
|
|
||||||
function alertNotHeard(callsign) {
|
function alertNotHeard(callsign) {
|
||||||
new Notification(`${callsign} has not been heard for 20 Minutes!`,
|
notify(`${callsign} has not been heard for ${prettyDuration(timeoutLength)}!`,
|
||||||
{body: `Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`});
|
`Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function alertVoltage(callsign) {
|
function alertVoltage(callsign) {
|
||||||
new Notification(`${callsign}'s battery has dropepd below ${lowVoltage}V`,
|
notify(`${callsign}'s battery has dropepd below ${lowVoltage}V`,
|
||||||
{body: `Voltage: ${stations[callsign].lastVoltage}`});
|
`Voltage: ${stations[callsign].lastVoltage}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let aprsStream = new WebSocket("ws://localhost:1234");
|
let aprsStream = new WebSocket("ws://localhost:1234");
|
||||||
|
Loading…
Reference in New Issue
Block a user