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