Move aprs parsing to client side using webpack

This commit is contained in:
Adam Goldsmith 2018-07-18 12:27:41 -04:00
parent 7f28f99ea3
commit 635a85aeab
6 changed files with 5779 additions and 19 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/.tern-port
/node_modules/
/dist/

5740
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,15 +2,27 @@
"name": "aprsnotifyjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"dependencies": {
"aprs-parser": "^1.0.4",
"ws": "^5.2.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"devDependencies": {
"webpack": "^4.16.1",
"webpack-cli": "^3.0.8",
"webpack-serve": "^2.0.2"
},
"author": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"monkeyPatch": "sed -i '8s| APRSIS| //APRSIS|' node_modules/aprs-parser/lib/index.js",
"serve": "node src/server.js",
"prestart": "npm run monkeyPatch",
"start": "node_modules/.bin/webpack-serve --content src",
"prebuild": "npm run monkeyPatch",
"build": "NODE_ENV=production node node_modules/.bin/webpack && cp src/index.html dist/index.html"
},
"author": "Adam Goldsmith <contact@adamgoldsmith.name>",
"license": "ISC"
}

View File

@ -1,6 +1,6 @@
<head>
<meta charset="UTF-8">
<script src="./client.js"></script>
<script src="main.js"></script>
<style>
table.stations {
border-collapse: collapse;

View File

@ -1,3 +1,5 @@
const aprs = require('aprs-parser');
// null here means just use the original callsign
const trackedStations = {
// Digis/iGates
@ -46,9 +48,10 @@ const lowVoltage = 11.9;
///////// End of Config /////////
let stations = {};
let messages = [];
window.stations = {};
window.messages = [];
let aprsStream;
let parser = new aprs.APRSParser();
if (Notification.permission !== "granted") {
Notification.requestPermission(permission => {
@ -128,9 +131,10 @@ function alertVoltage(callsign) {
`Voltage: ${stations[callsign].lastVoltage}`);
}
function handleMessage(message) {
let callsign = `${message.from.call}-${message.from.ssid || 0}`;
let date = new Date(); // TODO: could remove "message.recieved" from server
function handleMessage(packet) {
let message = parser.parse(packet[1]);
let callsign = message.from.toString();
let date = new Date(); // TODO: use data[0] instead
console.log(message);
messages.push(message);
@ -166,7 +170,7 @@ function handleMessage(message) {
}
function connectToStream() {
aprsStream = new WebSocket("wss://adamgoldsmith.name/APRSws");
aprsStream = new WebSocket("ws://localhost:1234");
aprsStream.onclose = () => {
// Try to reconnect every 5 seconds
let interval = window.setInterval(() => {

View File

@ -1,9 +1,7 @@
const WebSocket = require('ws');
const net = require('net');
const aprs = require("aprs-parser");
const fs = require('fs');
const parser = new aprs.APRSParser();
const client = new net.Socket();
const wss = new WebSocket.Server({host: "127.0.0.1", port: 1234});
@ -26,14 +24,19 @@ client.on('data', function(data) {
// 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();
let datestamp = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
message.recieved = date;
console.log(message);
fs.appendFile("log" + datestamp + ".json", JSON.stringify(message) + ",\n",
let data = [datestamp, packet];
console.log(data);
fs.appendFile("log" + datestamp + ".json", JSON.stringify(data) + ",\n",
err => {if (err) throw err;});
wss.broadcast(JSON.stringify(message));
wss.broadcast(JSON.stringify(data));
}
});
});
// wss.on('connection', ws => {
// let datestamp = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
// fs.readFileSync("log" + datestamp + ".json")
// .toString().split('\n').forEach(line => ws.send(line));
// });