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 = [];
|
global.wsConnections = [];
|
||||||
var roomList = [];
|
var roomList = [];
|
||||||
|
|
||||||
// IEM WebSocket
|
// IEM WebSocket
|
||||||
app.ws('/iem', (ws, req) => {
|
app.ws('/iem', (ws, req) => {
|
||||||
console.log(req.headers)
|
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}`);
|
console.log(`connection from ${clientIp}`);
|
||||||
const hostname = process.env.HOST_OVERRIDE || os.hostname();
|
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({
|
ws.send(JSON.stringify({
|
||||||
"type": "connection-info",
|
"type": "connection-info",
|
||||||
"status": socketStatus,
|
"status": socketStatus,
|
||||||
|
@ -399,8 +412,14 @@ xmpp.on("offline", () => {
|
||||||
xmpp.disconnect().then(() => {
|
xmpp.disconnect().then(() => {
|
||||||
xmpp.stop().then(() => {
|
xmpp.stop().then(() => {
|
||||||
start();
|
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;
|
var restartTimer = null;
|
||||||
|
@ -633,6 +652,14 @@ xmpp.on("close", () => {
|
||||||
|
|
||||||
const start = () => {
|
const start = () => {
|
||||||
startup = true;
|
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) => {
|
xmpp.start().catch((err) => {
|
||||||
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
|
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
|
||||||
setTimeout(start, 5000);
|
setTimeout(start, 5000);
|
||||||
|
|
Loading…
Reference in a new issue