Skip to content

feat: Javascript interface and implementation of API based upon RFC 001 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 89 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
a28c6f9
chore: ignore DS_Store files
SkySails Dec 5, 2023
6af3f43
build: create base navdata-sdk module
SkySails Dec 5, 2023
0b4dd16
build: fix build with navdata-sdk
SkySails Dec 5, 2023
0b5162f
build: include navdata-sdk in tsconfig
SkySails Dec 5, 2023
d2d4774
refactor: add msfstypes to ts library
pepperoni505 Dec 6, 2023
ab9ed5b
wip(feat/restructure): centralized function call, raw sql query
pepperoni505 Dec 8, 2023
57b146e
refactor: clean up queue processing
pepperoni505 Dec 8, 2023
3c5d5ba
refactor: move lint and lint to root
pepperoni505 Dec 10, 2023
6304788
refactor: centralize communications between wasm and js, and cleanups
pepperoni505 Dec 11, 2023
0128e6a
refactor: apply clippy changes
pepperoni505 Dec 11, 2023
ac73208
refactor: rename Request to Task
pepperoni505 Dec 11, 2023
2299cb6
refactor: download status update flow
pepperoni505 Dec 12, 2023
4e7535c
refactor: move phase matching logic
pepperoni505 Dec 12, 2023
10f537c
refactor: add typescript interface typings
pepperoni505 Dec 12, 2023
a811280
refactor: use string values for NavigraphFunction enum
pepperoni505 Dec 12, 2023
2d5db33
refactor: use serde for all commbus related things
pepperoni505 Dec 12, 2023
e49fc66
docs: add note about the navdata interface construction
pepperoni505 Dec 12, 2023
1d4b818
refactor: switch instead of if chain
SkySails Dec 13, 2023
d40fc3f
chore: add temp. CommBus types, use types lib
SkySails Dec 13, 2023
bb4c48f
refactor: avoid array with `any` callbacks
SkySails Dec 13, 2023
03b07c7
refactor: strongly type `callWasmFunction` name param
SkySails Dec 13, 2023
6fb334a
chore: use lowercase for type declaration file
SkySails Dec 13, 2023
fc4c70f
refactor: improve error handling
SkySails Dec 13, 2023
d80b82e
refactor: move msfstypes to base package
pepperoni505 Dec 13, 2023
ab4d459
feat: add get airport function
pepperoni505 Dec 13, 2023
502d12d
fix: use string literal instead of enum
pepperoni505 Dec 14, 2023
827de97
chore: format
pepperoni505 Dec 14, 2023
3874a16
feat: unit tests and project refactor (#1)
professoralex13 Dec 30, 2023
ab402a3
fix: use params and support number fields in raw sql query
professoralex13 Jan 10, 2024
ba9e84e
start new API
professoralex13 Dec 30, 2023
3805c8e
feat: get airports in range
professoralex13 Dec 30, 2023
69ccba2
feat: Airways by ident
professoralex13 Jan 10, 2024
9b6da96
feat: Airways by range
professoralex13 Jan 10, 2024
af083bb
formatting
professoralex13 Jan 10, 2024
df68fa7
feat: Departures query
professoralex13 Jan 10, 2024
f1ebcc7
fix: sim issues
professoralex13 Jan 11, 2024
3a3fcc4
refactor: Move database out of wasm module
professoralex13 Jan 11, 2024
7dddbc8
refactor: switch to fully snake_case and other spec compliance
professoralex13 Jan 12, 2024
fd6a4ce
feat: arrivals
professoralex13 Jan 12, 2024
a52bc7b
refactor: procedure mapping
professoralex13 Jan 12, 2024
9302356
feat: get_database_info
professoralex13 Jan 12, 2024
463891c
refactor: remove uneccesary serde renames
professoralex13 Jan 12, 2024
66c675e
feat: Approaches
professoralex13 Jan 13, 2024
c79792f
fix: fix airport_ident
professoralex13 Jan 13, 2024
42d705b
pad out tests
professoralex13 Jan 13, 2024
a7bbcbf
feat: Waypoint and VhfNavaid queries
professoralex13 Jan 13, 2024
3a7cb7f
refactor: Generic range query generator
professoralex13 Jan 13, 2024
1bd42bb
feat: get runways at airport
professoralex13 Jan 13, 2024
14ec451
feat: Waypoint/VhfNavaid range queries
professoralex13 Jan 13, 2024
a6befbc
feat: ndb navaids
professoralex13 Jan 14, 2024
802f3e2
feat: navaid and waypoint airport queries
professoralex13 Jan 14, 2024
1e2dd92
feat: get airways at fix
professoralex13 Jan 14, 2024
848b0f4
feat: comments
professoralex13 Jan 14, 2024
19abbe5
feat: Airspace range queries
professoralex13 Jan 14, 2024
26acfc5
fix: missing Database Info type
professoralex13 Jan 15, 2024
f2fdfb7
fix: approach
professoralex13 Jan 15, 2024
7fe4a38
feat: gates
professoralex13 Jan 15, 2024
af9f266
feat: communications
professoralex13 Jan 16, 2024
caefef4
feat: Gls navaids
professoralex13 Jan 16, 2024
6e45f44
feat: pathpoints
professoralex13 Jan 16, 2024
da2e17f
improved documentation
professoralex13 Jan 16, 2024
b1ed00a
Update README.md
professoralex13 Jan 16, 2024
3e563a0
Update README.md
professoralex13 Jan 16, 2024
f055ad1
Update NavigraphLogin.tsx
professoralex13 Jan 16, 2024
9b2632d
fix: js interface return types
professoralex13 Jan 17, 2024
4163bf8
general fixes
professoralex13 Jan 17, 2024
dafb9ef
refactor workflow env
professoralex13 Jan 17, 2024
c141b34
Revert "refactor workflow env"
professoralex13 Jan 17, 2024
f4e838b
refactors and comments in js
professoralex13 Jan 17, 2024
635f81a
feat: click on qr code to login
professoralex13 Jan 18, 2024
443dcb3
test verbose
professoralex13 Jan 29, 2024
15d5763
test
professoralex13 Jan 29, 2024
002a4d4
test
professoralex13 Jan 29, 2024
7bde835
Update pr.yml
professoralex13 Jan 29, 2024
2828783
ci: run tests without docker
SkySails Jan 29, 2024
551070d
ci: run jest directly
SkySails Jan 29, 2024
0fd338e
ci: update actions, bump node version
SkySails Jan 29, 2024
41d807f
ci: disable cone mode for sparse-checkout
SkySails Jan 29, 2024
ae13b38
ci: exclude blobs instead of sparse
SkySails Jan 29, 2024
9fb0810
ci: skip installing packages in docker
SkySails Jan 29, 2024
ecab85a
ci: run correct test script
SkySails Jan 29, 2024
7a85b78
ci: temporarily skip WASM builds
SkySails Jan 29, 2024
9dd9d7f
ci: explicit node version, install deps
SkySails Jan 29, 2024
6081a62
ci: install deps inside docker
SkySails Jan 29, 2024
0e753a7
ci: make sure both commands run inside docker
SkySails Jan 29, 2024
a9a7f77
ci: revert to incorrect (but working) script
SkySails Jan 29, 2024
b7b1b6b
ci: reintroduce WASM build step
SkySails Jan 29, 2024
d813803
ci: move test run to separate line for clarity
SkySails Jan 29, 2024
01d2f40
Delete DOCS.md
professoralex13 Jan 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[target.wasm32-wasi]
rustflags = [
"-Clink-arg=--export-table",
"-Clink-arg=--export=malloc",
"-Clink-arg=--export=free",
"-Clink-arg=-L/usr/lib/llvm-15/lib/clang/15.0.7/lib/wasi",
"-Clink-arg=-lclang_rt.builtins-wasm32"
]
[build]
[target.wasm32-wasi]
rustflags = [
"-Clink-arg=--export-table",
"-Clink-arg=--export=malloc",
"-Clink-arg=--export=free",
"-Clink-arg=-L/usr/lib/llvm-15/lib/clang/15.0.7/lib/wasi",
"-Clink-arg=-lclang_rt.builtins-wasm32"
]

[build]
target = "wasm32-wasi"
2 changes: 1 addition & 1 deletion examples/gauge/.eslintrc.js → .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
root: true,
ignorePatterns: [".eslintrc.js"],
ignorePatterns: [".eslintrc.js", "src/wasm/", "msfstypes/"],
env: { browser: true, commonjs: true, es6: true },
plugins: ["@typescript-eslint"],
extends: [
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build WASM module
uses: actions/checkout@v4
with:
filter: blob:none

- name: Create env file
run: |
./src/wasm_navdata_interface/scripts/run_docker_cmd.sh ./scripts/build.sh
touch .env
echo NAVDATA_SIGNED_URL=${{ secrets.NAVDATA_SIGNED_URL }} >> .env

- name: Build WASM module
run: npm run build:wasm-workflow

- name: Test
run: npm run test-workflow

- name: Upload WASM module to GitHub
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: navdata_interface.wasm
path: ./src/wasm_navdata_interface/out/navdata_interface.wasm
name: msfs_navdata_interface.wasm
path: ./out/msfs_navdata_interface.wasm
5 changes: 2 additions & 3 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Build WASM module
run: |
./src/wasm_navdata_interface/scripts/run_docker_cmd.sh ./scripts/build.sh
run: npm run build:wasm-workflow
- name: Pre-Release
uses: softprops/action-gh-release@v1
with:
files: ./src/wasm_navdata_interface/out/navdata_interface.wasm
files: ./out/msfs_navdata_interface.wasm
prerelease: true
24 changes: 24 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: create env file
run: |
touch .env
echo NAVDATA_SIGNED_URL=${{ secrets.NAVDATA_SIGNED_URL }} >> .env
- name: Build WASM module
run: npm run build:wasm-workflow
- name: Test
run: npm run test-workflow
- name: Upload WASM module to GitHub
uses: actions/upload-artifact@v2
with:
name: msfs_navdata_interface.wasm
path: ./out/msfs_navdata_interface.wasm
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Build WASM module
run: |
./src/wasm_navdata_interface/scripts/run_docker_cmd.sh ./scripts/build.sh
run: npm run build:wasm-workflow
- name: Release
uses: softprops/action-gh-release@v1
with:
files: ./src/wasm_navdata_interface/out/navdata_interface.wasm
files: ./out/msfs_navdata_interface.wasm
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ _PackageInt
tsconfig.tsbuildinfo
.vs
examples/aircraft/PackageSources/html_ui/Pages/VCockpit/Instruments/Navigraph/NavdataInterfaceSample
examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navdata_Interface_Aircraft/panel/navdata_interface.wasm
src/wasm_navdata_interface/out
examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navdata_Interface_Aircraft/panel/msfs_navdata_interface.wasm
out

# Rust
# will have compiled files and executables
Expand All @@ -26,3 +26,6 @@ Cargo.lock
.vscode
.env
*.local
.DS_Store

test_work/
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Rollup
.rollup.cache

package-lock.json

*.gltf
*.json
*.yml
File renamed without changes.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# @Navigraph/app-dev will be requested for
# review when someone opens a pull request.
* @pepperoni505
* @professoralex13
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[workspace]
resolver = "2"

members = ["src/wasm", "src/database"]

[profile.release]
lto = true
strip = true

[patch.crates-io]
rusqlite = { git = "https://github.com/navigraph/rusqlite", rev = "7921774" }
79 changes: 0 additions & 79 deletions DOCS.md

This file was deleted.

100 changes: 94 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Here's an overview on the structure of this repository, which is designed to be
- `aircraft/` includes a base aircraft to test in the sim
- `gauge/` includes a very simple TypeScript instrument to communicate with the WASM module
- `src/`
- Contains the source for the navdata interface (and soon the JS library)
- `wasm_navdata_interface` includes the Rust source code for the WASM module
- `database` Includes rust source code for interfacing with a DFD sqlite file (not WASM specific)
- `js` Includes source code for the JS interface for using the sdk
- `test` Includes code for testing the JS and Rust code using a Node runtime
- `wasm` includes the Rust source code for the WASM module which handles the downloading of the databse file, and interfacing with the database implementation

## Including in Your Aircraft

Expand All @@ -26,7 +28,7 @@ Here's an overview on the structure of this repository, which is designed to be
size_mm=0,0
pixel_size=0,0
texture=NO_TEXTURE
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=navdata_interface.wasm&wasm_gauge=navdata_interface,0,0,1,1
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=msfs_navdata_interface.wasm&wasm_gauge=navdata_interface,0,0,1,1
```
- Note that if you already have a `VCockpit` with `NO_TEXTURE` you can just add another `htmlgauge` to it, while making sure to increase the index

Expand All @@ -44,7 +46,93 @@ Before building, make sure you have properly created and set an `.env` file in `
## Building the WASM Module Yourself

1. [Download](https://www.docker.com/products/docker-desktop/) Docker Desktop
2. Open the `src/wasm_navdata_interface` folder in a terminal
3. Run `.\build.bat` (must be on Windows)
2. Run `npm run build:wasm` (must be on Windows)
- This will take a while to download and build the first time, but subsequent runs will be quicker
4. The compiled WASM module will be copied to `src/wasm_navdata_interface/out` **and** `examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navdata_Interface_Aircraft/panel`
3. The compiled WASM module will be copied to `out` **and** `examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navdata_Interface_Aircraft/panel`

## Interfacing with the navdata gauge manually

The navdata interface acts as its own WASM gauge in sim, so in order to communicate with it, you must use the [CommBus](https://docs.flightsimulator.com/html/Programming_Tools/WASM/Communication_API/Communication_API.htm).

The gauge communicates using the following event names:

(Any types referenced can be found in `wasm/src/json_structs.rs`)

- `NAVIGRAPH_CallFunction`: This event is received by the interface and is used to trigger one of the interfaces functions. It takes in arguments of type `CallFunction`. The available functions and their expected parameters can be found in the `json_structs.rs` file
- `NAVIGRAPH_FunctionResult`: This event is sent by the interface as a response to a previously triggered function. Its result will have the type `FunctionResult`, with the data field containing the expected return type of the function.
- `NAVIGRAPH_Event`: This event is sent by the interface to give indications of progress or that the interface is running correctly.

### Example

Below is an example of communicating with the interface in JS. (We provide a JS wrapper, the code below is just a basic example to show how it works). Please read the CommBus documentation to determine how to interface with CommBus in your chosen language. `src/js` contains our JS wrapper, it is also a useful example for implementing a fully fleshed out wrapper.

```js
const queue = []

const listener = RegisterCommBusListener(() => {
listener.on("NAVIGRAPH_FunctionResult", jsonArgs => {
const args = JSON.parse(jsonArgs)

// When a FunctionResult is received, find the item in queue which matches the id, and resolve or reject it
const queueItem = queue.find(m => m.id === args.id)

if (queueItem) {
queue.splice(queue.indexOf(queueItem), 1)
const data = args.data

if (args.status === FunctionResultStatus.Success) {
queueItem.resolve(data)
} else {
queueItem.reject(new Error(typeof data === "string" ? data : "Unknown error"))
}
}
})
}) // RegisterCommBusListener is a function provided by sim

function getAirport(ident) {
const id = Utils.generateGUID() // Utils is a class provided by sim

const args = {
function: "GetAirport", // The name of the function being called
id, // CallFunctions and FunctionResults are tied together with the id field
data: {
// The parameters of the function
ident,
},
}

listener.callWasm("NAVIGRAPH_CallFunction", JSON.stringify(args))

return new Promise((resolve, reject) => {
queue.push({
id,
resolve: response => resolve(response),
reject: error => reject(error),
})
})
}

function executeSql(sql, params) {
const id = Utils.generateGUID() // Utils is a class provided by sim

const args = {
function: "ExecuteSQLQuery", // The name of the function being called
id, // CallFunctions and FunctionResults are tied together with the id field
data: {
// The parameters of the function
sql,
params,
},
}

listener.callWasm("NAVIGRAPH_CallFunction", JSON.stringify(args))

return new Promise((resolve, reject) => {
queue.push({
id,
resolve: response => resolve(response),
reject: error => reject(error),
})
})
}
```
Loading