Skip to content

Commit

Permalink
feat(simbridge): simbridge client (#7378)
Browse files Browse the repository at this point in the history
* Initial Commit

* Simbridge client returns objects rather than response

* remove Terrain Component
- Terrain component added when #7268 merged

* fix: added src folder to folder structure
  • Loading branch information
Lucky38i authored Aug 12, 2022
1 parent de09300 commit 050f645
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/flybywire-aircraft-a320-neo/html_ui/JS/fmgc/
/flybywire-aircraft-a320-neo/html_ui/JS/sentry-client/
/flybywire-aircraft-a320-neo/html_ui/JS/tcas/
/flybywire-aircraft-a320-neo/html_ui/JS/simbridge-client/
/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/*
!/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/PFD
/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/PFD/*.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<script type="text/html" import-script="/Pages/VCockpit/Instruments/Shared/FlightElements/GeoCalc.js"></script>
<script type="text/html" import-script="/JS/atsu/atsu.js"></script>
<script type="text/html" import-script="/JS/sentry-client/sentry-client.js"></script>
<script type="text/html" import-script="/JS/simbridge-client/simbridge-client.js"></script>
<script type="text/html" import-script="/JS/fmgc/LzUtf8.js"></script>
<script type="text/html" import-script="/JS/fmgc/fmgc.js"></script>
<script type="text/html" import-script="/Pages/VCockpit/Instruments/NavSystems/Shared/LogicElements/SearchField.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions igniter.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default new TaskOfTasks('a32nx', [
'src/flypad-backend/build.sh',
'wasm-opt -O1 -o flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/flypad-backend.wasm flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/flypad-backend.wasm'
], ['src/flypad-backend', 'flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/flypad-backend.wasm']),
new TaskOfTasks('simbridge', [
new ExecTask('client', ['npm run build:simbridge-client'], ['src/simbridge-client', 'flybywire-aircraft-a320-neo/html_ui/JS/simbridge-client']),
]),
new TaskOfTasks('mcdu-server', [
new ExecTask('client', ['npm run build:mcdu-client'], ['src/mcdu-server/client', 'src/mcdu-server/client/build']),
new ExecTask('server', ['npm run build:mcdu-server'], ['src/mcdu-server', 'flybywire-aircraft-a320-neo/MCDU SERVER/server.exe']),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"build:pfd": "cd src/instruments/src/PFD && rollup -c",
"build:mcdu-client": "rollup -c src/mcdu-server/client/rollup.config.js",
"build:mcdu-server": "pkg src/mcdu-server/index.js --target node12-win-x64 --no-bytecode --public-packages \"*\" --public --output \"flybywire-aircraft-a320-neo/MCDU SERVER/server.exe\"",
"build:simbridge-client": "rollup -c src/simbridge-client/rollup.config.js",
"build:ace": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -wc .\\src\\instruments\\buildSrc\\aceBuild.mjs"
},
"lint-staged": {
Expand Down
75 changes: 75 additions & 0 deletions src/simbridge-client/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* MIT License
*
* Copyright (c) 2022 FlyByWire Simulations
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

'use strict';

const { join } = require('path');
const babel = require('@rollup/plugin-babel').default;
const { typescriptPaths } = require('rollup-plugin-typescript-paths');
const dotenv = require('dotenv');
const commonjs = require('@rollup/plugin-commonjs');
const nodeResolve = require('@rollup/plugin-node-resolve').default;
const json = require('@rollup/plugin-json');

const replace = require('@rollup/plugin-replace');

const extensions = ['.js', '.ts'];

const src = join(__dirname, '..');
const root = join(__dirname, '..', '..');

dotenv.config();

process.chdir(src);

module.exports = {
input: join(__dirname, 'src/index.ts'),
plugins: [
nodeResolve({ extensions, browser: true }),
commonjs(),
json(),
babel({
presets: ['@babel/preset-typescript', ['@babel/preset-env', { targets: { browsers: ['safari 11'] } }]],
plugins: [
'@babel/plugin-proposal-class-properties',
],
extensions,
}),
typescriptPaths({
tsConfigPath: join(src, 'tsconfig.json'),
preserveExtensions: true,
}),
replace({
'DEBUG': 'false',
'process.env.NODE_ENV': '"production"',
'process.env.SENTRY_DSN': JSON.stringify(process.env.SENTRY_DSN),
'preventAssignment': true,
}),
],
output: {
file: join(root, 'flybywire-aircraft-a320-neo/html_ui/JS/simbridge-client/simbridge-client.js'),
format: 'umd',
name: 'SimbridgeClient',
},
};
4 changes: 4 additions & 0 deletions src/simbridge-client/src/Coroute/Airport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable camelcase */
export interface Airport {
icao_code: String
}
16 changes: 16 additions & 0 deletions src/simbridge-client/src/Coroute/Fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable camelcase */
export interface Fix {
ident: String

name: String

type: String

via_airway: String

is_sid_star: String

pos_lat: String

pos_long: String
}
3 changes: 3 additions & 0 deletions src/simbridge-client/src/Coroute/General.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface General {
route: string
}
5 changes: 5 additions & 0 deletions src/simbridge-client/src/Coroute/Navlog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Fix } from './fix';

