Add stuff
This commit is contained in:
parent
2ee4718028
commit
ead50a8eae
|
@ -1,12 +1,13 @@
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
var retries = 0;
|
||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
console.log('Attempting to connect to WebSocket...');
|
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', () => {
|
ws.on('open', () => {
|
||||||
console.log('Connected to WebSocket');
|
console.log('Connected to WebSocket');
|
||||||
ws.send(JSON.stringify({ type: 'subscribe', channel: 'botstalk' }));
|
ws.send(JSON.stringify({ type: 'subscribe', channel: 'botstalk' }));
|
||||||
|
retries = 0; // Reset retries on successful connection
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('message', (data) => {
|
ws.on('message', (data) => {
|
||||||
|
@ -15,7 +16,10 @@ function connectWebSocket() {
|
||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
console.log('WebSocket connection closed. Reconnecting...');
|
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) => {
|
ws.on('error', (err) => {
|
||||||
|
|
22
index.js
22
index.js
|
@ -64,9 +64,24 @@ app.ws('/iem', (ws, req) => {
|
||||||
|
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
"type": "connection-info",
|
"type": "connection-info",
|
||||||
"state": true,
|
"status": socketStatus,
|
||||||
"uuid": curUUID,
|
"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: [] });
|
sock = wsConnections.push({ ws, req, subs: [] });
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
|
@ -444,11 +459,12 @@ xmpp.on("stanza", (stanza) => {
|
||||||
"data": {
|
"data": {
|
||||||
"channel": getWFOByRoom(fromChannel),
|
"channel": getWFOByRoom(fromChannel),
|
||||||
"event": evt,
|
"event": evt,
|
||||||
"body": bodyData.string,
|
"body": bodyData,
|
||||||
"timestamp": product_id.timestamp,
|
"timestamp": product_id.timestamp,
|
||||||
"wmo": product_id.wmo,
|
"wmo": product_id.wmo,
|
||||||
"pil": product_id.pil,
|
"pil": product_id.pil,
|
||||||
"station": product_id.station,
|
"station": product_id.station,
|
||||||
|
"product_data": product_id,
|
||||||
"raw": product_id_raw,
|
"raw": product_id_raw,
|
||||||
"rawBody": body,
|
"rawBody": body,
|
||||||
"image": stanza.getChild("x").attrs.twitter_media || null,
|
"image": stanza.getChild("x").attrs.twitter_media || null,
|
||||||
|
|
Loading…
Reference in a new issue