-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(simbridge): simbridge client (#7378)
* 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
Showing
15 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable camelcase */ | ||
export interface Airport { | ||
icao_code: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface General { | ||
route: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Fix } from './fix'; | ||
|
||
export class Navlog { | ||
fix: Fix[] = [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |