mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added proxy middleware and demo backend app
This commit is contained in:
@@ -11,11 +11,6 @@ declare global {
|
||||
function getOlympusPlugin(): OlympusPlugin;
|
||||
}
|
||||
|
||||
export interface ConfigurationOptions {
|
||||
port: number;
|
||||
address: string;
|
||||
}
|
||||
|
||||
export interface ContextMenuOption {
|
||||
tooltip: string;
|
||||
src: string;
|
||||
|
||||
@@ -24,7 +24,6 @@ import { aircraftDatabase } from "./unit/databases/aircraftdatabase";
|
||||
import { helicopterDatabase } from "./unit/databases/helicopterdatabase";
|
||||
import { groundUnitDatabase } from "./unit/databases/groundunitdatabase";
|
||||
import { navyUnitDatabase } from "./unit/databases/navyunitdatabase";
|
||||
import { ConfigurationOptions } from "./interfaces";
|
||||
import { UnitListPanel } from "./panels/unitlistpanel";
|
||||
import { ContextManager } from "./context/contextmanager";
|
||||
import { Context } from "./context/context";
|
||||
@@ -216,19 +215,8 @@ export class OlympusApp {
|
||||
|
||||
this.#pluginsManager = new PluginsManager();
|
||||
|
||||
/* Load the config file from the app server*/
|
||||
this.getServerManager().getConfig((config: ConfigurationOptions) => {
|
||||
if (config && config.address != undefined && config.port != undefined) {
|
||||
const address = config.address;
|
||||
const port = config.port;
|
||||
if (typeof address === 'string' && typeof port == 'number') {
|
||||
this.getServerManager().setAddress(address == "*" ? window.location.hostname : address, port);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error('Could not read configuration file');
|
||||
}
|
||||
});
|
||||
/* Set the address of the server */
|
||||
this.getServerManager().setAddress(window.location.href.split('?')[0]);
|
||||
|
||||
/* Setup all global events */
|
||||
this.#setupEvents();
|
||||
@@ -294,16 +282,7 @@ export class OlympusApp {
|
||||
});
|
||||
|
||||
const shortcutManager = this.getShortcutManager();
|
||||
shortcutManager.addKeyboardShortcut("toggleDemo", {
|
||||
"altKey": false,
|
||||
"callback": () => {
|
||||
if (DEBUG === true) this.getServerManager().toggleDemoEnabled();
|
||||
},
|
||||
"code": "KeyT",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
}).addKeyboardShortcut("togglePause", {
|
||||
shortcutManager.addKeyboardShortcut("togglePause", {
|
||||
"altKey": false,
|
||||
"callback": () => {
|
||||
this.getServerManager().setPaused(!this.getServerManager().getPaused());
|
||||
|
||||
@@ -11,13 +11,11 @@ import { zeroAppend } from '../other/utils';
|
||||
export class ServerManager {
|
||||
#connected: boolean = false;
|
||||
#paused: boolean = false;
|
||||
#REST_ADDRESS = "http://localhost:30000/olympus";
|
||||
#DEMO_ADDRESS = window.location.href.split('?')[0] + "demo"; /* Remove query parameters */
|
||||
#REST_ADDRESS = "http://localhost:3001/olympus";
|
||||
#username = "";
|
||||
#password = "";
|
||||
#sessionHash: string | null = null;
|
||||
#lastUpdateTimes: { [key: string]: number } = {}
|
||||
#demoEnabled = false;
|
||||
#previousMissionElapsedTime: number = 0; // Track if mission elapsed time is increasing (i.e. is the server paused)
|
||||
#serverIsPaused: boolean = false;
|
||||
#intervals: number[] = [];
|
||||
@@ -32,10 +30,6 @@ export class ServerManager {
|
||||
this.#lastUpdateTimes[MISSION_URI] = Date.now();
|
||||
}
|
||||
|
||||
toggleDemoEnabled() {
|
||||
this.#demoEnabled = !this.#demoEnabled;
|
||||
}
|
||||
|
||||
setCredentials(newUsername: string, newPassword: string) {
|
||||
this.#username = newUsername;
|
||||
this.#password = newPassword;
|
||||
@@ -63,7 +57,7 @@ export class ServerManager {
|
||||
optionsString = `commandHash=${options.commandHash}`;
|
||||
|
||||
/* On the connection */
|
||||
xmlHttp.open("GET", `${this.#demoEnabled ? this.#DEMO_ADDRESS : this.#REST_ADDRESS}/${uri}${optionsString ? `?${optionsString}` : ''}`, true);
|
||||
xmlHttp.open("GET", `${this.#REST_ADDRESS}/${uri}${optionsString ? `?${optionsString}` : ''}`, true);
|
||||
|
||||
/* If provided, set the credentials */
|
||||
if (this.#username && this.#password)
|
||||
@@ -106,7 +100,7 @@ export class ServerManager {
|
||||
|
||||
PUT(request: object, callback: CallableFunction) {
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.open("PUT", this.#demoEnabled ? this.#DEMO_ADDRESS : this.#REST_ADDRESS);
|
||||
xmlHttp.open("PUT", this.#REST_ADDRESS);
|
||||
xmlHttp.setRequestHeader("Content-Type", "application/json");
|
||||
if (this.#username && this.#password)
|
||||
xmlHttp.setRequestHeader("Authorization", "Basic " + btoa(`${this.#username}:${this.#password}`));
|
||||
@@ -130,8 +124,8 @@ export class ServerManager {
|
||||
xmlHttp.send(null);
|
||||
}
|
||||
|
||||
setAddress(address: string, port: number) {
|
||||
this.#REST_ADDRESS = `http://${address}:${port}/olympus`
|
||||
setAddress(address: string) {
|
||||
this.#REST_ADDRESS = `${address}olympus`
|
||||
console.log(`Setting REST address to ${this.#REST_ADDRESS}`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user