Skip to content

Commit

Permalink
Feature/bind js (#665)
Browse files Browse the repository at this point in the history
* add support for nodejs

---------

Signed-off-by: Andrey Parfenov <[email protected]>
Co-authored-by: Gordon Preumont <[email protected]>
  • Loading branch information
Andrey1994 and Gordon Preumont authored Sep 13, 2023
1 parent 467ee1e commit d71b4ca
Show file tree
Hide file tree
Showing 50 changed files with 6,970 additions and 15 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
python -m pip install twine
python -m pip install awscli
shell: cmd
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Typescript
run: |
npm install -g ts-node
shell: cmd
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down Expand Up @@ -102,6 +110,24 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Prepare Node Package
run: |
cd $env:GITHUB_WORKSPACE\nodejs_package\
Copy-Item "$env:GITHUB_WORKSPACE\linux\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
Copy-Item "$env:GITHUB_WORKSPACE\macos\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
Copy-Item "$env:GITHUB_WORKSPACE\win64\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
Copy-Item "$env:GITHUB_WORKSPACE\win32\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
ls $env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib
(gc .\package.json).replace('0.0.0-development', $env:VERSION) | Out-File -encoding ASCII package.json
type package.json
npm install
npm run build
npm pack
aws s3 cp $env:GITHUB_WORKSPACE\nodejs_package\ s3://brainflow/$env:GITHUB_SHA/npm --recursive
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
VERSION: ${{ github.event.inputs.version }}
- name: Prepare Java Package
run: |
cd $env:GITHUB_WORKSPACE\java_package\brainflow
Expand Down Expand Up @@ -196,12 +222,16 @@ jobs:
- name: Publish Packages
if: github.event.inputs.publish == 'true'
run: |
cd $env:GITHUB_WORKSPACE\nodejs_package
echo "//registry.npmjs.org/:_authToken=$env:NPM_TOKEN" > .npmrc
npm publish
cd $env:GITHUB_WORKSPACE\java_package\brainflow
mvn -s $env:GITHUB_WORKSPACE\java_package\brainflow\settings.xml deploy -Dregistry=https://maven.pkg.github.com/brainflow-dev -Dtoken=$env:PUBLISH_TOKEN
cd $env:GITHUB_WORKSPACE\python_package
twine upload --skip-existing dist/*.whl --user Andrey1994 --password $env:PYPI_PASSWORD
cd $env:GITHUB_WORKSPACE\rust_package\brainflow
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
PUBLISH_USER: ${{ secrets.PUBLISH_USER }}
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
workflow_dispatch:
inputs:
version:
description: New Version
description: Git tag to checkout
default: ""
required: true
required: false
publish:
description: Make Public(true or false)
default: "false"
Expand All @@ -26,12 +26,18 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clone Repository
uses: actions/checkout@v2
- name: Build Docker Container
- name: Build Docker Container with Tag
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
run: |
cd Docker
sudo docker build --tag brainflow/brainflow:${VERSION} --build-arg checkout_id=${VERSION} .
env:
VERSION: ${{ github.event.inputs.version }}
- name: Build Docker Container without Tag
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version == ''
run: |
cd Docker
sudo docker build --tag brainflow/brainflow:0.0.1 .
- name: Check Images
run: sudo -H docker images
- name: DockerHub Login
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/run_unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ jobs:
sudo -H apt-get install -y python3-setuptools python3-pygments libbluetooth-dev
env:
DEBIAN_FRONTEND: noninteractive
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Typescript
run: |
npm install -g ts-node
- name: Install Ninja
if: (matrix.os == 'macos-11.0')
uses: seanmiddleditch/gha-setup-ninja@master
Expand Down Expand Up @@ -91,6 +98,15 @@ jobs:
run: |
cd $GITHUB_WORKSPACE/python_package
sudo -H python3 -m pip install -U .
- name: Build Node Package
run: |
cd $GITHUB_WORKSPACE/nodejs_package/brainflow
npm install
npm run build
- name: Install Node Tests
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm install
- name: Setup Java package
run: |
cd $GITHUB_WORKSPACE/java_package/brainflow
Expand Down Expand Up @@ -305,6 +321,34 @@ jobs:
mvn exec:java -Dexec.mainClass="brainflow.examples.EEGMetrics" -Dexec.args="--board-id -1"
env:
LD_LIBRARY_PATH: ${{ github.workspace }}/installed/lib
- name: Synthetic Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run brainflow_get_data
- name: Signal Filters Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run signal_filtering
- name: Serialization Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run serialization
- name: Downsampling Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run downsampling
- name: Denoising Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run denoising
- name: EEG Metrics Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run eeg_metrics
- name: BandPowerAll Node
run: |
cd $GITHUB_WORKSPACE/nodejs_package/tests
npm run bandpower_all
# deploy started
- name: Install AWS CLI
run: sudo -H python3 -m pip install awscli==1.21.10
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/run_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: |
mkdir %GITHUB_WORKSPACE%\build32
cd %GITHUB_WORKSPACE%\build32
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DBUILD_TESTS=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A Win32 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed32\ ..
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A Win32 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed32\ ..
cmake --build . --target install --config Release -j 2 --parallel 2
env:
BRAINFLOW_VERSION: ${{ steps.version.outputs.version }}
Expand All @@ -54,7 +54,7 @@ jobs:
run: |
mkdir %GITHUB_WORKSPACE%\build64
cd %GITHUB_WORKSPACE%\build64
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DBUILD_TESTS=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed64\ ..
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed64\ ..
cmake --build . --target install --config Release -j 2 --parallel 2
env:
BRAINFLOW_VERSION: ${{ steps.version.outputs.version }}
Expand Down Expand Up @@ -120,10 +120,6 @@ jobs:
uses: julia-actions/setup-julia@v1
with:
version: 1.3.1
# Unit testing
- name: Run unit tests
run: .\build\tests\Release\brainflow_tests.exe
shell: cmd
# BoardController testing
- name: Run Julia Tests
run: |
Expand Down
17 changes: 11 additions & 6 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ echo "deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/" | tee /etc
echo "deb https://download.mono-project.com/repo/ubuntu vs-bionic main" | tee /etc/apt/sources.list.d/mono-official-vs.list && \
apt-get -qq update
# Installing Dependencies
RUN apt-get install -yqq python3 python3-pip python3-venv openjdk-13-jdk git curl wget build-essential python3-jira r-base rustc cargo nuget nuget mono-devel mono-complete monodevelop libxml2-dev libbluetooth-dev libdbus-1-dev dotnet-sdk-6.0 dotnet-runtime-6.0 dotnet-runtime-3.1 aspnetcore-runtime-6.0
RUN apt-get install -yqq python3 python3-pip python3-venv openjdk-13-jdk git curl wget build-essential python3-jira r-base rustc cargo nuget nuget mono-devel mono-complete monodevelop libxml2-dev libbluetooth-dev libdbus-1-dev dotnet-sdk-6.0 dotnet-runtime-6.0 dotnet-runtime-3.1 aspnetcore-runtime-6.0 nodejs npm
RUN mkdir -p /root/local/bin
WORKDIR /root/local/bin
# install latest cmake
RUN mkdir -p /opt/cmake && wget https://github.com/Kitware/CMake/releases/download/v3.24.3/cmake-3.24.3-linux-x86_64.sh && sh cmake-3.24.3-linux-x86_64.sh --prefix=/opt/cmake --skip-license
ENV PATH=/opt/cmake/bin/:$PATH
# Installing Maven and Julia
RUN curl "https://miroir.univ-lorraine.fr/apache/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz" -o maven.tar.gz
RUN curl "https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz" -o maven.tar.gz
RUN mkdir -p maven
RUN tar xzf maven.tar.gz -C ./maven
RUN export PATH=$PATH:/root/local/bin/maven/apache-maven-3.9.4/bin
RUN export PATH=$PATH:/root/local/bin/maven/apache-maven-3.6.3/bin
RUN wget "https://julialang-s3.julialang.org/bin/linux/x64/1.5/julia-1.5.3-linux-x86_64.tar.gz"
RUN mkdir -p julia
RUN tar xf julia-1.5.3-linux-x86_64.tar.gz -C ./julia
Expand All @@ -33,11 +33,11 @@ ENV PATH=$PATH:/root/local/bin/julia/julia-1.5.3/bin
RUN python3 -m pip install scipy pandas matplotlib mne jupyterlab notebook opencv-python pyriemann

WORKDIR /root
ARG checkout_id
ARG checkout_id="none"
# Compile
RUN git clone "https://github.com/brainflow-dev/brainflow.git"
WORKDIR /root/brainflow
RUN if [ ! -z "${checkout_id}" ]; then git checkout "${checkout_id}"; fi
RUN if [ "${checkout_id}" != "none" ]; then git checkout "${checkout_id}"; fi
RUN python3 ./tools/build.py --use-openmp --bluetooth --ble
ENV LD_LIBRARY_PATH=/root/brainflow/installed_linux/lib/

Expand All @@ -54,7 +54,7 @@ RUN dotnet build csharp_package/brainflow/brainflow.sln

# Java Binding
WORKDIR /root/brainflow/java_package/brainflow
RUN /root/local/bin/maven/apache-maven-3.9.4/bin/mvn package
RUN /root/local/bin/maven/apache-maven-3.6.3/bin/mvn package

# Julia Bindings
WORKDIR /root/brainflow/julia_package/brainflow
Expand All @@ -67,6 +67,11 @@ RUN R --vanilla -e 'install.packages("knitr", repos="http://cran.us.r-project.or
RUN R --vanilla -e 'install.packages("reticulate", repos="http://cran.us.r-project.org")'
RUN R CMD build .

# Node JS Binding
WORKDIR /root/brainflow/nodejs_binding/brainflow
RUN npm install -g ts-node
RUN npm install

# Rust Binding
WORKDIR /root/brainflow/rust_package/brainflow
RUN cargo build
Expand Down
17 changes: 17 additions & 0 deletions docs/BuildBrainFlow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ When using BrainFlow for the first time in Julia, the BrainFlow artifact contain

If you compile BrainFlow from source local libraries will take precedence over the artifact.

Typescript
-----------

.. compound::

You can install BrainFlow using next command without compilation ::

npm install brainflow

.. compound::

If you want to install it from source files or build unreleased version from Github, you should first compile the core module (:ref:`compilation-label`). Then run ::

cd nodejs_package
npm install --force


Rust
-------

Expand Down
63 changes: 63 additions & 0 deletions docs/Examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,69 @@ Rust ICA
.. literalinclude:: ../rust_package/brainflow/examples/ica.rs
:language: rust

Typescript
------------

Typescript Get Data from a Board
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/brainflow_get_data.ts
:language: javascript

Typescript Markers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/markers.ts
:language: javascript

Typescript Read Write File
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/serialization.ts
:language: javascript

Typescript Downsample Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/downsampling.ts
:language: javascript

Typescript Transforms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/transforms.ts
:language: javascript

Typescript Signal Filtering
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/signal_filtering.ts
:language: javascript

Typescript Denoising
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/denoising.ts
:language: javascript

Typescript Band Power
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/bandpower.ts
:language: javascript

Typescript EEG Metrics
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/eeg_metrics.ts
:language: javascript

Typescript ICA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../nodejs_package/tests/ica.ts
:language: javascript

Notebooks
------------
.. toctree::
Expand Down
1 change: 1 addition & 0 deletions docs/SupportedBoards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ To create such board you need to specify the following board ID and fields of Br
Initialization Example:

.. code-block:: python
params = BrainFlowInputParams()
params.serial_port = "COM6"
board = BoardShim(BoardIds.FREEEEG128_BOARD, params)
Expand Down
10 changes: 10 additions & 0 deletions docs/UserAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,13 @@ Example:

.. literalinclude:: ../rust_package/brainflow/examples/get_data.rs
:language: rust

Typescript API Reference
--------------------------

Typescript binding calls C/C++ code as any other binding. Use Typescript examples and API reference for other languaes as a starting point.

Example:

.. literalinclude:: ../nodejs_package/tests/brainflow_get_data.ts
:language: javascript
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Pygments==2.7.4
sphinxcontrib-matlabdomain==0.11.4
docutils<0.17
sphinx_rtd_theme==0.4.3
jinja2<3.1
Loading

0 comments on commit d71b4ca

Please sign in to comment.