fix: Audio backend working if both port and endpoint added

Added ability to use uri for backend address (remote debugging)
This commit is contained in:
Davide Passoni 2025-03-13 16:54:16 +01:00
parent 760fe18cc7
commit 5acc0e8ac5
3 changed files with 75 additions and 37 deletions

View File

@ -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) => {

View File

@ -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 }));

View File

@ -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;