Skip to content

Commit 2799839

Browse files
committed
feat: Update Readme and docs
1 parent 7fe7d19 commit 2799839

5 files changed

Lines changed: 61 additions & 10 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"includePath": [
66
"/Users/intro/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/**",
77
"${workspaceFolder}/**",
8-
"${workspaceFolder}/app/dependency/cpp/node/include",
8+
"${workspaceFolder}/app/dependency/cpp/node/include"
99
],
1010
"macFrameworkPath": [
1111
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
![C++17](https://img.shields.io/badge/C%2B%2B-17-blue.svg)
2+
![NodeJS v14.17.0](https://img.shields.io/badge/NodeJS-v14.17.0-blue.svg)
3+
14
# Description
25

36
This project aims to run Web Audio API in Android with javascript code. Most of the available APIs have passed wpt test cases.
@@ -22,18 +25,32 @@ Now it supports following Web Audio feature:
2225

2326
more detail info is descript [here](./js_api_define/features.md).
2427

25-
# Run
28+
# Build & Run
2629

2730
1. run `npm install` for installing dependency
2831
2. run `npm start` to get server address like `http://xxx.xxx.xxx.xxx:20490`
29-
3. add this line `js_entry="http://xxx.xxx.xxx.xxx:20490/index.js"` to local.property file
32+
3. open root folder with Android Studio
33+
4. add this line `js_entry="http://xxx.xxx.xxx.xxx:20490/index.js"` to local.property file
34+
5. build and run app
3035

31-
# Develop
36+
# App Interface
37+
38+
After running app, you can see five buttons:
3239

33-
## VSCode
40+
1. `START`: Start running js code in `index.js`
41+
2. `STOP`: Stop js event loop. You need to press `RESTART` button to re-run js code.
42+
3. `PAUSE`: Pause js event loop.
43+
4. `RESUME`: Resume js event from pause.
44+
5. `RESTART`: Restart app.
45+
46+
NOTE: all console message in js code will be output to Android Studio Logcat.
47+
48+
# Develop
3449

35-
1. You should open root folder by vscode after running app or building app at `app/build.gradle.kts` page. This will make Android Studio generate `.vscode/compile_commands.json` file, which is used by vscode to recognize cpp headers.
50+
see [develop.md](./docs/develop.md)
3651

37-
# Note:
52+
# Thanks
3853

39-
1. `combine` script in package.json is used to make vscode recognize all cpp files in different module inside android module. When Android Build success, scripts in `build.gradle.kts` will move all `compile_commands.json` contents to `.vscode/compile_commands.json`, this will make vscode cpp intelligence works fine.
54+
1. Test case based on [wpt](https://github.com/web-platform-tests/wpt).
55+
2. NAPI_IH base on [node-addon-api-helper](https://github.com/ajihyf/node-addon-api-helper).
56+
3. Use [ProcessPhoenix](https://github.com/JakeWharton/ProcessPhoenix) to restart Android App.

docs/develop.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Develop
2+
3+
## package.json
4+
5+
We put some useful script in `package.json` file:
6+
7+
```json
8+
"scripts": {
9+
"compress": "node js_task/compress.js",
10+
"combine": "node js_task/combine_compile_commands.js",
11+
"valid": "ROOT_DIR=$(pwd) node ./js_task/valid_task/valid.js",
12+
"start": "npm run compress && http-server -p 20490"
13+
},
14+
```
15+
16+
1. `compress`: each NAPI module which needs to be exported in js is export by `globalThis.ModuleApiName = process._linkedBinding("ModuleName").ApiName;`. These js code are put in `**/preload_script.js` file, which will be converted to c string saved in `**/preload_script.hpp`. This process is handled by `compress` command.
17+
2. `combine`: cpp code of this project is developed in vscode, so we need to add all relative file paths to the `compileCommands` options of `.vscode/c_cpp_properties.json`. These cpp relative files will be created when do build in Android Studio, `combine` command is used to collect and add them to `.vscode/compile_commands.json`, then vscode can recognize cpp symbol.
18+
3. `valid`: Use to check if WaveProducer, a tool used in OscillatorNode, works correctly.
19+
4. `start`: do `compress` and start a http-server accessed by app to load js code which need to be run.
20+
21+
## cpp hint
22+
23+
If you write cpp layer in vscode, you should build once after Android Studio sync. Build will trigger `combine` command which makes vscode recognize cpp symbol.
24+
25+
NOTE: if you find vscode not recognize cpp symbol, make sure to switch the Android Studio tab to `app/build.gradle.kts`, then build.
26+
27+
## NAPI
28+
29+
### NodeJS
30+
31+
The node env of this project is based on [v14.17.0](https://github.com/toyobayashi/node-android-build/releases/tag/v14.17.0) of [node-android-build](https://github.com/toyobayashi/node-android-build). The build tutorial is referenced to [在 Android 应用中嵌入 Node.js](https://toyobayashi.github.io/2021/03/29/NodeEmbedding/)
32+
33+
### NAPI_IH
34+
35+
The goal of the project architecture is to make the structure of the napi layer consistent with the cpp layer. But NAPI do not support inheritance, so we make a pitch to NAPI, that is [NAPI_IH](./napi_ih_api.md).

app/dependency/cpp/node/include/napi_ih/README.md renamed to docs/napi_ih_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Description
1+
# NAPI_IH
22

33
`napi_ih` means "napi inheritance helper" which is a pitch to napi to support inheritance and try to keep the style of napi. The implementation is inspired by https://github.com/ajihyf/node-addon-api-helper and https://mmomtchev.medium.com/-class-inheritance-with-node-api-and-node-addon-api-c180334d9902
44

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"compress": "node js_task/compress.js",
98
"combine": "node js_task/combine_compile_commands.js",
109
"valid": "ROOT_DIR=$(pwd) node ./js_task/valid_task/valid.js",

0 commit comments

Comments
 (0)