Move aprs parsing to client side using webpack
This commit is contained in:
parent
7f28f99ea3
commit
635a85aeab
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/.tern-port
|
/.tern-port
|
||||||
/node_modules/
|
/node_modules/
|
||||||
|
/dist/
|
||||||
|
5740
package-lock.json
generated
5740
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -2,15 +2,27 @@
|
|||||||
"name": "aprsnotifyjs",
|
"name": "aprsnotifyjs",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"aprs-parser": "^1.0.4",
|
"aprs-parser": "^1.0.4",
|
||||||
"ws": "^5.2.2"
|
"ws": "^5.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {
|
||||||
"scripts": {
|
"webpack": "^4.16.1",
|
||||||
"test": "echo \"Error: no test specified\" && exit 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"
|
"license": "ISC"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<script src="./client.js"></script>
|
<script src="main.js"></script>
|
||||||
<style>
|
<style>
|
||||||
table.stations {
|
table.stations {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
@ -1,3 +1,5 @@
|
|||||||
|
const aprs = require('aprs-parser');
|
||||||
|
|
||||||
// null here means just use the original callsign
|
// null here means just use the original callsign
|
||||||
const trackedStations = {
|
const trackedStations = {
|
||||||
// Digis/iGates
|
// Digis/iGates
|
||||||
@ -46,9 +48,10 @@ const lowVoltage = 11.9;
|
|||||||
|
|
||||||
///////// End of Config /////////
|
///////// End of Config /////////
|
||||||
|
|
||||||
let stations = {};
|
window.stations = {};
|
||||||
let messages = [];
|
window.messages = [];
|
||||||
let aprsStream;
|
let aprsStream;
|
||||||
|
let parser = new aprs.APRSParser();
|
||||||
|
|
||||||
if (Notification.permission !== "granted") {
|
if (Notification.permission !== "granted") {
|
||||||
Notification.requestPermission(permission => {
|
Notification.requestPermission(permission => {
|
||||||
@ -128,9 +131,10 @@ function alertVoltage(callsign) {
|
|||||||
`Voltage: ${stations[callsign].lastVoltage}`);
|
`Voltage: ${stations[callsign].lastVoltage}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessage(message) {
|
function handleMessage(packet) {
|
||||||
let callsign = `${message.from.call}-${message.from.ssid || 0}`;
|
let message = parser.parse(packet[1]);
|
||||||
let date = new Date(); // TODO: could remove "message.recieved" from server
|
let callsign = message.from.toString();
|
||||||
|
let date = new Date(); // TODO: use data[0] instead
|
||||||
|
|
||||||
console.log(message);
|
console.log(message);
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
@ -166,7 +170,7 @@ function handleMessage(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function connectToStream() {
|
function connectToStream() {
|
||||||
aprsStream = new WebSocket("wss://adamgoldsmith.name/APRSws");
|
aprsStream = new WebSocket("ws://localhost:1234");
|
||||||
aprsStream.onclose = () => {
|
aprsStream.onclose = () => {
|
||||||
// Try to reconnect every 5 seconds
|
// Try to reconnect every 5 seconds
|
||||||
let interval = window.setInterval(() => {
|
let interval = window.setInterval(() => {
|
@ -1,9 +1,7 @@
|
|||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const aprs = require("aprs-parser");
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const parser = new aprs.APRSParser();
|
|
||||||
const client = new net.Socket();
|
const client = new net.Socket();
|
||||||
const wss = new WebSocket.Server({host: "127.0.0.1", port: 1234});
|
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
|
// strip whitespace, then handle multiple APRS packets per TCP packet
|
||||||
str.split("\r\n").forEach(packet => {
|
str.split("\r\n").forEach(packet => {
|
||||||
if (!packet.startsWith('#')) { // ignore comments
|
if (!packet.startsWith('#')) { // ignore comments
|
||||||
let message = parser.parse(packet);
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
let datestamp = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
let datestamp = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
||||||
message.recieved = date;
|
let data = [datestamp, packet];
|
||||||
console.log(message);
|
console.log(data);
|
||||||
fs.appendFile("log" + datestamp + ".json", JSON.stringify(message) + ",\n",
|
fs.appendFile("log" + datestamp + ".json", JSON.stringify(data) + ",\n",
|
||||||
err => {if (err) throw err;});
|
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));
|
||||||
|
// });
|
Loading…
Reference in New Issue
Block a user