Add stuff

This commit is contained in:
Christopher Cookman 2025-04-20 09:51:46 -06:00
parent 2ee4718028
commit ead50a8eae
2 changed files with 26 additions and 6 deletions

View file

@ -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) => {

View file

@ -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,