Guh?
This commit is contained in:
parent
ff0a1215c2
commit
fe5ac6073a
20
index.js
20
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,6 +444,8 @@ xmpp.on("stanza", (stanza) => {
|
|||
if (wsConnections.length > 0) {
|
||||
wsConnections.forEach((ws) => {
|
||||
ws.send(JSON.stringify({
|
||||
"type": "iem-message",
|
||||
"data": {
|
||||
"channel": getWFOByRoom(fromChannel),
|
||||
"event": evt,
|
||||
"body": bodyData.string,
|
||||
|
@ -443,6 +456,7 @@ xmpp.on("stanza", (stanza) => {
|
|||
"raw": product_id_raw,
|
||||
"rawBody": body,
|
||||
"image": stanza.getChild("x").attrs.twitter_media || null
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
|
35
public/index.html
Normal file
35
public/index.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="stuff"></div>
|
||||
<script>
|
||||
const socket = new WebSocket(`ws://${window.location.host}/iem`);
|
||||
socket.onopen = () => {
|
||||
const newDiv = document.createElement('div');
|
||||
newDiv.innerText = "WebSocket connection opened";
|
||||
document.getElementById('stuff').prepend(newDiv);
|
||||
|
||||
};
|
||||
socket.onclose = () => {
|
||||
const newDiv = document.createElement('div');
|
||||
newDiv.innerText = "WebSocket connection closed";
|
||||
document.getElementById('stuff').prepend(newDiv);
|
||||
|
||||
};
|
||||
socket.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
const explanation = `Event: ${JSON.stringify(data.event)}, Channel: ${JSON.stringify(data.channel)}, Station: ${data.station}`;
|
||||
console.log(explanation);
|
||||
const newDiv = document.createElement('div');
|
||||
newDiv.innerText = explanation;
|
||||
document.getElementById('stuff').prepend(newDiv);
|
||||
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue