Initial Commit: basic notification functionality working
This commit is contained in:
commit
0f9a202b6f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/.tern-port
|
||||||
|
/node_modules/
|
43
client.js
Normal file
43
client.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
let calls = {};
|
||||||
|
|
||||||
|
let messages = [];
|
||||||
|
|
||||||
|
const checkTime = 1000; // 1 second
|
||||||
|
const timeOut = 20 * 60 * 1000; // 20 Minutes
|
||||||
|
//const timeOut = 60 * 1000; // 1 Minute
|
||||||
|
|
||||||
|
Notification.requestPermission(permission => {
|
||||||
|
if (permission === "granted") {
|
||||||
|
new Notification("Test notification", {body: "whatever"});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function checkNotHeard() {
|
||||||
|
let now = new Date();
|
||||||
|
for (let call in calls) {
|
||||||
|
let lastHeard = new Date(calls[call]);
|
||||||
|
console.log(call, now - lastHeard);
|
||||||
|
|
||||||
|
if (now - lastHeard > timeOut) {
|
||||||
|
new Notification(`${call} has not been heard for 20 Minutes!`,
|
||||||
|
{body: `Last Heard: ${lastHeard}`});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let aprsStream = new WebSocket("ws://localhost:1234");
|
||||||
|
aprsStream.onmessage = function(event) {
|
||||||
|
let message = JSON.parse(event.data);
|
||||||
|
let call = `${message.from.call}-${message.from.ssid || 0}`;
|
||||||
|
let date = message.recieved;
|
||||||
|
|
||||||
|
console.log(message);
|
||||||
|
|
||||||
|
if (call in calls) {
|
||||||
|
message.delta = date - calls[call];
|
||||||
|
}
|
||||||
|
calls[call] = date;
|
||||||
|
messages.push(message);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.setInterval(checkNotHeard, checkTime);
|
10
index.html
Normal file
10
index.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<head>
|
||||||
|
<script src="./client.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrapper">
|
||||||
|
<table>
|
||||||
|
</table>
|
||||||
|
test
|
||||||
|
</div>
|
||||||
|
</body>
|
38
package-lock.json
generated
Normal file
38
package-lock.json
generated
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "aprsnotifyjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"aprs-parser": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/aprs-parser/-/aprs-parser-1.0.4.tgz",
|
||||||
|
"integrity": "sha1-0Jsoj51f0gf3vhT6Pp6ZwH/Gpko="
|
||||||
|
},
|
||||||
|
"async-limiter": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
|
||||||
|
},
|
||||||
|
"js-aprs-is": {
|
||||||
|
"version": "file:../../../scratch/js-aprs-is",
|
||||||
|
"requires": {
|
||||||
|
"typescript": "^2.2.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"typescript": {
|
||||||
|
"version": "2.9.2",
|
||||||
|
"bundled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ws": {
|
||||||
|
"version": "5.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ws/-/ws-5.2.1.tgz",
|
||||||
|
"integrity": "sha512-2NkHdPKjDBj3CHdnAGNpmlliryKqF+n9MYXX7/wsVC4yqYocKreKNjydPDvT3wShAZnndlM0RytEfTALCDvz7A==",
|
||||||
|
"requires": {
|
||||||
|
"async-limiter": "~1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
package.json
Normal file
17
package.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "aprsnotifyjs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"aprs-parser": "^1.0.4",
|
||||||
|
"js-aprs-is": "file:../../../scratch/js-aprs-is",
|
||||||
|
"ws": "^5.2.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
35
server.js
Normal file
35
server.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
const WebSocket = require('ws');
|
||||||
|
let net = require('net');
|
||||||
|
let aprs = require("aprs-parser");
|
||||||
|
|
||||||
|
const parser = new aprs.APRSParser();
|
||||||
|
const client = new net.Socket();
|
||||||
|
const wss = new WebSocket.Server({port: 1234});
|
||||||
|
|
||||||
|
wss.broadcast = function(data) {
|
||||||
|
wss.clients.forEach(client => {
|
||||||
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
|
client.send(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
client.connect(
|
||||||
|
14580, "rotate.aprs2.net",
|
||||||
|
() => client.write("user KC1GDW pass -1 filter r/43.52/-72.11/50\r\n"));
|
||||||
|
|
||||||
|
client.on('data', function(data) {
|
||||||
|
let str = data.toString('utf8').replace(/^\s+|\s+$/g, "");
|
||||||
|
console.log(str);
|
||||||
|
|
||||||
|
// strip whitespace, then handle multiple APRS packets per TCP packet
|
||||||
|
str.split("\r\n").forEach(packet => {
|
||||||
|
if (!packet.startsWith('#')) { // ignore comments
|
||||||
|
let message = parser.parse(packet);
|
||||||
|
let date = new Date();
|
||||||
|
message.recieved = date;
|
||||||
|
console.log(message);
|
||||||
|
wss.broadcast(JSON.stringify(message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user