From fe5ac6073a4b475e769a1cdba734469b31095332 Mon Sep 17 00:00:00 2001 From: Chris Chrome Date: Tue, 15 Apr 2025 18:15:02 -0600 Subject: [PATCH] Guh? --- index.js | 40 +++++++++++++++++++++++++++------------- public/index.html | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 public/index.html diff --git a/index.js b/index.js index 0fb0d72..ab388a2 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const html = require('html-entities'); const blacklist = require("./blacklist.json") const wfos = require("./wfos.json") const events = require("./events.json") +const os = require('os'); const app = express(); expressWs(app); @@ -19,6 +20,14 @@ global.wsConnections = []; // IEM WebSocket app.ws('/iem', (ws, req) => { console.log(`connection from ${req.ip}`); + const hostname = os.hostname(); + + ws.send(JSON.stringify({ + "type": "connection-info", + "state": true, + "uuid": curUUID, + "host": hostname + })); wsConnections.push(ws); ws.on('close', () => { console.log(`disconnected from ${req.ip}`); @@ -221,9 +230,11 @@ xmpp.on("stanza", (stanza) => { if (stanza.is("message") && stanza.attrs.type === "groupchat") { clearTimeout(restartTimer) restartTimer = setTimeout(() => { - console.log(`${colors.red("[FATAL]")} No messages from weather.im in 10 minutes, restarting!!!!!!!!!!!`) - process.exit(1) - }, 600000) + console.log(`${colors.yellow("[WARN]")} Restarting XMPP connection...`); + xmpp.disconnect().then(() => { + xmpp.start(); + }); + }, 10000) // Stops spam from getting old messages if (startup) return; // Get channel name @@ -433,16 +444,19 @@ xmpp.on("stanza", (stanza) => { if (wsConnections.length > 0) { wsConnections.forEach((ws) => { ws.send(JSON.stringify({ - "channel": getWFOByRoom(fromChannel), - "event": evt, - "body": bodyData.string, - "timestamp": product_id.timestamp, - "wmo": product_id.wmo, - "pil": product_id.pil, - "station": product_id.station, - "raw": product_id_raw, - "rawBody": body, - "image": stanza.getChild("x").attrs.twitter_media || null + "type": "iem-message", + "data": { + "channel": getWFOByRoom(fromChannel), + "event": evt, + "body": bodyData.string, + "timestamp": product_id.timestamp, + "wmo": product_id.wmo, + "pil": product_id.pil, + "station": product_id.station, + "raw": product_id_raw, + "rawBody": body, + "image": stanza.getChild("x").attrs.twitter_media || null + } })); }); } diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..8713367 --- /dev/null +++ b/public/index.html @@ -0,0 +1,35 @@ + + + + + + Document + + +
+ + + \ No newline at end of file