-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ Check the website [zenoh.io](http://zenoh.io) and the [roadmap](https://github.c | |
|
||
--- | ||
|
||
# Typescript/Javascript API | ||
## Typescript/Javascript API | ||
|
||
This repository provides a Typscript / Javascript binding through the use of the `remote-api-plugin` in this repo. | ||
The long term plan is to use zenoh [Zenoh written in Rust](https://github.com/eclipse-zenoh/zenoh) to target WASM. | ||
|
@@ -29,97 +29,95 @@ Docs can be accessed at [Docs Link](https://eclipse-zenoh.github.io/zenoh-ts/) | |
|
||
> :warning: **WARNING** :warning: : Zenoh and its ecosystem are under active development. When you build from git, make sure you also build from git any other Zenoh repository you plan to use (e.g. binding, plugin, backend, etc.). It may happen that some changes in git are not compatible with the most recent packaged Zenoh release (e.g. deb, docker, pip). We put particular effort in maintaining compatibility between the various git repositories in the Zenoh project. | ||
## Executing the `zenohd` with `zenoh-plugin-remote-api` plugin | ||
### Executing the `zenohd` with `zenoh-plugin-remote-api` plugin | ||
|
||
The `zenohd` router and its pluigns should be built with the same zenoh sources and the same version of rust compiler with the same set of features. | ||
This requirement exists because router and plugins shares common Rust structures and Rust doesn't guarantee the ABI compatibility of | ||
memory representation of these structures. | ||
The `zenohd` router and its plugins should be built with the same Zenoh sources, the same version of the Rust compiler, and with the same set of features. This requirement exists because the router and plugins share common Rust structures, and Rust doesn't guarantee ABI compatibility of the memory representation of these structures. | ||
|
||
Therefore one of these methods is recommended: | ||
|
||
1. Install latest release of `zenohd` and `zenoh-plugin-remote-api` | ||
|
||
Ubuntu: | ||
Ubuntu: | ||
|
||
```sh | ||
echo "deb [trusted=yes] https://download.eclipse.org/zenoh/debian-repo/ /" | sudo tee -a /etc/apt/sources.list.d/zenoh.list > /dev/null | ||
sudo apt update | ||
sudo apt install zenohd | ||
sudo apt install zenoh-plugin-remote-api | ||
``` | ||
```sh | ||
echo "deb [trusted=yes] https://download.eclipse.org/zenoh/debian-repo/ /" | sudo tee -a /etc/apt/sources.list.d/zenoh.list > /dev/null | ||
sudo apt update | ||
sudo apt install zenohd | ||
sudo apt install zenoh-plugin-remote-api | ||
``` | ||
|
||
Mac-OS: | ||
Mac-OS: | ||
|
||
```sh | ||
brew tap eclipse-zenoh/homebrew-zenoh | ||
brew install zenoh | ||
brew install zenoh-plugin-remote-api | ||
``` | ||
```sh | ||
brew tap eclipse-zenoh/homebrew-zenoh | ||
brew install zenoh | ||
brew install zenoh-plugin-remote-api | ||
``` | ||
|
||
Run installed zenoh router with example config | ||
Run installed zenoh router with example config | ||
|
||
```sh | ||
zenohd --config EXAMPLE_CONFIG.json5 | ||
``` | ||
```sh | ||
zenohd --config EXAMPLE_CONFIG.json5 | ||
``` | ||
|
||
Expected output for is like: | ||
|
||
```txt | ||
zenohd: zenohd v1.0.3 built with rustc 1.75.0 (82e1608df 2023-12-21) | ||
zenoh::net::runtime: Using ZID: f7bc54e0941036422ec08ebac6fbdb40 | ||
zenoh::api::loader: Loading plugin "remote_api" | ||
zenoh::api::loader: Starting plugin "remote_api" | ||
zenoh::api::loader: Successfully started plugin remote_api from "/usr/lib/libzenoh_plugin_remote_api.so" | ||
zenoh::api::loader: Finished loading plugins | ||
zenoh::net::runtime::orchestrator: Zenoh can be reached at: tcp/.... | ||
``` | ||
Expected output is like: | ||
|
||
```txt | ||
zenohd: zenohd v1.0.3 built with rustc 1.75.0 (82e1608df 2023-12-21) | ||
zenoh::net::runtime: Using ZID: f7bc54e0941036422ec08ebac6fbdb40 | ||
zenoh::api::loader: Loading plugin "remote_api" | ||
zenoh::api::loader: Starting plugin "remote_api" | ||
zenoh::api::loader: Successfully started plugin remote_api from "/usr/lib/libzenoh_plugin_remote_api.so" | ||
zenoh::api::loader: Finished loading plugins | ||
zenoh::net::runtime::orchestrator: Zenoh can be reached at: tcp/.... | ||
``` | ||
|
||
1. Build the plugin and the router from the sources: | ||
|
||
Build the `zenoh-plugin-remote-api` | ||
Build the plugin `zenoh-plugin-remote-api` | ||
|
||
```sh | ||
cargo build | ||
``` | ||
```sh | ||
cargo build | ||
``` | ||
|
||
Build and run the zenohd from the same sources which were used for the plugin. | ||
The zenohd dependency is specified in `[workspace.metadata.bin]` section in Cargo.toml and processed by the 3-rd party tool [cargo-run-bin](https://crates.io/crates/cargo-run-bin). | ||
Build and run the zenohd from the same sources which were used for the plugin. | ||
The zenohd dependency is specified in `[workspace.metadata.bin]` section in Cargo.toml which is processed by the 3-rd party tool [cargo-run-bin](https://crates.io/crates/cargo-run-bin). | ||
|
||
```sh | ||
cargo install cargo-run-bin | ||
cargo bin zenohd --config EXAMPLE_CONFIG.json5 | ||
``` | ||
```sh | ||
cargo install cargo-run-bin | ||
cargo bin zenohd --config EXAMPLE_CONFIG.json5 | ||
``` | ||
|
||
Expected output is like: | ||
Expected output is like: | ||
|
||
```txt | ||
zenohd: zenohd vc764bf9b built with rustc 1.75.0 (82e1608df 2023-12-21) | ||
zenoh::net::runtime: Using ZID: bb3fb16628f57e92f92accf2f5c81511 | ||
zenoh::api::loader: Loading plugin "remote_api" | ||
zenoh::api::loader: Starting plugin "remote_api" | ||
zenoh::api::loader: Successfully started plugin remote_api from "./target/debug\\zenoh_plugin_remote_api.dll" | ||
zenoh::api::loader: Finished loading plugins | ||
zenoh::net::runtime::orchestrator: Zenoh can be reached at: ... | ||
``` | ||
```txt | ||
zenohd: zenohd vc764bf9b built with rustc 1.75.0 (82e1608df 2023-12-21) | ||
zenoh::net::runtime: Using ZID: bb3fb16628f57e92f92accf2f5c81511 | ||
zenoh::api::loader: Loading plugin "remote_api" | ||
zenoh::api::loader: Starting plugin "remote_api" | ||
zenoh::api::loader: Successfully started plugin remote_api from "./target/debug\\zenoh_plugin_remote_api.dll" | ||
zenoh::api::loader: Finished loading plugins | ||
zenoh::net::runtime::orchestrator: Zenoh can be reached at: tcp/... | ||
``` | ||
|
||
## Building the Typescript project | ||
### Building the library | ||
|
||
1. Make sure that the following utilities are available on your platform. | ||
1. Make sure that the following utilities are available on your platform. | ||
|
||
- [NPM](https://www.npmjs.com/package/npm) | ||
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#debian-stable) | ||
- [Typescript](https://www.typescriptlang.org/download/) | ||
|
||
1. Navigate to the directory `zenoh-ts` | ||
2. Navigate to the directory `zenoh-ts` | ||
|
||
1. Run the commands: | ||
|
||
```sh | ||
yarn install | ||
yarn run build | ||
``` | ||
```sh | ||
yarn install | ||
yarn run build | ||
``` | ||
|
||
## Build and run the command line examples | ||
### Build and run the command line examples | ||
|
||
This library is currently compatible with browsers, but not with NodeJS due to websocket library limitations. | ||
To run the command line examples use javascript runtime [deno](https://deno.com/) which is expected be consistent with the browser. | ||
|
@@ -130,7 +128,7 @@ To run the command line examples use javascript runtime [deno](https://deno.com/ | |
1. Run zenohd with remote_api plugin, configured to websocket port 10000, as described above | ||
1. Run the examples by running `yarn example <PATH TO EXAMPLE>`, i.e. `yarn example src/z_sub.ts` | ||
|
||
E.g. in different sessions run publisher and subcriber examples: | ||
For to run publisher and subcriber examples: | ||
|
||
```sh | ||
yarn example src/pub.rs | ||
|
@@ -140,27 +138,21 @@ yarn example src/pub.rs | |
yarn example src/sub.rs | ||
``` | ||
|
||
The subscriber should start to receive messages from publisher | ||
The subscriber should start to receive messages from publisher: | ||
|
||
```text | ||
>> [Subscriber] Received PUT ('demo/example/zenoh-ts-pub': '[0] 122,101,110,111,104') | ||
>> [Subscriber] Received PUT ('demo/example/zenoh-ts-pub': '[1] 122,101,110,111,104') | ||
>> [Subscriber] Received PUT ('demo/example/zenoh-ts-pub': '[2] 122,101,110,111,104') | ||
``` | ||
|
||
This will start an instance of Deno running the example. | ||
The application will attempt to connect to a `websocket_port` : `10000` where the Remote API plugin is expected to be running. | ||
|
||
## Adding Typescript to your application | ||
### Adding Typescript to your application | ||
|
||
The TypeScript library can be install from the command line: | ||
The latest version of zenoh-ts library can be installed from npm: | ||
|
||
```sh | ||
npm install @eclipse-zenoh/[email protected] | ||
```` | ||
|
||
Or added via package.json | ||
|
||
`"@eclipse-zenoh/zenoh-ts": "0.0.8" ` | ||
|
||
Note: In order to add this library to your project you must log into the github npm repository, | ||
please refer to this link for more information [Accessing github NPM](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-with-a-personal-access-token) | ||
|
||
|
||
[zenoh]: https://github.com/eclipse-zenoh/zenoh | ||
|
||
|
||
npm install @eclipse-zenoh/zenoh-ts | ||
``` |