Compare commits

..

2 commits

Author SHA1 Message Date
Christopher Cookman ddbff495b3 asdf 2025-06-23 17:41:31 -06:00
Christopher Cookman b8fecd731c Working branch go brr 2025-06-23 17:36:33 -06:00
2 changed files with 43 additions and 60 deletions

View file

@ -16,9 +16,7 @@ ws.on('message', (data) => {
try {
const msg = JSON.parse(data);
// Assuming the message has 'channel' and 'product_id' fields
if (msg.channel && msg.product_data) {
console.log(`Channel: ${msg.channel}, Product ID: ${msg.product_data}`);
}
console.log(`Channel: ${msg.data.fromChannel}, Product ID: ${msg.product_data}`);
} catch (err) {
console.error('Error parsing message:', err);
}

View file

@ -457,7 +457,7 @@ xmpp.on("stanza", (stanza) => {
const bodyData = getFirstURL(body);
// get product id from "x" tag
var evt = events[product_id.pil.substring(0, 3)];
if (process.env.LOG_EVENTS === "true") {
// Log the full event object to a file named "productid-timestamp-channelname.json"
const nowDate = new Date();
const year = nowDate.getFullYear();
@ -481,7 +481,6 @@ xmpp.on("stanza", (stanza) => {
return value;
};
};
}
if (!evt) {
evt = { name: "Unknown", priority: 3 }
@ -504,7 +503,7 @@ xmpp.on("stanza", (stanza) => {
const diff = (now - product_id.timestamp) / 1000 / 60;
if (diff > 3) return;
// if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`);
console.log(`${colors.cyan("[INFO]")} ${fromChannel} ${getWFOByRoom(fromChannel).location} - ${product_id_raw} - ${evt.text} - ${product_id.timestamp}`);
console.log(`${colors.cyan("[INFO]")} ${getWFOByRoom(fromChannel).location} - ${product_id_raw} - ${evt.text} - ${product_id.timestamp}`);
messages++;
textTries = 0;
tryGetText = () => {
@ -570,7 +569,6 @@ xmpp.on("stanza", (stanza) => {
}
})
});
if (process.env.LOG_EVENTS === "true") {
fs.writeFileSync(logPath, JSON.stringify({
evt, stanza, product_id, product_id_raw, bodyData, body, sentData: {
"type": "iem-message",
@ -591,7 +589,6 @@ xmpp.on("stanza", (stanza) => {
}
}, getCircularReplacer(), 2), 'utf8');
}
}
tryGetText();
}
});
@ -608,18 +605,6 @@ xmpp.on("status", (status) => {
}));
}
});
// If status is 'disconnect', attempt to reconnect after 5 seconds
if (status === 'disconnect') {
console.log(`${colors.yellow("[WARN]")} XMPP disconnected, attempting to reconnect in 5 seconds...`);
setTimeout(() => {
console.log(`${colors.yellow("[WARN]")} Attempting to reconnect to XMPP...`);
xmpp.start().catch((err) => {
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
setTimeout(start, 5000);
});
}, 5000);
}
});
xmpp.reconnect.on("reconnecting", () => {