commit 0f9a202b6f955783e978283819c2e36b1f41064b Author: Adam Goldsmith Date: Tue Jul 10 01:15:26 2018 -0400 Initial Commit: basic notification functionality working diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..661f101 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.tern-port +/node_modules/ diff --git a/client.js b/client.js new file mode 100644 index 0000000..b33c6ee --- /dev/null +++ b/client.js @@ -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); diff --git a/index.html b/index.html new file mode 100644 index 0000000..7b2121d --- /dev/null +++ b/index.html @@ -0,0 +1,10 @@ + + + + +
+ +
+ test +
+ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..dd817fa --- /dev/null +++ b/package-lock.json @@ -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" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..afde2de --- /dev/null +++ b/package.json @@ -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" +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..5c7e15d --- /dev/null +++ b/server.js @@ -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)); + } + }); +});