From ead50a8eae32eedb6f9f981719325f92641e46a9 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 20 Apr 2025 09:51:46 -0600 Subject: [PATCH] Add stuff --- client-example/index.js | 10 +++++++--- index.js | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/client-example/index.js b/client-example/index.js index 4543133..e9903e6 100644 --- a/client-example/index.js +++ b/client-example/index.js @@ -1,12 +1,13 @@ const WebSocket = require('ws'); - +var retries = 0; function connectWebSocket() { console.log('Attempting to connect to WebSocket...'); - const ws = new WebSocket('ws://localhost:3000/iem'); + const ws = new WebSocket('wss://iem-alerter.ko4wal.radio/iem'); ws.on('open', () => { console.log('Connected to WebSocket'); ws.send(JSON.stringify({ type: 'subscribe', channel: 'botstalk' })); + retries = 0; // Reset retries on successful connection }); ws.on('message', (data) => { @@ -15,7 +16,10 @@ function connectWebSocket() { ws.on('close', () => { console.log('WebSocket connection closed. Reconnecting...'); - setTimeout(connectWebSocket, 1000); // Retry after 1 second + retries++; + const retryDelay = Math.min(5000, Math.pow(2, retries) * 100); + console.log(`Retrying connection in ${retryDelay} ms...`); + setTimeout(connectWebSocket, retryDelay); }); ws.on('error', (err) => { diff --git a/index.js b/index.js index 1a7e9c6..0812839 100644 --- a/index.js +++ b/index.js @@ -64,9 +64,24 @@ app.ws('/iem', (ws, req) => { ws.send(JSON.stringify({ "type": "connection-info", - "state": true, + "status": socketStatus, "uuid": curUUID, - "host": hostname + "host": hostname, + "connections": wsConnections.length, + "uptime": process.uptime(), + "messages": messages, + "errCount": errCount, + "startup": startup, + "startTime": startTimestap, + "roomList": roomList, + "wfos": Object.keys(wfos).map((key) => { + return { + code: key, + location: wfos[key].location, + room: wfos[key].room + } + }); + iem })); sock = wsConnections.push({ ws, req, subs: [] }); ws.on('close', () => { @@ -444,11 +459,12 @@ xmpp.on("stanza", (stanza) => { "data": { "channel": getWFOByRoom(fromChannel), "event": evt, - "body": bodyData.string, + "body": bodyData, "timestamp": product_id.timestamp, "wmo": product_id.wmo, "pil": product_id.pil, "station": product_id.station, + "product_data": product_id, "raw": product_id_raw, "rawBody": body, "image": stanza.getChild("x").attrs.twitter_media || null,