Compare commits
2 commits
26f6e7e9c2
...
4249815c55
Author | SHA1 | Date | |
---|---|---|---|
|
4249815c55 | ||
|
bca8efef23 |
44
index.js
44
index.js
|
@ -59,6 +59,7 @@ global.wsConnections = [];
|
|||
var roomList = [];
|
||||
// IEM WebSocket
|
||||
app.ws('/iem', (ws, req) => {
|
||||
req.ip = process.env.REALIP ? req.headers[process.env.REALIP.toLowerCase()] : req.ip;
|
||||
console.log(`connection from ${req.ip}`);
|
||||
const hostname = process.env.HOST_OVERRIDE || os.hostname();
|
||||
|
||||
|
@ -90,7 +91,20 @@ app.ws('/iem', (ws, req) => {
|
|||
});
|
||||
try {
|
||||
ws.on('message', (msg) => {
|
||||
const data = JSON.parse(msg);
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(msg);
|
||||
} catch (error) {
|
||||
ws.send(JSON.stringify({
|
||||
"type": "internal-response",
|
||||
"code": 400,
|
||||
"data": {
|
||||
"error": "Invalid JSON format."
|
||||
}
|
||||
}));
|
||||
console.log(`${colors.red("[ERROR]")} Invalid JSON format from ${req.ip}: ${msg}`);
|
||||
return;
|
||||
}
|
||||
if (!data.type) return ws.send(JSON.stringify({
|
||||
"type": "internal-response",
|
||||
"code": 400,
|
||||
|
@ -191,6 +205,15 @@ app.ws('/iem', (ws, req) => {
|
|||
}));
|
||||
}
|
||||
break;
|
||||
case "ping":
|
||||
ws.send(JSON.stringify({
|
||||
"type": "internal-response",
|
||||
"code": 200,
|
||||
"data": {
|
||||
"message": "pong"
|
||||
}
|
||||
}));
|
||||
break;
|
||||
default:
|
||||
ws.send(JSON.stringify({
|
||||
"type": "internal-response",
|
||||
|
@ -551,25 +574,6 @@ xmpp.reconnect.on("reconnected", () => {
|
|||
});
|
||||
})
|
||||
|
||||
const createDiscordEmbed = (data) => {
|
||||
const embed = {
|
||||
description: `<t:${Math.floor(data.timestamp / 1000)}:T> <t:${Math.floor(data.timestamp / 1000)}:R> ${data.body}`,
|
||||
color: parseInt(config.priorityColors[data.event.priority].replace("#", ""), 16) || 0x000000,
|
||||
timestamp: new Date(data.timestamp).toISOString(),
|
||||
footer: {
|
||||
text: `Station: ${data.station} PID: ${data.raw} Channel: ${data.channel}`
|
||||
}
|
||||
};
|
||||
|
||||
if (data.image) {
|
||||
embed.image = {
|
||||
url: data.image
|
||||
};
|
||||
}
|
||||
|
||||
return embed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
xmpp.on("online", async (address) => {
|
||||
|
|
Loading…
Reference in a new issue