1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 14:11:59 +01:00

community tunnel, minor bugfixes

This commit is contained in:
Marek Farkaš
2025-11-30 22:49:00 +01:00
parent 7f6957e162
commit 531a0f23e6
10 changed files with 108 additions and 24 deletions

View File

@@ -155,14 +155,6 @@ router.get('/wizard', (req, res) => {
});
router.get('/rds', (req, res) => {
res.send('Please connect using a WebSocket compatible app to obtain RDS stream.');
});
router.get('/rdsspy', (req, res) => {
res.send('Please connect using a WebSocket compatible app to obtain RDS stream.');
});
router.get('/rds', (req, res) => {
res.send('Please connect using a WebSocket compatible app to obtain RDS stream.');
});
@@ -466,4 +458,24 @@ router.get('/log_fmlist', (req, res) => {
request.end();
});
router.get('/tunnelservers', async (req, res) => {
const servers = [
{ value: "eu", host: "eu.fmtuner.org", label: "Europe" },
{ value: "us", host: "us.fmtuner.org", label: "Americas" },
{ value: "sg", host: "sg.fmtuner.org", label: "Asia & Oceania" },
];
const results = await Promise.all(
servers.map(async s => {
const latency = await helpers.checkLatency(s.host);
return {
value: s.value,
label: `${s.label} (${latency ? latency + ' ms' : 'offline'})` // From my tests, the latency via HTTP ping is roughly 2x higher than regular ping
};
})
);
res.json(results);
});
module.exports = router;

View File

@@ -240,6 +240,23 @@ function checkIPv6Support(callback) {
});
}
function checkLatency(host) {
return new Promise(resolve => {
const start = Date.now();
const req = http.get({ host, timeout: 2000 }, res => {
res.resume(); // discard body
resolve(Date.now() - start);
});
req.on("error", () => resolve(null)); // server offline
req.on("timeout", () => {
req.destroy();
resolve(null);
});
});
}
function antispamProtection(message, clientIp, ws, userCommands, lastWarn, userCommandHistory, lengthCommands, endpointName) {
const command = message.toString();
const now = Date.now();
@@ -313,5 +330,5 @@ const escapeHtml = (unsafe) => {
module.exports = {
authenticateWithXdrd, parseMarkdown, handleConnect, removeMarkdown, formatUptime, resolveDataBuffer, kickClient, checkIPv6Support, antispamProtection, escapeHtml
authenticateWithXdrd, parseMarkdown, handleConnect, removeMarkdown, formatUptime, resolveDataBuffer, kickClient, checkIPv6Support, checkLatency, antispamProtection, escapeHtml
}

View File

@@ -94,10 +94,15 @@ let serverConfig = {
enabled: false,
username: "",
token: "",
region: "eu",
lowLatencyMode: false,
subdomain: "",
httpName: "",
httpPassword: "",
community: {
enabled: false,
host: ""
}
},
plugins: [],
device: 'tef',

View File

@@ -41,6 +41,7 @@ async function connect() {
}
const cfg = ejs.render(frpcConfigTemplate, {
cfg: serverConfig.tunnel,
host: serverConfig.tunnel.community.enabled ? serverConfig.tunnel.community.host : serverConfig.tunnel.region + ".fmtuner.org",
server: {
port: serverConfig.webserver.webserverPort
}
@@ -84,7 +85,7 @@ async function connect() {
}
const frpcConfigTemplate = `
serverAddr = "fmtuner.org"
serverAddr = "<%= host %>"
serverPort = 7000
loginFailExit = false
log.disablePrintColor = true