I think stuff changed
This commit is contained in:
parent
b1777ffa4e
commit
a3066ec5a3
33
index.js
33
index.js
|
@ -57,13 +57,26 @@ app.get('/health', (req, res) => {
|
|||
|
||||
global.wsConnections = [];
|
||||
var roomList = [];
|
||||
|
||||
// IEM WebSocket
|
||||
app.ws('/iem', (ws, req) => {
|
||||
console.log(req.headers)
|
||||
const clientIp = process.env.REALIP ? req.headers[process.env.REALIP.toLowerCase()] : req.ip;
|
||||
const clientIp = process.env.REALIP ? req.headers[process.env.REALIP.toLowerCase()] || req.ip : req.ip;
|
||||
console.log(`connection from ${clientIp}`);
|
||||
const hostname = process.env.HOST_OVERRIDE || os.hostname();
|
||||
if (!req.headers['user-agent']) {
|
||||
ws.send(JSON.stringify({
|
||||
"type": "internal-response",
|
||||
"code": 400,
|
||||
"data": {
|
||||
"error": "User-Agent header is required."
|
||||
}
|
||||
}));
|
||||
|
||||
console.log(`${colors.red("[ERROR]")} User-Agent header is required from ${clientIp}`);
|
||||
ws.close();
|
||||
return;
|
||||
}
|
||||
ws.send(JSON.stringify({
|
||||
"type": "connection-info",
|
||||
"status": socketStatus,
|
||||
|
@ -399,8 +412,14 @@ xmpp.on("offline", () => {
|
|||
xmpp.disconnect().then(() => {
|
||||
xmpp.stop().then(() => {
|
||||
start();
|
||||
})
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.log(`${colors.red("[ERROR]")} XMPP failed to stop: ${err}. Gonna go ahead and try to reconnect...`);
|
||||
start();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log(`${colors.red("[ERROR]")} XMPP failed to disconnect: ${err}. Gonna go ahead and try to reconnect...`);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
var restartTimer = null;
|
||||
|
@ -633,6 +652,14 @@ xmpp.on("close", () => {
|
|||
|
||||
const start = () => {
|
||||
startup = true;
|
||||
if (xmpp.status !== "offline") {
|
||||
console.log(`${colors.yellow("[WARN]")} XMPP is already running, stopping it...`);
|
||||
xmpp.stop().then(() => {
|
||||
console.log(`${colors.cyan("[INFO]")} XMPP stopped, starting it again...`);
|
||||
}).catch((err) => {
|
||||
console.log(`${colors.red("[ERROR]")} Failed to stop XMPP: ${err}. Trying to start anyway...`);
|
||||
});
|
||||
}
|
||||
xmpp.start().catch((err) => {
|
||||
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
|
||||
setTimeout(start, 5000);
|
||||
|
|
Loading…
Reference in a new issue