export class Navlog {
fix: Fix[] = []
}
15 changes: 15 additions & 0 deletions src/simbridge-client/src/Coroute/coroute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Airport } from './Airport';
import { General } from './General';
import { Navlog } from './Navlog';

export interface CoRouteDto {
name: String;

origin: Airport;

destination: Airport;

general: General;

navlog: Navlog
}
3 changes: 3 additions & 0 deletions src/simbridge-client/src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NXDataStore } from '@shared/persistence';

export const simbridgeUrl: String = `http://localhost:${NXDataStore.get('CONFIG_SIMBRIDGE_PORT', '8380')}`;
40 changes: 40 additions & 0 deletions src/simbridge-client/src/components/Coroute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { simbridgeUrl } from '../common';
import { CoRouteDto } from '../Coroute/coroute';

/**
* Class responsible for retrieving data related to company routes from SimBridge
*/
export class CompanyRoute {
/**
* Used to retrieve a given company route
* @param route The routename in question
* @returns Returns the CoRoute DTO
*/
public static async getCoRoute(route: String): Promise<CoRouteDto> {
if (route) {
const response = await fetch(`${simbridgeUrl}/api/v1/coroute?rteNum=${route}`);
if (response.status === 200) {
response.json();
}
throw new Error('Server Error');
}
throw new Error('No Company route provided');
}

/**
* Used to retrieve a list of company routes for a given origin and dest
* @param origin the origin
* @param dest the destination
* @returns Returns a list of CoRoute DTOs
*/
public static async getRouteList(origin: String, dest: String): Promise<CoRouteDto[]> {
if (origin || dest) {
const response = await fetch(`${simbridgeUrl}/api/v1/coroute/list?origin=${origin}&destination=${dest}`);
if (response.ok) {
response.json();
}
throw new Error('Server Error');
}
throw new Error('Origin or Destination missing');
}
}
79 changes: 79 additions & 0 deletions src/simbridge-client/src/components/Viewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { simbridgeUrl } from '../common';

/**
* Class pertaining to retrieving static files for general viewing from SimBridge
*/
export class Viewer {
/**
* Used to retrieve a streamable image of specified page within a given PDF file
* @param filename required field, filename of the pdf
* @param pageNumber required field, The page of the PDF file
* @returns a Blob
*/
public static async getPDFPage(filename: string, pageNumber: number): Promise<Blob> {
if (filename || pageNumber) {
const response = await fetch(`${simbridgeUrl}/api/v1/utility/pdf?filename=${filename}&pagenumber=${pageNumber}`);
if (response.ok) {
return response.blob();
}
throw new Error(`SimBridge Error: ${response.status}`);
}
throw new Error('File name or page number missing');
}

/**
* Retrieve the number of pages within a specified PDF file
* @param filename required field, filename of the pdf
* @returns A number
*/
public static async getPDFPageNum(filename: string): Promise<Number> {
if (filename) {
const response = await fetch(`${simbridgeUrl}/api/v1/utility/pdf/numpages?filename=${filename}`);
if (response.ok) {
return response.json();
}
throw new Error(`SimBridge Error: ${response.status}`);
}
throw new Error('File name or page number missing');
}

/**
* Used to retrieve a list of filenames within the PDF folder
* @returns an Array of strings
*/
public static async getPDFList(): Promise<string[]> {
const response = await fetch(`${simbridgeUrl}/api/v1/utility/pdf/list`);
if (response.ok) {
return response.json();
}
throw new Error(`SimBridge Error: ${response.status}`);
}

/**
* Used to retrieve a streamable image of a specified image in the images folder
* @param filename required field, filename of the image
* @returns A Blob
*/
public static async getImage(filename: string, pageNumber: number): Promise<Blob> {
if (filename || pageNumber) {
const response = await fetch(`${simbridgeUrl}/api/v1/utility/image?filename=${filename}`);
if (response.ok) {
return response.blob();
}
throw new Error(`SimBridge Error: ${response.status}`);
}
throw new Error('File name or page number missing');
}

/**
* Used to retrieve a list of filenames within the PDF folder
* @returns an Array of strings
*/
public static async getImageList(): Promise<string[]> {
const response = await fetch(`${simbridgeUrl}/api/v1/utility/image/list`);
if (response.ok) {
return response.json();
}
throw new Error(`SimBridge Error: ${response.status}`);
}
}
4 changes: 4 additions & 0 deletions src/simbridge-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { CompanyRoute } from './components/Coroute';
import { Viewer } from './components/Viewer';

export { CompanyRoute, Viewer };
13 changes: 13 additions & 0 deletions src/simbridge-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"target": "ESNext",
"noEmit": true,
"typeRoots": ["../../typings"]
},
"include": [
"src/**/*",
"../../typings/**/*.d.ts"
]
}

0 comments on commit 050f645

Please sign in to comment.