From 760fe18cc77092c532bbdd0b904d4848ded1779d Mon Sep 17 00:00:00 2001 From: Davide Passoni Date: Thu, 13 Mar 2025 09:39:34 +0100 Subject: [PATCH 1/2] fix: Autoconnect when local checkbox not reflecting configuration --- manager/javascripts/dcsinstance.js | 2 +- manager/javascripts/manager.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/manager/javascripts/dcsinstance.js b/manager/javascripts/dcsinstance.js index 9aa93fd1..ca9ca63c 100644 --- a/manager/javascripts/dcsinstance.js +++ b/manager/javascripts/dcsinstance.js @@ -190,7 +190,7 @@ class DCSInstance { this.gameMasterPasswordHash = config["authentication"]["gameMasterPassword"]; /* Read the new configurations added in v2.0.0 */ - if ( config["frontend"]["autoconnectWhenLocal"] !== undefined) + if (config["frontend"]["autoconnectWhenLocal"] !== undefined) this.autoconnectWhenLocal = config["frontend"]["autoconnectWhenLocal"]; if (config["frontend"]["audio"] !== undefined && config["frontend"]["audio"]["SRSPort"] !== undefined) this.SRSPort = config["audio"]["SRSPort"]; diff --git a/manager/javascripts/manager.js b/manager/javascripts/manager.js index 3bcbedb3..691bedc8 100644 --- a/manager/javascripts/manager.js +++ b/manager/javascripts/manager.js @@ -159,6 +159,7 @@ class Manager { if (this.getActiveInstance()) { this.setPort('frontend', this.getActiveInstance().frontendPort); this.setPort('backend', this.getActiveInstance().backendPort); + this.expertSettingsPage.getElement().querySelector(".autoconnect .checkbox").classList.toggle("checked", this.getActiveInstance().autoconnectWhenLocal) } } From 5acc0e8ac567f302b08c89d40bea67438c1cb38a Mon Sep 17 00:00:00 2001 From: Davide Passoni Date: Thu, 13 Mar 2025 16:54:16 +0100 Subject: [PATCH 2/2] fix: Audio backend working if both port and endpoint added Added ability to use uri for backend address (remote debugging) --- frontend/react/src/audio/audiomanager.ts | 24 ++++++++----- frontend/server/src/app.ts | 43 ++++++++++++++-------- frontend/server/src/routes/admin.ts | 45 ++++++++++++++++-------- 3 files changed, 75 insertions(+), 37 deletions(-) diff --git a/frontend/react/src/audio/audiomanager.ts b/frontend/react/src/audio/audiomanager.ts index 8c4e0094..be88f287 100644 --- a/frontend/react/src/audio/audiomanager.ts +++ b/frontend/react/src/audio/audiomanager.ts @@ -54,10 +54,10 @@ export class AudioManager { constructor() { ConfigLoadedEvent.on((config: OlympusConfig) => { - if (config.audio) - config.audio.WSPort ? this.setPort(config.audio.WSPort) : this.setEndpoint(config.audio.WSEndpoint); - else - console.error("No audio configuration found in the Olympus configuration file"); + if (config.audio) { + this.setPort(config.audio.WSPort); + this.setEndpoint(config.audio.WSEndpoint); + } else console.error("No audio configuration found in the Olympus configuration file"); }); CommandModeOptionsChangedEvent.on((options: CommandModeOptions) => { @@ -101,11 +101,19 @@ export class AudioManager { let wsAddress = res ? res[1] : location.toString(); if (wsAddress.at(wsAddress.length - 1) === "/") wsAddress = wsAddress.substring(0, wsAddress.length - 1); - if (this.#endpoint) this.#socket = new WebSocket(`wss://${wsAddress}/${this.#endpoint}`); - else if (this.#port) this.#socket = new WebSocket(`ws://${wsAddress}:${this.#port}`); - else console.error("The audio backend was enabled but no port/endpoint was provided in the configuration"); - if (!this.#socket) return; + if (this.#port === undefined && this.#endpoint === undefined) { + console.error("The audio backend was enabled but no port/endpoint was provided in the configuration"); + return; + } + + this.#socket = new WebSocket(`wss://${wsAddress}/${this.#endpoint}`); + if (!this.#socket) this.#socket = new WebSocket(`ws://${wsAddress}:${this.#port}`); + + if (!this.#socket) { + console.error("Failed to connect to audio websocket"); + return; + } /* Log the opening of the connection */ this.#socket.addEventListener("open", (event) => { diff --git a/frontend/server/src/app.ts b/frontend/server/src/app.ts index b74b57e9..0ceb1a37 100644 --- a/frontend/server/src/app.ts +++ b/frontend/server/src/app.ts @@ -126,9 +126,13 @@ module.exports = function (configLocation, viteProxy) { }); /* Define middleware */ - app.use(logger('dev', { - skip: function (req, res) { return res.statusCode < 400 } - })); + app.use( + logger("dev", { + skip: function (req, res) { + return res.statusCode < 400; + }, + }) + ); /* Authorization middleware */ if ( @@ -166,7 +170,7 @@ module.exports = function (configLocation, viteProxy) { app.use("/olympus", async (req, res, next) => { /* Check if custom authorization headers are being used */ const user = - //@ts-ignore + //@ts-ignore req.auth?.user ?? checkCustomHeaders(config, usersConfig, groupsConfig, req); @@ -221,16 +225,27 @@ module.exports = function (configLocation, viteProxy) { }); /* Proxy middleware */ - app.use( - "/olympus", - httpProxyMiddleware.createProxyMiddleware({ - target: `http://${ - backendAddress === "*" ? "localhost" : backendAddress - }:${config["backend"]["port"]}/olympus`, - changeOrigin: true, - }) - ); - + if (config["backend"]["port"]) { + app.use( + "/olympus", + httpProxyMiddleware.createProxyMiddleware({ + target: `http://${ + backendAddress === "*" ? "localhost" : backendAddress + }:${config["backend"]["port"]}/olympus`, + changeOrigin: true, + }) + ); + } else { + app.use( + "/olympus", + httpProxyMiddleware.createProxyMiddleware({ + target: `https://${ + backendAddress === "*" ? "localhost" : backendAddress + }/olympus`, + changeOrigin: true, + }) + ); + } app.use(bodyParser.json({ limit: "50mb" })); app.use(bodyParser.urlencoded({ limit: "50mb", extended: true })); diff --git a/frontend/server/src/routes/admin.ts b/frontend/server/src/routes/admin.ts index d39a6a99..caed34ff 100644 --- a/frontend/server/src/routes/admin.ts +++ b/frontend/server/src/routes/admin.ts @@ -45,29 +45,44 @@ module.exports = function (configLocation) { router.put("/config", function (req, res, next) { if (req.auth?.user === "Admin") { /* Create a backup folder for the configuration files */ - let backupFolder = path.join(path.dirname(configLocation), "Olympus Configs Backup"); + let backupFolder = path.join( + path.dirname(configLocation), + "Olympus Configs Backup" + ); if (!fs.existsSync(backupFolder)) { fs.mkdirSync(backupFolder); } /* Make a backup of the existing files */ let timestamp = new Date().toISOString().replace(/:/g, "-"); - fs.copyFileSync( - path.join(path.dirname(configLocation), "olympusUsers.json"), - path.join( - path.dirname(configLocation), - "Olympus Configs Backup", - "olympusUsers.json." + timestamp + if ( + fs.existsSync( + path.join(path.dirname(configLocation), "olympusUsers.json") ) - ); - fs.copyFileSync( - path.join(path.dirname(configLocation), "olympusGroups.json"), - path.join( - path.dirname(configLocation), - "Olympus Configs Backup", - "olympusGroups.json." + timestamp + ) { + fs.copyFileSync( + path.join(path.dirname(configLocation), "olympusUsers.json"), + path.join( + path.dirname(configLocation), + "Olympus Configs Backup", + "olympusUsers.json." + timestamp + ) + ); + } + if ( + fs.existsSync( + path.join(path.dirname(configLocation), "olympusGroups.json") ) - ); + ) { + fs.copyFileSync( + path.join(path.dirname(configLocation), "olympusGroups.json"), + path.join( + path.dirname(configLocation), + "Olympus Configs Backup", + "olympusGroups.json." + timestamp + ) + ); + } /* Save the users configuration file */ let usersConfig = req.body.users;